| 1 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#}; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#; |
| 3 | |
| 4 | /// Implementation guts for `min_set`, `min_set_by`, and `min_set_by_key`. |
| 5 | pub fn min_set_implrust-analyzer cargo itertools 0.14.0 extrema_set/min_set_impl().<I, K, F, Compare>( |
| 6 | mut it: I, |
| 7 | mut key_for: F, |
| 8 | mut compare: Compare, |
| 9 | ) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> |
| 10 | where |
| 11 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 12 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> K, |
| 13 | Compare: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#, &I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#, &K, &K) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#, |
| 14 | { |
| 15 | match it.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() { |
| 16 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 17 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(element) => { |
| 18 | let mut current_key = key_for(&element); |
| 19 | let mut result = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![element]; |
| 20 | it.for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#for_each().(|element| { |
| 21 | let key = key_for(&element); |
| 22 | match compare(&element, &result[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., &key, ¤t_key) { |
| 23 | Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Lessrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Less# => { |
| 24 | result.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().(); |
| 25 | result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(element); |
| 26 | current_key = key; |
| 27 | } |
| 28 | Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal# => { |
| 29 | result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(element); |
| 30 | } |
| 31 | Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::Greaterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Greater# => {} |
| 32 | } |
| 33 | }); |
| 34 | result |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /// Implementation guts for `ax_set`, `max_set_by`, and `max_set_by_key`. |
| 40 | pub fn max_set_implrust-analyzer cargo itertools 0.14.0 extrema_set/max_set_impl().<I, K, F, Compare>(it: I, key_for: F, mut compare: Compare) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> |
| 41 | where |
| 42 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 43 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> K, |
| 44 | Compare: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#, &I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#, &K, &K) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#, |
| 45 | { |
| 46 | min_set_implrust-analyzer cargo itertools 0.14.0 extrema_set/min_set_impl().(it, key_for, |it1, it2, key1, key2| { |
| 47 | compare(it2, it1, key2, key1) |
| 48 | }) |
| 49 | } |