Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Heap ¶
type Heap[T any] struct { // contains filtered or unexported fields }
Heap implements the classic heap data-structure. A Heap is not safe for concurrent operations.
func (*Heap[T]) Peek ¶
Peek returns the minium element (according to the LessFunc) in the heap, it does not remove the item from the heap. The complexity is O(1).
type Ordered ¶
type Ordered interface { constraints.Integer | ~string }
type PriorityQueue ¶
PriorityQueue is a heap-based priority queue implementation.
It can be either min (ascending) or max (descending) oriented/ordered. The type parameters `P` and `V` specify the type of the underlying priority and value.
A PriorityQueue is not safe for concurrent operations.
func NewMaxPriorityQueue ¶ added in v2.12.4
func NewMaxPriorityQueue[P Ordered, V any]() *PriorityQueue[P, V]
NewMaxPriorityQueue creates a new maximum oriented PriorityQueue.
func NewMinPriorityQueue ¶ added in v2.12.4
func NewMinPriorityQueue[P Ordered, V any]() *PriorityQueue[P, V]
NewMinPriorityQueue creates a new minimum oriented PriorityQueue.
func (*PriorityQueue[P, V]) Len ¶
func (pq *PriorityQueue[P, V]) Len() int
Len returns the size of the PriorityQueue.
func (*PriorityQueue[P, V]) Peek ¶
func (pq *PriorityQueue[P, V]) Peek() (priority P, value V, ok bool)
Peek returns the most priority value in the PriorityQueue, it does not remove the value from the queue.
func (*PriorityQueue[P, V]) Pop ¶
func (pq *PriorityQueue[P, V]) Pop() (priority P, value V, ok bool)
Pop removes and returns the most priority value in the PriorityQueue.
func (*PriorityQueue[P, V]) Push ¶
func (pq *PriorityQueue[P, V]) Push(priority P, value V)
Push adds a value with priority to the PriorityQueue.