Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPriorityQueueIsEmpty = errors.New("priority queue is empty")
ErrPriorityQueueIsEmpty is returned when the priority queue is empty.
Functions ¶
This section is empty.
Types ¶
type PriorityQueue ¶
type PriorityQueue[K constraints.Ordered, V any] struct { // contains filtered or unexported fields }
PriorityQueue represents a priority queue with items of type V and priorities of type K. The item with the highest priority is always at the front of the queue. The priority queue is implemented using a max heap.
func New ¶
func New[K constraints.Ordered, V any]() *PriorityQueue[K, V]
New creates a new, empty priority queue with items of type V and priorities of type K.
func (*PriorityQueue[K, V]) Dequeue ¶
func (pq *PriorityQueue[K, V]) Dequeue() (V, error)
Dequeue removes the item with the highest priority from the priority queue.
func (*PriorityQueue[K, V]) Enqueue ¶
func (pq *PriorityQueue[K, V]) Enqueue(priority K, value V)
Enqueue adds an item to the priority queue.
func (*PriorityQueue[K, V]) IsEmpty ¶
func (pq *PriorityQueue[K, V]) IsEmpty() bool
IsEmpty returns true if the priority queue is empty, false otherwise.
func (*PriorityQueue[K, V]) Peek ¶
func (pq *PriorityQueue[K, V]) Peek() (V, error)
Peek returns the item with the highest priority from the priority queue without removing it.
func (*PriorityQueue[K, V]) Size ¶
func (pq *PriorityQueue[K, V]) Size() int
Size returns the size of the priority queue.