priorityqueue

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package priorityqueue provides an interface and implementations for the priority queue abstract data type

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MaxHeapPriorityQueue

type MaxHeapPriorityQueue[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

PriorityQueue is a list of elements which each have a priority. When polling the queue, the highest priority item is returned.

func NewMaxHeapPriorityQueue

func NewMaxHeapPriorityQueue[T cmp.Ordered]() *MaxHeapPriorityQueue[T]

NewPriorityQueue instantiates a priority queue and returns a pointer to it.

func (*MaxHeapPriorityQueue[T]) Extract

func (q *MaxHeapPriorityQueue[T]) Extract() (T, bool)

Poll removes the highest-priority item and returns it. It returns a Boolean that is false if the priority queue was empty. In cases where the priority queue was empty then the zero value of the type will be returned but this is meaningless.

func (*MaxHeapPriorityQueue[T]) Insert

func (q *MaxHeapPriorityQueue[T]) Insert(i T)

Add adds an item the priority queue.

func (*MaxHeapPriorityQueue[T]) Peek

func (q *MaxHeapPriorityQueue[T]) Peek() (T, bool)

Peek returns the highest-priority item in the priority queue but, unlike poll, does not remove it. It also returns a Boolean that is false if the priority queue was empty. In cases where the priority queue was empty, the zero value for the type will be returned but this is meaningless.

func (*MaxHeapPriorityQueue[T]) Size

func (q *MaxHeapPriorityQueue[T]) Size() int

Size returns the number of items in the priority queue.

type PriorityQueue

type PriorityQueue[T cmp.Ordered] interface {
	Size() int
	Insert(T)
	Extract() (T, bool)
	Peek() (T, bool)
}

Jump to

Keyboard shortcuts

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