Documentation ¶
Overview ¶
Package fibHeap implements the Fibonacci Heap priority queue. This implementation is a bit different from the traditional Fibonacci Heap by having an index map to achieve better encapsulation.
Index ¶
- type FibHeap
- func (heap *FibHeap) DecreaseKey(tag interface{}, key float64) error
- func (heap *FibHeap) DecreaseKeyValue(value Value) error
- func (heap *FibHeap) Delete(tag interface{}) error
- func (heap *FibHeap) DeleteValue(value Value) error
- func (heap *FibHeap) ExtractMin() (interface{}, float64)
- func (heap *FibHeap) ExtractMinValue() Value
- func (heap *FibHeap) ExtractTag(tag interface{}) (key float64)
- func (heap *FibHeap) ExtractValue(tag interface{}) (value Value)
- func (heap *FibHeap) GetTag(tag interface{}) (key float64)
- func (heap *FibHeap) GetValue(tag interface{}) (value Value)
- func (heap *FibHeap) IncreaseKey(tag interface{}, key float64) error
- func (heap *FibHeap) IncreaseKeyValue(value Value) error
- func (heap *FibHeap) Insert(tag interface{}, key float64) error
- func (heap *FibHeap) InsertValue(value Value) error
- func (heap *FibHeap) Minimum() (interface{}, float64)
- func (heap *FibHeap) MinimumValue() Value
- func (heap *FibHeap) Num() uint
- func (heap *FibHeap) String() string
- func (heap *FibHeap) Union(anotherHeap *FibHeap) error
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FibHeap ¶
type FibHeap struct {
// contains filtered or unexported fields
}
FibHeap represents a Fibonacci Heap. Please note that all methods of FibHeap are not concurrent safe.
func (*FibHeap) DecreaseKey ¶
DecreaseKey updates the tag in the heap by the input key. If the input key has a larger key or -inf key, an error will be returned. If the input tag is not existed in the heap, an error will be returned. DecreaseKey will check the nil interface but not the interface with nil value. Try to input of an interface with nil value will cause invalid address panic.
func (*FibHeap) DecreaseKeyValue ¶
DecreaseKeyValue updates the value in the heap by the input value. If the input value has a larger key or -inf key, an error will be returned. If the tag of the input value is not existed in the heap, an error will be returned. DecreaseKeyValue will check the nil interface but not the interface with nil value. Try to input of an interface with nil value will cause invalid address panic.
func (*FibHeap) Delete ¶
Delete deletes the input tag in the heap. If the input tag is not existed in the heap, an error will be returned. Delete will check the nil interface but not the interface with nil value. Try to input of an interface with nil value will cause invalid address panic.
func (*FibHeap) DeleteValue ¶
DeleteValue deletes the value in the heap by the input value. If the tag of the input value is not existed in the heap, an error will be returned. DeleteValue will check the nil interface but not the interface with nil value. Try to input of an interface with nil value will cause invalid address panic.
func (*FibHeap) ExtractMin ¶
ExtractMin returns the current minimum tag and key in the heap and then extracts them from the heap. An empty heap will return nil/-inf and extracts nothing.
func (*FibHeap) ExtractMinValue ¶
ExtractMinValue returns the current minimum value in the heap and then extracts it from the heap. An empty heap will return nil and extracts nothing.
func (*FibHeap) ExtractTag ¶
ExtractTag searches and extracts the tag/key in the heap by the input tag. If the input tag does not exist in the heap, nil will be returned. ExtractTag will extract the value so the value will no longer exist in the heap.
func (*FibHeap) ExtractValue ¶
ExtractValue searches and extracts the value in the heap by the input tag. If the input tag does not exist in the heap, nil will be returned. ExtractValue will extract the value so the value will no longer exist in the heap.
func (*FibHeap) GetTag ¶
GetTag searches and returns the key in the heap by the input tag. If the input tag does not exist in the heap, nil will be returned. GetTag will not extract the value so the value will still exist in the heap.
func (*FibHeap) GetValue ¶
GetValue searches and returns the value in the heap by the input tag. If the input tag does not exist in the heap, nil will be returned. GetValue will not extract the value so the value will still exist in the heap.
func (*FibHeap) IncreaseKey ¶
IncreaseKey updates the tag in the heap by the input key. If the input key has a smaller key or -inf key, an error will be returned. If the input tag is not existed in the heap, an error will be returned. IncreaseKey will check the nil interface but not the interface with nil value. Try to input of an interface with nil value will cause invalid address panic.
func (*FibHeap) IncreaseKeyValue ¶
IncreaseKeyValue updates the value in the heap by the input value. If the input value has a smaller key or -inf key, an error will be returned. If the tag of the input value is not existed in the heap, an error will be returned. IncreaseKeyValue will check the nil interface but not the interface with nil value. Try to input of an interface with nil value will cause invalid address panic.
func (*FibHeap) Insert ¶
Insert pushes the input tag and key into the heap. Try to insert a duplicate tag value will cause an error return. The valid range of the key is (-inf, +inf]. Try to insert a -inf key value will cause an error return. Insert will check the nil interface but not the interface with nil value. Try to input of an interface with nil value will cause invalid address panic.
func (*FibHeap) InsertValue ¶
InsertValue pushes the input value into the heap. The input value must implements the Value interface. Try to insert a duplicate tag value will cause an error return. The valid range of the value's key is (-inf, +inf]. Try to insert a -inf key value will cause an error return. Insert will check the nil interface but not the interface with nil value. Try to input of an interface with nil value will cause invalid address panic.
func (*FibHeap) Minimum ¶
Minimum returns the current minimum tag and key in the heap sorted by the key. Minimum will not extract the tag and key so the value will still exists in the heap. An empty heap will return nil and -inf.
func (*FibHeap) MinimumValue ¶
MinimumValue returns the current minimum value in the heap sorted by the key. MinimumValue will not extract the value so the value will still exists in the heap. An empty heap will return nil.
type Value ¶
type Value interface { // Tag returns the unique tag of the value. // The tag is used in the index map. Tag() interface{} // Key returns the key as known as the priority of the value. // The valid range of the key is (-inf, +inf]. Key() float64 }
Value is the interface that all values push into or pop from the FibHeap by value interfaces must implement.