Documentation
¶
Index ¶
- type Comparator
- type IndexedPriorityQueue
- func (ipq *IndexedPriorityQueue[T, K]) Clear()
- func (ipq *IndexedPriorityQueue[T, K]) Dequeue() (T, bool)
- func (ipq *IndexedPriorityQueue[T, K]) Enqueue(value T)
- func (ipq *IndexedPriorityQueue[T, K]) Get(key K) (T, bool)
- func (ipq *IndexedPriorityQueue[T, K]) Len() int
- func (ipq *IndexedPriorityQueue[T, K]) Peek() (T, bool)
- func (ipq *IndexedPriorityQueue[T, K]) Remove(key K) (T, bool)
- type KeyExtractor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comparator ¶
Comparator defines the function signature for comparing two elements. It should return:
- negative value if a < b
- zero if a == b
- positive value if a > b
type IndexedPriorityQueue ¶
type IndexedPriorityQueue[T any, K comparable] struct { // contains filtered or unexported fields }
IndexedPriorityQueue represents a priority queue where elements can be accessed and updated by a key.
func New ¶
func New[T any, K comparable](comparator Comparator[T], keyFunc KeyExtractor[T, K]) *IndexedPriorityQueue[T, K]
New creates a new IndexedPriorityQueue.
- comparator: Function to determine the priority between two elements.
- keyFunc: Function to extract the unique key K from an element T.
func NewOrdered ¶
func NewOrdered[O cmp.Ordered]() *IndexedPriorityQueue[O, O]
func (*IndexedPriorityQueue[T, K]) Clear ¶
func (ipq *IndexedPriorityQueue[T, K]) Clear()
Clear removes all elements from the queue.
func (*IndexedPriorityQueue[T, K]) Dequeue ¶
func (ipq *IndexedPriorityQueue[T, K]) Dequeue() (T, bool)
Dequeue removes and returns the highest priority element from the queue. Returns the element and true if the queue is not empty, otherwise the zero value of T and false.
func (*IndexedPriorityQueue[T, K]) Enqueue ¶
func (ipq *IndexedPriorityQueue[T, K]) Enqueue(value T)
Enqueue adds an element to the priority queue. If an element with the same key already exists it is replaced by the new one.
func (*IndexedPriorityQueue[T, K]) Get ¶
func (ipq *IndexedPriorityQueue[T, K]) Get(key K) (T, bool)
Get retrieves the element associated with the given key without removing it. Returns the element and true if the key exists, otherwise the zero value of T and false.
func (*IndexedPriorityQueue[T, K]) Len ¶
func (ipq *IndexedPriorityQueue[T, K]) Len() int
Len returns the number of elements in the queue.
func (*IndexedPriorityQueue[T, K]) Peek ¶
func (ipq *IndexedPriorityQueue[T, K]) Peek() (T, bool)
Peek returns the highest priority element without removing it. Returns the element and true if the queue is not empty, otherwise the zero value of T and false.
func (*IndexedPriorityQueue[T, K]) Remove ¶
func (ipq *IndexedPriorityQueue[T, K]) Remove(key K) (T, bool)
Remove removes the element associated with the given key from the queue. Returns the removed element and true if the key existed, otherwise the zero value of T and false.
type KeyExtractor ¶
type KeyExtractor[T any, K comparable] func(item T) K
KeyExtractor defines the function signature for extracting a key K from an element T.