File tree 1 file changed +4
-3
lines changed
1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change 14
14
where
15
15
F : FnMut ( & T , & T ) -> bool ,
16
16
{
17
+ #[ inline]
17
18
fn children_of ( n : usize ) -> ( usize , usize ) {
18
19
( 2 * n + 1 , 2 * n + 2 )
19
20
}
47
48
48
49
let mut is_less_than = move |a : & _ , b : & _ | comparator ( a, b) == Ordering :: Less ;
49
50
50
- // Rearrange the into a valid heap by reordering from the second-bottom-most layer up to the root
51
+ // Rearrange the storage into a valid heap by reordering from the second-bottom-most layer up to the root
51
52
// Slightly faster than ordering on each insert, but only by a factor of lg(k)
52
53
// The resulting heap has the **largest** item on top
53
54
for i in ( 0 ..=( storage. len ( ) / 2 ) ) . rev ( ) {
59
60
// So feed them into the heap
60
61
// Also avoids unexpected behaviour with restartable iterators
61
62
iter. for_each ( |val| {
62
- // `for_each` is potentially more performant for deeply nested iterators, see its docs.
63
- if is_less_than ( & val, & mut storage[ 0 ] ) {
63
+ if is_less_than ( & val, & storage[ 0 ] ) {
64
64
// Treating this as an push-and-pop saves having to write a sift-up implementation
65
65
// https://en.wikipedia.org/wiki/Binary_heap#Insert_then_extract
66
66
storage[ 0 ] = val;
88
88
storage
89
89
}
90
90
91
+ #[ inline]
91
92
pub ( crate ) fn key_to_cmp < T , K , F > ( key : F ) -> impl Fn ( & T , & T ) -> Ordering
92
93
where
93
94
F : Fn ( & T ) -> K ,
You can’t perform that action at this time.
0 commit comments