Remove branches from sift_down_to_bottom loop
This commit is contained in:
parent
dc06a36074
commit
6dfcf9afde
1 changed files with 5 additions and 6 deletions
|
@ -563,15 +563,14 @@ impl<T: Ord> BinaryHeap<T> {
|
|||
unsafe {
|
||||
let mut hole = Hole::new(&mut self.data, pos);
|
||||
let mut child = 2 * pos + 1;
|
||||
while child < end {
|
||||
let right = child + 1;
|
||||
// compare with the greater of the two children
|
||||
if right < end && hole.get(child) <= hole.get(right) {
|
||||
child = right;
|
||||
}
|
||||
while child < end - 1 {
|
||||
child += (hole.get(child) <= hole.get(child + 1)) as usize;
|
||||
hole.move_to(child);
|
||||
child = 2 * hole.pos() + 1;
|
||||
}
|
||||
if child == end - 1 {
|
||||
hole.move_to(child);
|
||||
}
|
||||
pos = hole.pos;
|
||||
}
|
||||
self.sift_up(start, pos);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue