Documentation
¶
Overview ¶
Package priorityqueue provides an interface and implementations for the priority queue abstract data type
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MaxHeapPriorityQueue ¶
PriorityQueue is a list of elements which each have a priority. When polling the queue, the highest priority item is returned.
func NewMaxHeapPriorityQueue ¶
func NewMaxHeapPriorityQueue[T cmp.Ordered]() *MaxHeapPriorityQueue[T]
NewPriorityQueue instantiates a priority queue and returns a pointer to it.
func (*MaxHeapPriorityQueue[T]) Extract ¶
func (q *MaxHeapPriorityQueue[T]) Extract() (T, bool)
Poll removes the highest-priority item and returns it. It returns a Boolean that is false if the priority queue was empty. In cases where the priority queue was empty then the zero value of the type will be returned but this is meaningless.
func (*MaxHeapPriorityQueue[T]) Insert ¶
func (q *MaxHeapPriorityQueue[T]) Insert(i T)
Add adds an item the priority queue.
func (*MaxHeapPriorityQueue[T]) Peek ¶
func (q *MaxHeapPriorityQueue[T]) Peek() (T, bool)
Peek returns the highest-priority item in the priority queue but, unlike poll, does not remove it. It also returns a Boolean that is false if the priority queue was empty. In cases where the priority queue was empty, the zero value for the type will be returned but this is meaningless.
func (*MaxHeapPriorityQueue[T]) Size ¶
func (q *MaxHeapPriorityQueue[T]) Size() int
Size returns the number of items in the priority queue.