Documentation
¶
Index ¶
- type PriorityQueue
- func (self *PriorityQueue[T]) ChangePriority(index int, value T)
- func (self *PriorityQueue[T]) Count() int
- func (self *PriorityQueue[T]) Dequeue() (T, bool)
- func (self *PriorityQueue[T]) Enqueue(element T)
- func (self *PriorityQueue[T]) IndexOf(element T) int
- func (self *PriorityQueue[T]) IsEmpty() bool
- func (self *PriorityQueue[T]) Peek() (T, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PriorityQueue ¶
type PriorityQueue[T comparable] struct { // contains filtered or unexported fields }
Priority Queue, a queue where the most "important" items are at the front of the queue.
The heap is a natural data structure for a priority queue, so this object simply wraps the Heap struct.
All operations are O(lg n).
Just like a heap can be a max-heap or min-heap, the queue can be a max-priority queue (largest element first) or a min-priority queue (smallest element first).
func PriorityQueueInit ¶
func PriorityQueueInit[T comparable](sort func(T, T) bool) *PriorityQueue[T]
To create a max-priority queue, supply a GreaterThan sort function. For a min-priority queue, use the LessThan sort function.
func (*PriorityQueue[T]) ChangePriority ¶
func (self *PriorityQueue[T]) ChangePriority(index int, value T)
Allows you to change the priority of an element. In a max-priority queue, the new priority should be larger than the old one; in a min-priority queue it should be smaller.
func (*PriorityQueue[T]) Count ¶
func (self *PriorityQueue[T]) Count() int
func (*PriorityQueue[T]) Dequeue ¶
func (self *PriorityQueue[T]) Dequeue() (T, bool)
func (*PriorityQueue[T]) Enqueue ¶
func (self *PriorityQueue[T]) Enqueue(element T)
func (*PriorityQueue[T]) IndexOf ¶
func (self *PriorityQueue[T]) IndexOf(element T) int
func (*PriorityQueue[T]) IsEmpty ¶
func (self *PriorityQueue[T]) IsEmpty() bool
func (*PriorityQueue[T]) Peek ¶
func (self *PriorityQueue[T]) Peek() (T, bool)