v1_mutex

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeapPriorityQueue

type HeapPriorityQueue[T comparable, P constraints.Ordered] struct {
	// contains filtered or unexported fields
}

HeapPriorityQueue 基于容器/堆的优先级队列实现

func (*HeapPriorityQueue[T, P]) Clear

func (pq *HeapPriorityQueue[T, P]) Clear()

Clear 清空优先级队列

func (*HeapPriorityQueue[T, P]) Get

func (pq *HeapPriorityQueue[T, P]) Get() *Item[T, P]

Get 返回优先级队列中的下一个元素而不移除它

func (*HeapPriorityQueue[T, P]) GetAndPop

func (pq *HeapPriorityQueue[T, P]) GetAndPop() *Item[T, P]

GetAndPop 移除并返回优先级队列中的下一个元素

func (*HeapPriorityQueue[T, P]) IsEmpty

func (pq *HeapPriorityQueue[T, P]) IsEmpty() bool

IsEmpty 检查优先级队列是否为空

func (*HeapPriorityQueue[T, P]) Len

func (pq *HeapPriorityQueue[T, P]) Len() int

Len implements heap.Interface

func (*HeapPriorityQueue[T, P]) Less

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

Less implements heap.Interface

func (*HeapPriorityQueue[T, P]) Pop

func (pq *HeapPriorityQueue[T, P]) Pop() any

Pop implements heap.Interface 弹出最后一个元素

func (*HeapPriorityQueue[T, P]) Push

func (pq *HeapPriorityQueue[T, P]) Push(x any)

Push implements heap.Interface

func (*HeapPriorityQueue[T, P]) Put

func (pq *HeapPriorityQueue[T, P]) Put(value T, priority P)

Put 将元素添加到优先级队列中

func (*HeapPriorityQueue[T, P]) Swap

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

Swap implements heap.Interface

func (*HeapPriorityQueue[T, P]) Update

func (pq *HeapPriorityQueue[T, P]) Update(value T, priority P)

Update 更新元素的优先级

type HeapType

type HeapType int

HeapType 指定堆类型 - 最小或最大

const (
	MinHeap HeapType = iota // 小顶堆
	MaxHeap                 // 大顶堆
)

type Item

type Item[T any, P constraints.Ordered] struct {
	Value    T // 元素值
	Priority P // 元素优先级
}

Item 代表优先级队列中的一个元素

type PriorityQueue

type PriorityQueue[T any, P constraints.Ordered] interface {
	Len() int
	Put(value T, priority P)
	Get() *Item[T, P]
	GetAndPop() *Item[T, P]
	IsEmpty() bool
	Update(value T, priority P)
	Clear()
}

func New

func New[T comparable, P constraints.Ordered](kind HeapType) PriorityQueue[T, P]

New 创建一个新的优先级队列

Jump to

Keyboard shortcuts

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