Skip to content

Commit 08a10da

Browse files
committed
Add {min,max}_set(_by{_key)?)? functions (7) cargo fmt extrema_set.rs
1 parent fb57fc6 commit 08a10da

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/extrema_set.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use std::cmp::Ordering;
22

33
/// Implementation guts for `min_set`, `min_set_by`, and `min_set_by_key`.
4-
pub fn min_set_impl<I, K, F, Compare>(mut it: I,
5-
mut key_for: F,
6-
mut compare: Compare) -> Vec<I::Item>
7-
where I: Iterator,
8-
F: FnMut(&I::Item) -> K,
9-
Compare: FnMut(&I::Item, &I::Item, &K, &K) -> Ordering,
4+
pub fn min_set_impl<I, K, F, Compare>(
5+
mut it: I,
6+
mut key_for: F,
7+
mut compare: Compare,
8+
) -> Vec<I::Item>
9+
where
10+
I: Iterator,
11+
F: FnMut(&I::Item) -> K,
12+
Compare: FnMut(&I::Item, &I::Item, &K, &K) -> Ordering,
1013
{
1114
match it.next() {
1215
None => Vec::new(),
@@ -20,29 +23,26 @@ pub fn min_set_impl<I, K, F, Compare>(mut it: I,
2023
result.clear();
2124
result.push(element);
2225
current_key = key;
23-
},
26+
}
2427
Ordering::Equal => {
2528
result.push(element);
26-
},
27-
Ordering::Greater => {
28-
},
29+
}
30+
Ordering::Greater => {}
2931
}
3032
});
3133
result
3234
}
3335
}
34-
3536
}
3637

3738
/// Implementation guts for `ax_set`, `max_set_by`, and `max_set_by_key`.
38-
pub fn max_set_impl<I, K, F, Compare>(it: I,
39-
key_for: F,
40-
mut compare: Compare) -> Vec<I::Item>
41-
where I: Iterator,
42-
F: FnMut(&I::Item) -> K,
43-
Compare: FnMut(&I::Item, &I::Item, &K, &K) -> Ordering,
39+
pub fn max_set_impl<I, K, F, Compare>(it: I, key_for: F, mut compare: Compare) -> Vec<I::Item>
40+
where
41+
I: Iterator,
42+
F: FnMut(&I::Item) -> K,
43+
Compare: FnMut(&I::Item, &I::Item, &K, &K) -> Ordering,
4444
{
45-
min_set_impl(it, key_for, |it1, it2, key1, key2| compare(it2, it1, key2, key1))
45+
min_set_impl(it, key_for, |it1, it2, key1, key2| {
46+
compare(it2, it1, key2, key1)
47+
})
4648
}
47-
48-

0 commit comments

Comments
 (0)