Coverage Report

Created: 2026-02-26 07:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/itertools-0.14.0/src/group_map.rs
Line
Count
Source
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()`](crate::Itertools::into_group_map)
10
/// for more information.
11
0
pub fn into_group_map<I, K, V>(iter: I) -> HashMap<K, Vec<V>>
12
0
where
13
0
    I: Iterator<Item = (K, V)>,
14
0
    K: Hash + Eq,
15
{
16
0
    let mut lookup = HashMap::new();
17
18
0
    iter.for_each(|(key, val)| {
19
0
        lookup.entry(key).or_insert_with(Vec::new).push(val);
20
0
    });
21
22
0
    lookup
23
0
}
24
25
0
pub fn into_group_map_by<I, K, V, F>(iter: I, mut f: F) -> HashMap<K, Vec<V>>
26
0
where
27
0
    I: Iterator<Item = V>,
28
0
    K: Hash + Eq,
29
0
    F: FnMut(&V) -> K,
30
{
31
0
    into_group_map(iter.map(|v| (f(&v), v)))
32
0
}