Coverage Report

Created: 2025-10-10 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/itertools-0.11.0/src/extrema_set.rs
Line
Count
Source
1
use std::cmp::Ordering;
2
3
/// Implementation guts for `min_set`, `min_set_by`, and `min_set_by_key`.
4
0
pub fn min_set_impl<I, K, F, Compare>(
5
0
    mut it: I,
6
0
    mut key_for: F,
7
0
    mut compare: Compare,
8
0
) -> Vec<I::Item>
9
0
where
10
0
    I: Iterator,
11
0
    F: FnMut(&I::Item) -> K,
12
0
    Compare: FnMut(&I::Item, &I::Item, &K, &K) -> Ordering,
13
{
14
0
    match it.next() {
15
0
        None => Vec::new(),
16
0
        Some(element) => {
17
0
            let mut current_key = key_for(&element);
18
0
            let mut result = vec![element];
19
0
            it.for_each(|element| {
20
0
                let key = key_for(&element);
21
0
                match compare(&element, &result[0], &key, &current_key) {
22
0
                    Ordering::Less => {
23
0
                        result.clear();
24
0
                        result.push(element);
25
0
                        current_key = key;
26
0
                    }
27
0
                    Ordering::Equal => {
28
0
                        result.push(element);
29
0
                    }
30
0
                    Ordering::Greater => {}
31
                }
32
0
            });
33
0
            result
34
        }
35
    }
36
0
}
37
38
/// Implementation guts for `ax_set`, `max_set_by`, and `max_set_by_key`.
39
0
pub fn max_set_impl<I, K, F, Compare>(it: I, key_for: F, mut compare: Compare) -> Vec<I::Item>
40
0
where
41
0
    I: Iterator,
42
0
    F: FnMut(&I::Item) -> K,
43
0
    Compare: FnMut(&I::Item, &I::Item, &K, &K) -> Ordering,
44
{
45
0
    min_set_impl(it, key_for, |it1, it2, key1, key2| {
46
0
        compare(it2, it1, key2, key1)
47
0
    })
48
0
}