Skip to content

Commit

Permalink
fix IntervalHeap::pop_max
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtkana committed Apr 4, 2024
1 parent d9c1553 commit c7d94ab
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions libs/interval_heap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ impl<T: Ord> IntervalHeap<T> {

/// Removes and returns $\max(S)$.
pub fn pop_max(&mut self) -> Option<T> {
if self.values.len() <= 1 {
if self.values.len() <= 2 {
return self.values.pop();
}
let ret = self.values.swap_remove(1);
if self.values.len() >= 3 {
max_heapify_down(&mut self.values, 1);
}
max_heapify_down(&mut self.values, 1);
Some(ret)
}

Expand Down

0 comments on commit c7d94ab

Please sign in to comment.