File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change 1414 where
1515 F : FnMut ( & T , & T ) -> bool ,
1616 {
17+ #[ inline]
1718 fn children_of ( n : usize ) -> ( usize , usize ) {
1819 ( 2 * n + 1 , 2 * n + 2 )
1920 }
4748
4849 let mut is_less_than = move |a : & _ , b : & _ | comparator ( a, b) == Ordering :: Less ;
4950
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
5152 // Slightly faster than ordering on each insert, but only by a factor of lg(k)
5253 // The resulting heap has the **largest** item on top
5354 for i in ( 0 ..=( storage. len ( ) / 2 ) ) . rev ( ) {
5960 // So feed them into the heap
6061 // Also avoids unexpected behaviour with restartable iterators
6162 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 ] ) {
6464 // Treating this as an push-and-pop saves having to write a sift-up implementation
6565 // https://en.wikipedia.org/wiki/Binary_heap#Insert_then_extract
6666 storage[ 0 ] = val;
8888 storage
8989}
9090
91+ #[ inline]
9192pub ( crate ) fn key_to_cmp < T , K , F > ( key : F ) -> impl Fn ( & T , & T ) -> Ordering
9293where
9394 F : Fn ( & T ) -> K ,
You can’t perform that action at this time.
0 commit comments