]> git.proxmox.com Git - rustc.git/blob - vendor/itertools-0.7.8/src/group_map.rs
New upstream version 1.34.2+dfsg1
[rustc.git] / vendor / itertools-0.7.8 / src / group_map.rs
1 #![cfg(feature = "use_std")]
2
3 use std::collections::HashMap;
4 use std::hash::Hash;
5 use std::iter::Iterator;
6
7 /// Return a `HashMap` of keys mapped to a list of their corresponding values.
8 ///
9 /// See [`.into_group_map()`](../trait.Itertools.html#method.into_group_map)
10 /// for more information.
11 pub fn into_group_map<I, K, V>(iter: I) -> HashMap<K, Vec<V>>
12 where I: Iterator<Item=(K, V)>,
13 K: Hash + Eq,
14 {
15 let mut lookup = HashMap::new();
16
17 for (key, val) in iter {
18 lookup.entry(key).or_insert(Vec::new()).push(val);
19 }
20
21 lookup
22 }