Skip to content

Commit 5c8f029

Browse files
committed
Style tweaks and tidy up
1 parent 626bdd4 commit 5c8f029

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

Diff for: src/k_smallest.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ where
4747

4848
let mut is_less_than = move |a: &_, b: &_| comparator(a, b) == Ordering::Less;
4949

50-
// Rearrange the into a valid heap by reordering from the second-bottom-most layer up
50+
// Rearrange the into a valid heap by reordering from the second-bottom-most layer up to the root
5151
// Slightly faster than ordering on each insert, but only by a factor of lg(k)
5252
// The resulting heap has the **largest** item on top
5353
for i in (0..=(storage.len() / 2)).rev() {
@@ -88,13 +88,6 @@ where
8888
storage
8989
}
9090

91-
pub(crate) fn reverse_cmp<T, F>(cmp: F) -> impl Fn(&T, &T) -> Ordering
92-
where
93-
F: Fn(&T, &T) -> Ordering,
94-
{
95-
move |a, b| cmp(b, a)
96-
}
97-
9891
pub(crate) fn key_to_cmp<T, K, F>(key: F) -> impl Fn(&T, &T) -> Ordering
9992
where
10093
F: Fn(&T) -> K,

Diff for: src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2956,7 +2956,7 @@ pub trait Itertools: Iterator {
29562956
Self::Item: Ord,
29572957
{
29582958
// The stdlib heap has optimised handling of "holes", which is not included in our heap implementation in k_smallest_general.
2959-
// While the difference is unlikely to have practical impact unless `T` is very large, this method uses the stdlib structure
2959+
// While the difference is unlikely to have practical impact unless `Self::Item` is very large, this method uses the stdlib structure
29602960
// to maintain performance compared to previous versions of the crate.
29612961
use alloc::collections::BinaryHeap;
29622962

@@ -3011,7 +3011,7 @@ pub trait Itertools: Iterator {
30113011
/// Sort the k largest elements into a new iterator, in descending order.
30123012
/// Semantically equivalent to `k_smallest` with a reversed `Ord`
30133013
/// However, this is implemented by way of a custom binary heap
3014-
/// which does not have the same performance characteristics for very large `T`
3014+
/// which does not have the same performance characteristics for very large `Self::Item`
30153015
/// ```
30163016
/// use itertools::Itertools;
30173017
///
@@ -3030,7 +3030,7 @@ pub trait Itertools: Iterator {
30303030
Self: Sized,
30313031
Self::Item: Ord,
30323032
{
3033-
self.k_smallest_by(k, k_smallest::reverse_cmp(Self::Item::cmp))
3033+
self.k_largest_by(k, Self::Item::cmp)
30343034
}
30353035

30363036
/// Sort the k largest elements into a new iterator using the provided comparison.
@@ -3041,7 +3041,7 @@ pub trait Itertools: Iterator {
30413041
Self: Sized,
30423042
F: Fn(&Self::Item, &Self::Item) -> Ordering,
30433043
{
3044-
self.k_smallest_by(k, k_smallest::reverse_cmp(cmp))
3044+
self.k_smallest_by(k, move |a, b| cmp(b, a))
30453045
}
30463046

30473047
/// Return the elements producing the k largest outputs of the provided function

0 commit comments

Comments
 (0)