pq

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 2 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 any] struct {
	// contains filtered or unexported fields
}

Queue is a priority queue implementation based on a binary heap. By default, the queue is a min-heap, but a custom comparator can be provided.

func New

func New[T any](comparator comparison.Comparator[T]) *Queue[T]

New creates a new priority queue with the given comparator.

func NewFromIterable added in v1.6.1

func NewFromIterable[T any](comparator comparison.Comparator[T], iterable iter.Iterable[T]) *Queue[T]

NewFromIterable creates a new Queue with the given comparator and elements from the given iter.Iterable

func (*Queue[T]) Empty

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

Empty returns true if the queue is empty.

func (*Queue[T]) PeekFront

func (pq *Queue[T]) PeekFront() T

PeekFront returns the element at the front of the queue. Panics if the queue is empty.

func (*Queue[T]) PopFront

func (pq *Queue[T]) PopFront() T

PopFront removes and returns the element at the front of the queue. Panics if the queue is empty.

func (*Queue[T]) PushBack

func (pq *Queue[T]) PushBack(value T)

PushBack pushes a new element into the queue. The element is inserted at the end of the queue and then moved up the heap until the heap property is satisfied.

Jump to

Keyboard shortcuts

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