Skip to content

Commit

Permalink
Update fibonacci.go
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzotinfena committed Mar 10, 2024
1 parent aef6498 commit 4ce0c67
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions collections/heap/fibonacci.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,34 +144,17 @@ func (fb *FibonacciHeap[T]) Remove(value T) {
// Assumptions:
// - last value in nodesMapGet(value) != fb.rootlist
func (fb *FibonacciHeap[T]) remove(value T) {
tmp := fb.nodesMapGet(value)
node := tmp[len(tmp)-1]
if len(tmp) == 1 {
fb.nodesMapRemove(node.value)
} else {
fb.nodesMapSet(node.value, tmp[:len(tmp)-1])
}

if node.parent == nil {
node.left.right = node.right
node.right.left = node.left
} else {
node.parent.degree--
if node.parent.child == node {
if node.parent.degree == 0 {
node.parent.child = nil
} else {
node.parent.child = node.right
}
tmp := fb.prior
fb.prior = func(t1, t2 T) bool {
if t1 == value {
return true
} else {
return tmp(t1, t2)
}
node.left.right = node.right
node.right.left = node.left
fb.mark(node.parent)
}

fb.appendSiblings(node.child)

fb.size--
fb.DecreaseKey(value, value)
fb.prior = tmp
fb.pop()
}

// Assumptions:
Expand Down

0 comments on commit 4ce0c67

Please sign in to comment.