Documentation
¶
Index ¶
- type Item
- type Ordered
- type PriorityQueue
- func (pq *PriorityQueue[T, P]) Clear()
- func (pq *PriorityQueue[T, P]) IsEmpty() bool
- func (pq *PriorityQueue[T, P]) Items() []Item[T, P]
- func (pq *PriorityQueue[T, P]) Len() int
- func (pq *PriorityQueue[T, P]) Peek() T
- func (pq *PriorityQueue[T, P]) PeekPriority() P
- func (pq *PriorityQueue[T, P]) Pop() T
- func (pq *PriorityQueue[T, P]) Push(value T, priority P)
- func (pq *PriorityQueue[T, P]) Remove(value T, equals func(T, T) bool) bool
- func (pq *PriorityQueue[T, P]) String() string
- func (pq *PriorityQueue[T, P]) UpdatePriority(value T, newPriority P, equals func(T, T) bool) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ordered ¶
type Ordered interface {
constraints.Ordered
}
Ordered represents types that can be ordered.
type PriorityQueue ¶
PriorityQueue is a generic priority queue implementation using a binary heap. Lower priority values are dequeued first (min-heap by default).
func New ¶
func New[T any, P Ordered]() *PriorityQueue[T, P]
New creates a new min-heap priority queue.
func NewMax ¶
func NewMax[T any, P Ordered]() *PriorityQueue[T, P]
NewMax creates a new max-heap priority queue. Higher priority values are dequeued first.
func (*PriorityQueue[T, P]) Clear ¶
func (pq *PriorityQueue[T, P]) Clear()
Clear removes all items from the queue.
func (*PriorityQueue[T, P]) IsEmpty ¶
func (pq *PriorityQueue[T, P]) IsEmpty() bool
IsEmpty returns true if the queue is empty.
func (*PriorityQueue[T, P]) Items ¶
func (pq *PriorityQueue[T, P]) Items() []Item[T, P]
Items returns a slice of all items in the queue (not in priority order).
func (*PriorityQueue[T, P]) Len ¶
func (pq *PriorityQueue[T, P]) Len() int
Len returns the number of items in the queue.
func (*PriorityQueue[T, P]) Peek ¶
func (pq *PriorityQueue[T, P]) Peek() T
Peek returns the item with the highest priority without removing it. Panics if the queue is empty.
func (*PriorityQueue[T, P]) PeekPriority ¶
func (pq *PriorityQueue[T, P]) PeekPriority() P
PeekPriority returns the priority of the item at the front of the queue. Panics if the queue is empty.
func (*PriorityQueue[T, P]) Pop ¶
func (pq *PriorityQueue[T, P]) Pop() T
Pop removes and returns the item with the highest priority. Panics if the queue is empty.
func (*PriorityQueue[T, P]) Push ¶
func (pq *PriorityQueue[T, P]) Push(value T, priority P)
Push adds an item to the queue with the given priority.
func (*PriorityQueue[T, P]) Remove ¶
func (pq *PriorityQueue[T, P]) Remove(value T, equals func(T, T) bool) bool
Remove finds and removes an item by value. Returns true if the item was found and removed, false otherwise. This is an O(n) operation.
func (*PriorityQueue[T, P]) String ¶
func (pq *PriorityQueue[T, P]) String() string
String returns a string representation of the priority queue.
func (*PriorityQueue[T, P]) UpdatePriority ¶
func (pq *PriorityQueue[T, P]) UpdatePriority(value T, newPriority P, equals func(T, T) bool) bool
UpdatePriority finds an item by value and updates its priority. Returns true if the item was found and updated, false otherwise. This is an O(n) operation.