priorityqueue

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package priorityqueue provides a generic priority queue with Insert, PopMax, and RemoveFunc operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PriorityQueue

type PriorityQueue[T any] struct {
	// contains filtered or unexported fields
}

PriorityQueue is a generic priority queue with a configurable comparison function.

func New

func New[T any](sizeHint int, cmp func(a, b T) int) *PriorityQueue[T]

New creates a new PriorityQueue, configured with a function that compares the priorities of two items a and b; it should return a number > 0 if the priority of a is higher, 0 if the priorities are equal, and a number < 0 otherwise. sizeHint sets the initial capacity of the queue; -1 means to use the default.

func (*PriorityQueue[T]) Insert

func (pq *PriorityQueue[T]) Insert(elem T)

Insert inserts a new element into the priority queue.

func (*PriorityQueue[T]) Len

func (pq *PriorityQueue[T]) Len() int

Len returns the length (number of items) of the priority queue.

func (*PriorityQueue[T]) PopMax

func (pq *PriorityQueue[T]) PopMax() T

PopMax returns the element with the maximal priority in the queue, and removes it from the queue. Warning: to maintain a clean API, PopMax panics if the queue is empty. Make sure to check Len() first.

func (*PriorityQueue[T]) RemoveFunc

func (pq *PriorityQueue[T]) RemoveFunc(rm func(T) bool)

RemoveFunc removes all elements for which rm returns true.

Jump to

Keyboard shortcuts

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