priorityqueue

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package priorityqueue describe an prioriry queue implement.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMismatchQueue represent the element's queue mismatch current operation queue
	ErrMismatchQueue = xerrors.Errorf("MismatchQueue")

	// ErrOutOfIndex represent the element's index out of queue's length
	ErrOutOfIndex = xerrors.Errorf("OutOfIndex")

	// ErrMismatchPriority represent the element's priority mismatch
	ErrMismatchPriority = xerrors.Errorf("MismatchPriority")
)

Functions

This section is empty.

Types

type Element

type Element[T any] struct {
	// Value for element
	Value T
	// contains filtered or unexported fields
}

Element for priority queue element

func (*Element[T]) Index

func (e *Element[T]) Index() int

Index return the element index in slice

func (*Element[T]) Priority

func (e *Element[T]) Priority() int64

Priority return the priority value of element

func (*Element[T]) String

func (e *Element[T]) String() string

String return the representation of element

type PriorityQueue

type PriorityQueue[T any] interface {
	// Add element to the PriorityQueue, it will return the element witch been added
	Add(v T, priority int64) *Element[T]

	// Peek return the lowest priority element
	Peek() *Element[T]

	// Pop return the lowest priority element and remove it
	Pop() *Element[T]

	// Remove will remove the element from the priority queue
	Remove(v *Element[T]) error

	// Update the element in the priority queue with the new priority
	Update(v *Element[T], priority int64) error

	// Size return the element size of queue
	Size() int
}

PriorityQueue for priority queue trait

func NewPriorityQueue

func NewPriorityQueue[T any](size int) PriorityQueue[T]

NewPriorityQueue construct a PriorityQueue

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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