indexedpriorityqueue

package
v0.0.0-...-ec0d933 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparator

type Comparator[T any] func(a, b T) int

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL