Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct { // The value of the item; arbitrary. Value any // The priority of the item in the queue. Priority int }
An Item is something to be managed in a priority queue.
type PriorityQueue ¶
type PriorityQueue []*Item
A PriorityQueue implements heap.Interface and holds Items. This is a min-heap, so the item with the lowest priority is popped first.
func (*PriorityQueue) IsEmpty ¶
func (pq *PriorityQueue) IsEmpty() bool
IsEmpty is used to check whether the queue is empty or not (length == 0).
func (PriorityQueue) Len ¶
func (pq PriorityQueue) Len() int
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() (v any)
Pop removes and returns the minimum element (according to Item.Priority) from the queue.
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(v any)
Push pushes the value v in the queue.
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)
type Queue ¶
type Queue[T any] []T
Queue represents a simple queue data structure. It is backed by a slice of an unconstrained type T.
func New ¶
New returns an initialized queue, optionally with the given elements. The elements are added in the same order as provided.
func (*Queue[T]) Dequeue ¶
Dequeue is used to dequeue or remove the frontmost element from the queue and return it.
An attempt to dequeue when the queue is empty will return the zero value for the type of the elements in the queue. Using multiple assignment, one can distinguish a missing entry from a zero value. This is referred to as the "comma ok" idiom.
func (*Queue[T]) Enqueue ¶
func (q *Queue[T]) Enqueue(es ...T)
Enqueue is used to enqueue all the given elements to the queue. Multiple elements are added in the same order as provided.
func (*Queue[T]) Peek ¶
Peek returns the frontmost element of the queue without removing it.
An attempt to peek when the queue is empty will return the zero value for the type of the elements in the queue. Using multiple assignment, one can distinguish a missing entry from a zero value. This is referred to as the "comma ok" idiom.