heap

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Binary = 2

	Quadratic = 4

	Octal = 8
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Element added in v1.1.3

type Element[K cmp.Ordered, V any] struct {
	Value V
	// contains filtered or unexported fields
}

func (*Element[K, V]) Index added in v1.1.3

func (c *Element[K, V]) Index() int

Index 获取索引 index==-1 表示元素已被删除, 不允许做更新或删除操作

func (*Element[K, V]) Key added in v1.1.3

func (c *Element[K, V]) Key() K

Key 获取排序Key

type Heap

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

func New

func New[T cmp.Ordered]() *Heap[T]

New 新建一个最小四叉堆 Create a new minimum quadratic heap

func NewWithWays added in v1.1.3

func NewWithWays[T any](ways uint32, lessFunc cmp.LessFunc[T]) *Heap[T]

NewWithWays 新建堆 @ways 分叉数, ways=pow(2,n) @lessFunc 比较函数

func (*Heap[T]) Clone added in v1.1.1

func (c *Heap[T]) Clone() *Heap[T]

func (*Heap[T]) Len

func (c *Heap[T]) Len() int

Len 获取元素数量

func (*Heap[T]) Pop

func (c *Heap[T]) Pop() (ele T)

Pop 弹出堆顶元素

func (*Heap[T]) Push

func (c *Heap[T]) Push(v T)

Push 追加元素

func (*Heap[T]) Range added in v1.1.0

func (c *Heap[T]) Range(f func(index int, value T) bool)

Range 遍历

func (*Heap[T]) Reset added in v1.1.0

func (c *Heap[T]) Reset()

Reset 重置堆

func (*Heap[T]) SetCap added in v1.1.0

func (c *Heap[T]) SetCap(n int) *Heap[T]

SetCap 设置预分配容量

func (*Heap[T]) Top added in v1.1.0

func (c *Heap[T]) Top() T

Top 获取堆顶元素

func (*Heap[T]) UnWrap added in v1.1.2

func (c *Heap[T]) UnWrap() []T

UnWrap 解包, 返回底层数组

type IndexedHeap added in v1.1.3

type IndexedHeap[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

func NewIndexedHeap added in v1.1.3

func NewIndexedHeap[K cmp.Ordered, V any](ways uint32, lessFunc cmp.LessFunc[K]) *IndexedHeap[K, V]

NewIndexedHeap 新建索引堆 @ways 分叉数, ways=pow(2,n) @lessFunc 比较函数, 可以传空指针, 默认为最小堆

func (*IndexedHeap[K, V]) Clone added in v1.1.3

func (c *IndexedHeap[K, V]) Clone() *IndexedHeap[K, V]

Clone 拷贝索引堆副本

func (*IndexedHeap[K, V]) DeleteByIndex added in v1.1.3

func (c *IndexedHeap[K, V]) DeleteByIndex(index int)

DeleteByIndex 通过索引删除元素

func (*IndexedHeap[K, V]) GetByIndex added in v1.1.3

func (c *IndexedHeap[K, V]) GetByIndex(index int) *Element[K, V]

GetByIndex 通过索引获取元素

func (*IndexedHeap[K, V]) Len added in v1.1.3

func (c *IndexedHeap[K, V]) Len() int

Len 获取元素数量

func (*IndexedHeap[K, V]) Pop added in v1.1.3

func (c *IndexedHeap[K, V]) Pop() (ele *Element[K, V])

Pop 弹出堆顶元素

func (*IndexedHeap[K, V]) Push added in v1.1.3

func (c *IndexedHeap[K, V]) Push(key K, value V) *Element[K, V]

Push 追加元素

func (*IndexedHeap[K, V]) Range added in v1.1.3

func (c *IndexedHeap[K, V]) Range(f func(ele *Element[K, V]) bool)

Range 遍历

func (*IndexedHeap[K, V]) Reset added in v1.1.3

func (c *IndexedHeap[K, V]) Reset()

Reset 重置堆

func (*IndexedHeap[K, V]) SetCap added in v1.1.3

func (c *IndexedHeap[K, V]) SetCap(n int) *IndexedHeap[K, V]

SetCap 设置预分配容量

func (*IndexedHeap[K, V]) Top added in v1.1.3

func (c *IndexedHeap[K, V]) Top() *Element[K, V]

Top 获取堆顶元素

func (*IndexedHeap[K, V]) UpdateKeyByIndex added in v1.1.3

func (c *IndexedHeap[K, V]) UpdateKeyByIndex(index int, key K)

UpdateKeyByIndex 通过索引更新排序Key

Jump to

Keyboard shortcuts

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