priorityqueue

package
v0.0.0-...-97e7716 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[T comparable] struct {
	// contains filtered or unexported fields
}

Queue represents a priority queue data structure. Elements are ordered according to their natural ordering (for Ordered types) or a custom comparator provided during initialization.

func New

func New[T cmp.Ordered]() *Queue[T]

New creates a new priority queue with the given Ordered type. The queue orders elements according to their natural ordering (ascending).

func NewWith

func NewWith[T comparable](comparator utils.Comparator[T]) *Queue[T]

NewWith creates a new priority queue with the given comparator. The queue orders elements according to the comparator provided.

func (*Queue[T]) Clear

func (queue *Queue[T]) Clear()

Clear removes all elements from the queue.

func (*Queue[T]) Dequeue

func (queue *Queue[T]) Dequeue() (value T, ok bool)

Dequeue removes and returns the element with the highest priority (minimum value). Returns ok=false if the queue is empty.

func (*Queue[T]) Enqueue

func (queue *Queue[T]) Enqueue(value T)

Enqueue adds an element to the priority queue.

func (*Queue[T]) IsEmpty

func (queue *Queue[T]) IsEmpty() bool

IsEmpty returns true if the queue contains no elements.

func (*Queue[T]) Peek

func (queue *Queue[T]) Peek() (value T, ok bool)

Peek returns the element with the highest priority (minimum value) without removing it. Returns ok=false if the queue is empty.

func (*Queue[T]) Size

func (queue *Queue[T]) Size() int

Size returns the number of elements in the queue.

Jump to

Keyboard shortcuts

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