Skip to content

Commit

Permalink
Update binarywithremove.go
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzotinfena committed Mar 4, 2024
1 parent a1357e3 commit 3fba76e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions collections/heap/binarywithremove.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ func (h *BinaryHeapWithRemove[T]) Push(value T) {
func (h *BinaryHeapWithRemove[T]) Pop() (res T) {
res = h.v[0]
h.m.Remove(h.v[0], 0)
h.v[0] = h.v[h.Len()-1]
h.m.Remove(h.v[0], h.Len()-1)
h.m.Add(h.v[0], 0)
if len(h.v) > 1 {
h.v[0] = h.v[h.Len()-1]
h.m.Remove(h.v[0], h.Len()-1)
h.m.Add(h.v[0], 0)
}
h.v = h.v[:h.Len()-1]
h.heapifyDown(0)
if len(h.v) > 0 {
h.heapifyDown(0)
}
return
}

Expand Down

0 comments on commit 3fba76e

Please sign in to comment.