pq

package
v0.0.0-...-b50cce2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package pq provides a priority queue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is a priority queue that supports updating the priority of an element. A Queue must be created with NewQueue.

func NewQueue

func NewQueue(less func(x, y interface{}) bool, setIndex func(x interface{}, idx int)) *Queue

NewQueue returns an unbounded priority queue that compares elements using less; the minimal element is at the top of the queue.

If setIndex is not nil, the queue calls setIndex to inform each element of its position in the queue. If an element's priority changes, its position in the queue may be incorrect. Call Fix on the element's index to update the queue. Call Remove on the element's index to remove it from the queue.

func (*Queue) Fix

func (pq *Queue) Fix(index int)

Fix adjusts the heap to reflect that the element at index has changed priority.

func (*Queue) Len

func (pq *Queue) Len() int

Len returns the number of elements in the queue.

func (*Queue) Min

func (pq *Queue) Min() interface{}

Min returns the minimal element. Min panics if the queue is empty.

func (*Queue) Pop

func (pq *Queue) Pop() interface{}

Pop removes and returns the minimal element. Pop panics if the queue is empty.

func (*Queue) Push

func (pq *Queue) Push(x interface{})

Push adds x to the queue.

func (*Queue) Remove

func (pq *Queue) Remove(index int)

Remove removes the element at index i from the heap.

Jump to

Keyboard shortcuts

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