priorityqueue

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PriorityQueue

type PriorityQueue[T any] struct {
	// contains filtered or unexported fields
}

func NewPriorityQueue

func NewPriorityQueue[T constraints.Ordered](t PriorityType) *PriorityQueue[T]

NewPriorityQueue returns a new PriorityQueue.

t is the type of priority queue : greater or lower

func NewPriorityQueueWithCompare

func NewPriorityQueueWithCompare[T any](f compareFunc[T]) *PriorityQueue[T]

NewPriorityQueueWithCompare returns a new PriorityQueue.

f is Custom comparison function

compareFunc[T] func(src, des T) bool

when src has a higher priority than des, returns true

func (*PriorityQueue[T]) IsEmpty

func (q *PriorityQueue[T]) IsEmpty() bool

IsEmpty returns true if the stack is empty.

func (*PriorityQueue[T]) Pop

func (q *PriorityQueue[T]) Pop() (T, bool)

Pop removes the element with the highest priority from the priority queue and returns it. If the priority queue is empty, Pop returns the zero value of the type T and false.

func (*PriorityQueue[T]) Push

func (q *PriorityQueue[T]) Push(e T)

Push adds an element to the priority queue.

func (*PriorityQueue[T]) Size

func (q *PriorityQueue[T]) Size() int

Size returns the number of items in the stack.

func (*PriorityQueue[T]) Top

func (q *PriorityQueue[T]) Top() (T, bool)

Top returns the element with the highest priority from the priority queue without removing it. If the priority queue is empty, Top returns the zero value of the type T and false.

type PriorityType

type PriorityType int
const (
	PriorityTypeGreater PriorityType
	PriorityTypeLower
)

Jump to

Keyboard shortcuts

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