priorityq

package
v0.2.19-beta.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// High indicates the highest priority.
	High = Priority(0)

	// Mid indicates the medium priority.
	Mid = Priority(1)

	// Low indicates the lowest priority.
	Low = Priority(2)
)

Variables

View Source
var (
	// ErrEmptyQueue is returned on attempt to read from an empty queue.
	ErrEmptyQueue = errors.New("attempt to read from an empty queue")
	// ErrClosed is returned when a queue is closed.
	ErrClosed = errors.New("queue is closed")
)

Functions

This section is empty.

Types

type HeapQueue

type HeapQueue struct {
	util.Closer
	// contains filtered or unexported fields
}

A HeapQueue implements priority.Interface using container/heap and holds Items.

func (*HeapQueue) Close

func (pq *HeapQueue) Close()

Close closes priority queue.

func (*HeapQueue) Len

func (pq *HeapQueue) Len() int

Len implements heap.Interface.

func (*HeapQueue) Length

func (pq *HeapQueue) Length() int

Length returns priority queue length. It's just a wrapper for Len now.

func (*HeapQueue) Less

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

Less implements heap.Interface.

func (*HeapQueue) Pop

func (pq *HeapQueue) Pop() any

Pop implements heap.Interface.

func (*HeapQueue) Push

func (pq *HeapQueue) Push(x any)

Push implements heap.Interface.

func (*HeapQueue) Read

func (pq *HeapQueue) Read() (any, error)

Read reads a value from the priority queue. It's a wrapper for Pop.

func (*HeapQueue) Swap

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

Swap implements heap.Interface.

func (*HeapQueue) Write

func (pq *HeapQueue) Write(priority Priority, value any) error

Write pushes a value in the priority queue. It's a wrapper for Push.

type HeapQueueItem

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

An HeapQueueItem is something we manage in a priority queue.

type Priority

type Priority int

Priority is the type that indicates the priority of different queues.

type PriorityQueue added in v0.1.31

type PriorityQueue interface {
	Write(priority Priority, value any) error
	Read() (any, error)
	Close()
	Length() int
}

PriorityQueue is the interface used to interact with the queue.

func New

func New() PriorityQueue

New creates a new priority queue based on HeapQueue.

Jump to

Keyboard shortcuts

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