Coverage Report

Created: 2026-10-17 08:02

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