pqueue

package module
v0.0.0-...-3369327 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2012 License: BSD-2-Clause Imports: 1 Imported by: 0

README

## pqueue - Simple Go priority queue ##

pqueue is a very simple priority queue that satisfies the container/heap and
sort interfaces from the Go standard library.

### Install ###

    go get github.com/gnanderson/pqueue

### Usage ###

	see doc/example.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	QERR_OUT_OF_BOUNDS = Error("This index is out of bounds.")
	QERR_NOT_QUEUEABLE = Error("Object does not implemnt Queueable interface.")
)

Functions

This section is empty.

Types

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type Queue

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

Queue is the basic priority queue structure

func NewQueue

func NewQueue() *Queue

NeqQueue returns new Q object with default capacity of 100

func (*Queue) Add

func (q *Queue) Add(x Queueable)

Add a single object to the queue

func (*Queue) AddSlice

func (q *Queue) AddSlice(s []Queueable)

AddSlice pushes a slice of queueable objects onto the Q and then min-heaps the elements. complexity is O(n) where n = q.Len().

func (*Queue) Collection

func (q *Queue) Collection() []Queueable

Return the full collection (possibly unsorted & not min-heap initialised) use heap.Init(q) or sort.Sort(q) if you need the members sorted or min-heaped

func (*Queue) Len

func (q *Queue) Len() int

Len satisfies the sort interface

func (*Queue) Less

func (q *Queue) Less(i, j int) bool

Less satisfies the sort interface

func (*Queue) Member

func (q *Queue) Member(i int) (m Queueable, err error)

Member returns the queue member at index i

func (*Queue) Pop

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

Pop satisfies the heap interface, do not use directly

NOTE: This method pops elements from the Q and does not min-heapify the elements. User container/heap instead e.g. x, ok := heap.Pop(q).(Queueable)

func (*Queue) Push

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

Push satisfies the heap interface, do not use directly.

NOTE: This method simply appends to the Q and does not min-heapify or sort the elements. Use Add(x Queueable) or container/heap instead e.g. heap.Push(q, x interface{}). Additionally this method panics if your Q element does not satisfy the Queueable interface.

func (*Queue) Remove

func (q *Queue) Remove() interface{}

Remove the highest priority item from the Q

func (*Queue) Swap

func (q *Queue) Swap(i, j int)

Swap satisfies the sort interface

type Queueable

type Queueable interface {
	Priority() int
}

Queueable describes the interface objects must satisfy to be placed in the Q

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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