Documentation ¶
Index ¶
- type HeapPriorityQueue
- func (pq *HeapPriorityQueue[T, P]) BatchPut(items ...*Item[T, P])
- func (pq *HeapPriorityQueue[T, P]) Clear()
- func (pq *HeapPriorityQueue[T, P]) Get() *Item[T, P]
- func (pq *HeapPriorityQueue[T, P]) GetAndPop() *Item[T, P]
- func (pq *HeapPriorityQueue[T, P]) IsEmpty() bool
- func (pq *HeapPriorityQueue[T, P]) Len() int
- func (pq *HeapPriorityQueue[T, P]) Less(i, j int) bool
- func (pq *HeapPriorityQueue[T, P]) Pop() any
- func (pq *HeapPriorityQueue[T, P]) Push(x any)
- func (pq *HeapPriorityQueue[T, P]) Put(value T, priority P)
- func (pq *HeapPriorityQueue[T, P]) Swap(i, j int)
- func (pq *HeapPriorityQueue[T, P]) Update(value T, priority P)
- func (pq *HeapPriorityQueue[T, P]) Upsert(value T, priority P)
- type HeapType
- type Item
- type PriorityQueue
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]) BatchPut ¶
func (pq *HeapPriorityQueue[T, P]) BatchPut(items ...*Item[T, P])
BatchPut 批量将元素添加到优先级队列中
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 更新元素的优先级
func (*HeapPriorityQueue[T, P]) Upsert ¶ added in v0.1.2
func (pq *HeapPriorityQueue[T, P]) Upsert(value T, priority P)
Upsert 插入新元素或更新已有元素的优先级
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) BatchPut(items ...*Item[T, P]) Get() *Item[T, P] GetAndPop() *Item[T, P] IsEmpty() bool Update(value T, priority P) Upsert(value T, priority P) Clear() }
func New ¶
func New[T comparable, P constraints.Ordered](kind HeapType) PriorityQueue[T, P]
New 创建一个新的优先级队列
Click to show internal directories.
Click to hide internal directories.