priorityqueue

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDisposed is returned when an operation is performed on a disposed
	// queue.
	ErrDisposed = errors.New(`queue: disposed`)

	// ErrTimeout is returned when an applicable queue operation times out.
	ErrTimeout = errors.New(`queue: poll timed out`)

	// ErrEmptyQueue is returned when an non-applicable queue operation was called
	// due to the queue's empty item state
	ErrEmptyQueue = errors.New(`queue: empty queue`)
)

Functions

This section is empty.

Types

type Item

type Item interface {
	// Compare returns a bool that can be used to determine
	// ordering in the priority queue.  Assuming the queue
	// is in ascending order, this should return > logic.
	// Return 1 to indicate this object is greater than the
	// the other logic, 0 to indicate equality, and -1 to indicate
	// less than other.
	Compare(other Item) int
}

Item is an item that can be added to the priority queue.

type PriorityQueue

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

PriorityQueue is similar to queue except that it takes items that implement the Item interface and adds them to the queue in priority order.

func NewPriorityQueue

func NewPriorityQueue(hint int, allowDuplicates bool) *PriorityQueue

NewPriorityQueue is the constructor for a priority queue.

func (*PriorityQueue) Dispose

func (pq *PriorityQueue) Dispose()

Dispose will prevent any further reads/writes to this queue and frees available resources.

func (*PriorityQueue) Disposed

func (pq *PriorityQueue) Disposed() bool

Disposed returns a bool indicating if this queue has been disposed.

func (*PriorityQueue) Empty

func (pq *PriorityQueue) Empty() bool

Empty returns a bool indicating if there are any items left in the queue.

func (*PriorityQueue) Get

func (pq *PriorityQueue) Get(number int) ([]Item, error)

Get retrieves items from the queue. If the queue is empty, this call blocks until the next item is added to the queue. This will attempt to retrieve number of items.

func (*PriorityQueue) Len

func (pq *PriorityQueue) Len() int

Len returns a number indicating how many items are in the queue.

func (*PriorityQueue) Peek

func (pq *PriorityQueue) Peek() Item

Peek will look at the next item without removing it from the queue.

func (*PriorityQueue) Put

func (pq *PriorityQueue) Put(items ...Item) error

Put adds items to the queue.

Jump to

Keyboard shortcuts

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