pq

package
v0.0.0-...-db2e5f8 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2019 License: BSD-2-Clause Imports: 1 Imported by: 1

Documentation

Overview

Package pq provides a priority queue, implemented as a heap

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

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

Item is an element of a priority queue.

func NewItem

func NewItem(priority int, value interface{}) *Item

NewItem creates a new item with given priority, index and value

func (*Item) GetPriority

func (i *Item) GetPriority() int

GetPriority returns priority of Item i

func (*Item) GetValue

func (i *Item) GetValue() interface{}

GetValue returns value of Item i

func (*Item) UpdatePriority

func (i *Item) UpdatePriority(newPriority int, pq *PriorityQueue)

UpdatePriority updates priorty of Item i in PriorityQueue pq

type PriorityQueue

type PriorityQueue []*Item

PriorityQueue is stored as a list of Items

func New

func New(reservedSize int) *PriorityQueue

New returns an empty priority queue with initial size 0 and reserved size reservedSize

func (*PriorityQueue) Contains

func (pq *PriorityQueue) Contains(el interface{}, same func(a, b interface{}) bool) *Item

Contains checks whether PriorityQueue pq contains element el, using function same for comparison

func (*PriorityQueue) Len

func (pq *PriorityQueue) Len() int

Len returns number of elements in the priority queue pq

func (*PriorityQueue) Less

func (pq *PriorityQueue) Less(i, j int) bool

Less returns true if priority of element on index i is smaller than priority of element on index j

func (*PriorityQueue) Pop

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

Pop returns the first element is the priority queue pq

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(el interface{})

Push adds el to the priority queue pq

func (*PriorityQueue) Swap

func (pq *PriorityQueue) Swap(i, j int)

Swap swaps elements with indices i and j in pq

Jump to

Keyboard shortcuts

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