Documentation
¶
Overview ¶
Package priorityqueue provides a generic priority queue with Insert, PopMax, and RemoveFunc operations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PriorityQueue ¶
type PriorityQueue[T any] struct { // contains filtered or unexported fields }
PriorityQueue is a generic priority queue with a configurable comparison function.
func New ¶
func New[T any](sizeHint int, cmp func(a, b T) int) *PriorityQueue[T]
New creates a new PriorityQueue, configured with a function that compares the priorities of two items a and b; it should return a number > 0 if the priority of a is higher, 0 if the priorities are equal, and a number < 0 otherwise. sizeHint sets the initial capacity of the queue; -1 means to use the default.
func (*PriorityQueue[T]) Insert ¶
func (pq *PriorityQueue[T]) Insert(elem T)
Insert inserts a new element into the priority queue.
func (*PriorityQueue[T]) Len ¶
func (pq *PriorityQueue[T]) Len() int
Len returns the length (number of items) of the priority queue.
func (*PriorityQueue[T]) PopMax ¶
func (pq *PriorityQueue[T]) PopMax() T
PopMax returns the element with the maximal priority in the queue, and removes it from the queue. Warning: to maintain a clean API, PopMax panics if the queue is empty. Make sure to check Len() first.
func (*PriorityQueue[T]) RemoveFunc ¶
func (pq *PriorityQueue[T]) RemoveFunc(rm func(T) bool)
RemoveFunc removes all elements for which rm returns true.