pq

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PMin = false
	PMax = true
)

Variables

This section is empty.

Functions

This section is empty.

Types

type P added in v0.2.0

type P bool

P is the queue priority type, i.e. a queue backed by a min- or max-heap.

type PQ

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

PQ is a priority queue of arbitrary data with a maximum queue size. Data popped from the queue is of highest priority. The priority queue may be a max or min queue.

func New

func New[T any](size int, priority P) *PQ[T]

New creates a priority queue instance. Size indicates the maximum size of the heap -- a size of 0 indicates no limit on the queue size.

func (*PQ[T]) Empty

func (pq *PQ[T]) Empty() bool

func (*PQ[T]) Full

func (pq *PQ[T]) Full() bool

func (*PQ[T]) Len

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

func (*PQ[T]) Pop

func (pq *PQ[T]) Pop() (T, float64)

Pop removes the node with the highest (or lowest) priority from the queue.

func (*PQ[T]) Priority

func (pq *PQ[T]) Priority() float64

Priority calculates the current highest priority of the queue.

func (*PQ[T]) Push

func (pq *PQ[T]) Push(p T, priority float64)

Push adds a new point into the queue.

The queue will enforce the struct size constraint by removing elements from itself until the constraint is satisfied.

Jump to

Keyboard shortcuts

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