File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change 7
7
I : Iterator ,
8
8
F : FnMut ( & I :: Item , & I :: Item ) -> Ordering ,
9
9
{
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
11
13
fn sift_down < T , F > ( heap : & mut [ T ] , is_less_than : & mut F , mut origin : usize )
12
14
where
13
15
F : FnMut ( & T , & T ) -> bool ,
56
58
// So feed them into the heap
57
59
// Also avoids unexpected behaviour with restartable iterators
58
60
iter. for_each ( |val| {
61
+ // `for_each` is potentially more performant for deeply nested iterators, see its docs.
59
62
if is_less_than ( & val, & mut storage[ 0 ] ) {
60
63
// Treating this as an push-and-pop saves having to write a sift-up implementation
61
64
// https://en.wikipedia.org/wiki/Binary_heap#Insert_then_extract
You can’t perform that action at this time.
0 commit comments