priorityqueue

package
v1.8.6 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorEmptyQueue     = errors.New("empty queue")
	ErrorItemNotFound   = errors.New("item not found")
	ErrorItemDuplicated = errors.New("item duplicated")
)

Functions

This section is empty.

Types

type PriorityQueue

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

PriorityQueue represents the queue

func New

func New() PriorityQueue

New initializes an empty priority queue.

func (*PriorityQueue) Insert

func (p *PriorityQueue) Insert(v interface{}, priority int64) error

Insert inserts a new element into the queue. No action is performed on duplicate elements.

func (*PriorityQueue) Len

func (p *PriorityQueue) Len() int

Len returns the number of elements in the queue.

func (*PriorityQueue) Pop

func (p *PriorityQueue) Pop() (interface{}, error)

Pop removes the element with the highest priority from the queue and returns it. In case of an empty queue, an error is returned.

func (*PriorityQueue) Remove

func (p *PriorityQueue) Remove(x interface{})

Remove removes element

func (*PriorityQueue) Top

func (p *PriorityQueue) Top() (interface{}, error)

Top returns the element with the highest priority from the queue.

func (*PriorityQueue) UpdatePriority

func (p *PriorityQueue) UpdatePriority(x interface{}, newPriority int64) error

UpdatePriority changes the priority of a given item. If the specified item is not present in the queue, no action is performed.

Jump to

Keyboard shortcuts

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