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 {
|
unsafe {
|
||||||
let mut hole = Hole::new(&mut self.data, pos);
|
let mut hole = Hole::new(&mut self.data, pos);
|
||||||
let mut child = 2 * pos + 1;
|
let mut child = 2 * pos + 1;
|
||||||
while child < end {
|
while child < end - 1 {
|
||||||
let right = child + 1;
|
child += (hole.get(child) <= hole.get(child + 1)) as usize;
|
||||||
// compare with the greater of the two children
|
|
||||||
if right < end && hole.get(child) <= hole.get(right) {
|
|
||||||
child = right;
|
|
||||||
}
|
|
||||||
hole.move_to(child);
|
hole.move_to(child);
|
||||||
child = 2 * hole.pos() + 1;
|
child = 2 * hole.pos() + 1;
|
||||||
}
|
}
|
||||||
|
if child == end - 1 {
|
||||||
|
hole.move_to(child);
|
||||||
|
}
|
||||||
pos = hole.pos;
|
pos = hole.pos;
|
||||||
}
|
}
|
||||||
self.sift_up(start, pos);
|
self.sift_up(start, pos);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue