Documentation ¶
Index ¶
- type Heap
- func (h *Heap[T]) Empty() bool
- func (h *Heap[T]) Len() int
- func (h *Heap[T]) Less(i, j int) bool
- func (h *Heap[T]) Peek() T
- func (h *Heap[T]) Pop() T
- func (h *Heap[T]) Push(value T)
- func (h *Heap[T]) Remove(i int) T
- func (h *Heap[T]) Swap(i, j int)
- func (h *Heap[T]) Update(i int, value T)
- func (h *Heap[T]) Values() []T
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Heap ¶
type Heap[T any] struct { // contains filtered or unexported fields }
Heap implement generic heap
func NewEmptyHeap ¶
NewEmptyHeap
根据 less 返回最小堆/最大堆
当 x < y 时, 如果 less(x, y) = true, 返回最小堆; 如果 less(x, y) = false, 返回最大堆
func NewHeap ¶
NewHeap
根据 data 和 less 初始化堆
当 x < y 时, 如果 less(x, y) = true, 返回最小堆; 如果 less(x, y) = false, 返回最大堆
func NewMaxIntHeap ¶
NewMaxIntHeap return a max-heap of ints.
func NewMinIntHeap ¶
NewMinIntHeap return a min-heap of ints.
func (*Heap[T]) Peek ¶
func (h *Heap[T]) Peek() T
Peek 仅返回堆的根节点的值,不作删除 非空的堆才可以调用,空堆调用会触发 panic(slices out of size)
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
func NewSet ¶
func NewSet[T comparable](data ...T) *Set[T]
Click to show internal directories.
Click to hide internal directories.