Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element[T any] struct { // The value stored with this element. Value T // contains filtered or unexported fields }
Element is an element of the PriorityQueue.
type PriorityQueue ¶
type PriorityQueue[T any] struct { // contains filtered or unexported fields }
PriorityQueue this implementation is based on https://golang.org/pkg/container/heap/ High priority is closer to -infinity. Low priority is closer to +infinity. Note: This is not a thread-safe implementation.
func NewPriorityQueue ¶
func NewPriorityQueue[T any]() *PriorityQueue[T]
NewPriorityQueue creates a new PriorityQueue.
func (*PriorityQueue[T]) Len ¶
func (pq *PriorityQueue[T]) Len() int
Len returns the number of elements in the queue. O(1)
func (*PriorityQueue[T]) Peek ¶
func (pq *PriorityQueue[T]) Peek() *Element[T]
Peek returns the highest priority element without removing it. O(1)
func (*PriorityQueue[T]) Pop ¶
func (pq *PriorityQueue[T]) Pop() *Element[T]
Pop removes the highest priority element from the queue and returns it. O(log(n))
func (*PriorityQueue[T]) Push ¶
func (pq *PriorityQueue[T]) Push(x T, priority int64) *Element[T]
Push pushes a new element to the queue. O(log(n)) High priority is closer to -infinity. Low priority is closer to +infinity. Two elements with the same priority are ordered by insertion order with the first element inserted being the first returned by Pop.
func (*PriorityQueue[T]) Remove ¶
func (pq *PriorityQueue[T]) Remove(item *Element[T]) bool
Remove removes an element from the queue. O(log(n)) It returns true if the element was removed, false otherwise.