priorityqueue

package
v0.0.0-...-2e88929 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOutOfCapacity = errors.New("队列已满")
	ErrEmptyQueue    = errors.New("队列为空")
)

Functions

This section is empty.

Types

type PriorityQueue

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

func NewPriorityQueue

func NewPriorityQueue[T any](capacity int, less func(a, b T) bool) *PriorityQueue[T]

func (*PriorityQueue[T]) Dequeue

func (pq *PriorityQueue[T]) Dequeue() (T, error)

Dequeue 移除并返回最小元素

func (*PriorityQueue[T]) Enqueue

func (pq *PriorityQueue[T]) Enqueue(item T) error

Enqueue 添加一个元素

func (*PriorityQueue[T]) Len

func (pq *PriorityQueue[T]) Len() int

Len 返回队列的长度

func (*PriorityQueue[T]) Less

func (pq *PriorityQueue[T]) Less(i, j int) bool

Less 比较两个元素的大小

func (*PriorityQueue[T]) Pop

func (pq *PriorityQueue[T]) Pop() interface{}

Pop 移除并返回最小元素

func (*PriorityQueue[T]) Push

func (pq *PriorityQueue[T]) Push(x interface{})

Push 添加一个元素

func (*PriorityQueue[T]) Swap

func (pq *PriorityQueue[T]) Swap(i, j int)

Swap 交换两个元素

Jump to

Keyboard shortcuts

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