Skip to content

Commit e2e04f8

Browse files
committed
More comments
1 parent fe5a8d8 commit e2e04f8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/k_smallest.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ where
77
I: Iterator,
88
F: FnMut(&I::Item, &I::Item) -> Ordering,
99
{
10-
/// Sift the element currently at `origin` **away** from the root until it is properly ordered
10+
/// Sift the element currently at `origin` away from the root until it is properly ordered
11+
///
12+
/// This will leave **larger** elements closer to the root of the heap
1113
fn sift_down<T, F>(heap: &mut [T], is_less_than: &mut F, mut origin: usize)
1214
where
1315
F: FnMut(&T, &T) -> bool,
@@ -56,6 +58,7 @@ where
5658
// So feed them into the heap
5759
// Also avoids unexpected behaviour with restartable iterators
5860
iter.for_each(|val| {
61+
// `for_each` is potentially more performant for deeply nested iterators, see its docs.
5962
if is_less_than(&val, &mut storage[0]) {
6063
// Treating this as an push-and-pop saves having to write a sift-up implementation
6164
// https://en.wikipedia.org/wiki/Binary_heap#Insert_then_extract

0 commit comments

Comments
 (0)