Documentation
¶
Overview ¶
Package heap implements various heap data structures
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinomialHeap ¶
type BinomialHeap struct {
// contains filtered or unexported fields
}
BinomialHeap represents a binomial heap data structure
func NewBinomialHeap ¶
func NewBinomialHeap() *BinomialHeap
NewBinomialHeap creates and returns a new instance of BinomialHeap
func (*BinomialHeap) Extract ¶
func (bh *BinomialHeap) Extract() (int, error)
Extract removes and returns the minimum element from the heap
func (*BinomialHeap) Insert ¶
func (bh *BinomialHeap) Insert(value int)
Insert adds a new value to the binomial heap
func (*BinomialHeap) IsEmpty ¶
func (bh *BinomialHeap) IsEmpty() bool
IsEmpty returns true if the heap contains no elements
func (*BinomialHeap) Peek ¶
func (bh *BinomialHeap) Peek() (int, error)
Peek returns the minimum element without removing it
func (*BinomialHeap) Size ¶
func (bh *BinomialHeap) Size() int
Size returns the number of elements in the heap
type BinomialNode ¶
type BinomialNode struct {
// contains filtered or unexported fields
}
BinomialNode represents a node in the binomial heap
type FibNode ¶
type FibNode struct {
// contains filtered or unexported fields
}
FibNode represents a node in the Fibonacci heap
type FibonacciHeap ¶
type FibonacciHeap struct {
// contains filtered or unexported fields
}
FibonacciHeap represents a Fibonacci heap data structure
func NewFibonacciHeap ¶
func NewFibonacciHeap() *FibonacciHeap
NewFibonacciHeap creates and returns a new instance of FibonacciHeap
func (*FibonacciHeap) DecreaseKey ¶
func (fh *FibonacciHeap) DecreaseKey(node *FibNode, newKey int) error
DecreaseKey decreases the key of a node
func (*FibonacciHeap) Extract ¶
func (fh *FibonacciHeap) Extract() (int, error)
Extract removes and returns the minimum element from the heap
func (*FibonacciHeap) Insert ¶
func (fh *FibonacciHeap) Insert(value int)
Insert adds a new value to the Fibonacci heap
func (*FibonacciHeap) IsEmpty ¶
func (fh *FibonacciHeap) IsEmpty() bool
IsEmpty returns true if the heap contains no elements
func (*FibonacciHeap) Peek ¶
func (fh *FibonacciHeap) Peek() (int, error)
Peek returns the minimum element without removing it
func (*FibonacciHeap) Size ¶
func (fh *FibonacciHeap) Size() int
Size returns the number of elements in the heap
type IHeap ¶
type IHeap interface { // Insert adds a new element to the heap Insert(value int) // Extract removes and returns the root element (min for MinHeap, max for MaxHeap) Extract() (int, error) // Peek returns the root element without removing it Peek() (int, error) // Size returns the number of elements in the heap Size() int // IsEmpty returns true if the heap has no elements IsEmpty() bool }
IHeap interface defines the basic operations that all heap implementations must provide
type LeftistHeap ¶ added in v1.1.0
type LeftistHeap struct {
// contains filtered or unexported fields
}
LeftistHeap represents a leftist heap data structure
func NewLeftistHeap ¶ added in v1.1.0
func NewLeftistHeap() *LeftistHeap
NewLeftistHeap creates a new empty leftist heap
func (*LeftistHeap) Clear ¶ added in v1.1.0
func (lh *LeftistHeap) Clear()
Clear removes all elements from the heap
func (*LeftistHeap) DeleteMin ¶ added in v1.1.0
func (lh *LeftistHeap) DeleteMin() (int, bool)
DeleteMin removes and returns the minimum element
func (*LeftistHeap) FindMin ¶ added in v1.1.0
func (lh *LeftistHeap) FindMin() (int, bool)
FindMin returns the minimum element without removing it
func (*LeftistHeap) Insert ¶ added in v1.1.0
func (lh *LeftistHeap) Insert(key int)
Insert adds a new key to the heap
func (*LeftistHeap) IsEmpty ¶ added in v1.1.0
func (lh *LeftistHeap) IsEmpty() bool
IsEmpty returns true if the heap is empty
func (*LeftistHeap) Merge ¶ added in v1.1.0
func (lh *LeftistHeap) Merge(other *LeftistHeap)
Merge combines two leftist heaps into one
func (*LeftistHeap) Size ¶ added in v1.1.0
func (lh *LeftistHeap) Size() int
Size returns the number of elements in the heap
type LeftistNode ¶ added in v1.1.0
type LeftistNode struct {
// contains filtered or unexported fields
}
LeftistNode represents a node in the Leftist Heap
type MaxHeapImpl ¶
type MaxHeapImpl struct {
// contains filtered or unexported fields
}
MaxHeapImpl represents a binary heap data structure that maintains the max-heap property
func NewMaxHeap ¶
func NewMaxHeap() *MaxHeapImpl
NewMaxHeap creates and returns a new instance of MaxHeapImpl
func (*MaxHeapImpl) Extract ¶
func (h *MaxHeapImpl) Extract() (int, error)
Extract removes and returns the maximum element from the heap
func (*MaxHeapImpl) Insert ¶
func (h *MaxHeapImpl) Insert(value int)
Insert adds a new value to the heap while maintaining the max-heap property
func (*MaxHeapImpl) IsEmpty ¶
func (h *MaxHeapImpl) IsEmpty() bool
IsEmpty returns true if the heap contains no elements
func (*MaxHeapImpl) Peek ¶
func (h *MaxHeapImpl) Peek() (int, error)
Peek returns the maximum element without removing it
func (*MaxHeapImpl) Size ¶
func (h *MaxHeapImpl) Size() int
Size returns the number of elements in the heap
type MinHeapImpl ¶
type MinHeapImpl struct {
// contains filtered or unexported fields
}
MinHeapImpl represents a binary heap data structure that maintains the min-heap property
func NewMinHeap ¶
func NewMinHeap() *MinHeapImpl
NewMinHeap creates and returns a new instance of MinHeapImpl
func (*MinHeapImpl) Extract ¶
func (h *MinHeapImpl) Extract() (int, error)
Extract removes and returns the minimum element from the heap
func (*MinHeapImpl) Insert ¶
func (h *MinHeapImpl) Insert(value int)
Insert adds a new value to the heap while maintaining the min-heap property
func (*MinHeapImpl) IsEmpty ¶
func (h *MinHeapImpl) IsEmpty() bool
IsEmpty returns true if the heap contains no elements
func (*MinHeapImpl) Peek ¶
func (h *MinHeapImpl) Peek() (int, error)
Peek returns the minimum element without removing it
func (*MinHeapImpl) Size ¶
func (h *MinHeapImpl) Size() int
Size returns the number of elements in the heap
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue implements a priority queue using a min heap
func NewPriorityQueue ¶
func NewPriorityQueue() *PriorityQueue
NewPriorityQueue creates and returns a new instance of PriorityQueue
func (*PriorityQueue) Dequeue ¶
func (pq *PriorityQueue) Dequeue() (interface{}, error)
Dequeue removes and returns the highest priority item
func (*PriorityQueue) Enqueue ¶
func (pq *PriorityQueue) Enqueue(value interface{}, priority int)
Enqueue adds a new item to the priority queue
func (*PriorityQueue) IsEmpty ¶
func (pq *PriorityQueue) IsEmpty() bool
IsEmpty returns true if the priority queue contains no elements
func (*PriorityQueue) Peek ¶
func (pq *PriorityQueue) Peek() (interface{}, error)
Peek returns the highest priority item without removing it
func (*PriorityQueue) Size ¶
func (pq *PriorityQueue) Size() int
Size returns the number of elements in the priority queue
type SkewHeap ¶ added in v1.1.0
type SkewHeap struct {
// contains filtered or unexported fields
}
SkewHeap represents a skew heap data structure
func NewSkewHeap ¶ added in v1.1.0
func NewSkewHeap() *SkewHeap
NewSkewHeap creates a new empty skew heap
func (*SkewHeap) Clear ¶ added in v1.1.0
func (sh *SkewHeap) Clear()
Clear removes all elements from the heap