1#![cfg(feature = "use_std")]
2
3use std::collections::HashMap;
4use std::hash::Hash;
5use std::iter::Iterator;
6
7pub fn into_group_map<I, K, V>(iter: I) -> HashMap<K, Vec<V>>
12where
13 I: Iterator<Item = (K, V)>,
14 K: Hash + Eq,
15{
16 let mut lookup = HashMap::new();
17
18 iter.for_each(|(key, val)| {
19 lookup.entry(key).or_insert_with(Vec::new).push(val);
20 });
21
22 lookup
23}
24
25pub fn into_group_map_by<I, K, V, F>(iter: I, mut f: F) -> HashMap<K, Vec<V>>
26where
27 I: Iterator<Item = V>,
28 K: Hash + Eq,
29 F: FnMut(&V) -> K,
30{
31 into_group_map(iter.map(|v| (f(&v), v)))
32}