pq

package module
v0.0.0-...-342bdc4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: MIT Imports: 2 Imported by: 0

README

go-priority-queue Build Status Coverage Status Go Report Card GoDoc

A priority queue implementation on top of container/heap

Documentation

Overview

Package pq implements a priority queue data structure on top of container/heap. As an addition to regular operations, it allows an update of an items priority, allowing the queue to be used in graph search algorithms like Dijkstra's algorithm. Computational complexities of operations are mainly determined by container/heap. In addition, a map of items is maintained, allowing O(1) lookup needed for priority updates, which themselves are O(log n).

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyQueue = errors.New("empty queue")

Functions

This section is empty.

Types

type PriorityQueue

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

PriorityQueue[T] represents the queue of comparable type T.

func New

func New[T comparable]() PriorityQueue[T]

New[T] initializes an empty priority queue of type T.

func (*PriorityQueue[T]) Insert

func (p *PriorityQueue[T]) Insert(v T, priority float64)

Insert inserts a new element into the queue. No action is performed on duplicate elements.

func (*PriorityQueue[T]) Len

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

Len returns the number of elements in the queue.

func (*PriorityQueue[T]) Pop

func (p *PriorityQueue[T]) Pop() (T, error)

Pop removes the element with the highest priority from the queue and returns it. In case of an empty queue, an error is returned.

func (*PriorityQueue[T]) UpdatePriority

func (p *PriorityQueue[T]) UpdatePriority(x T, newPriority float64)

UpdatePriority changes the priority of a given item. If the specified item is not present in the queue, no action is performed.

Jump to

Keyboard shortcuts

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