container

package
v0.0.0-...-8a7fe10 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

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

func NewEmptyHeap[T any](less func(x, y T) bool) *Heap[T]

NewEmptyHeap

根据 less 返回最小堆/最大堆

当 x < y 时, 如果 less(x, y) = true, 返回最小堆; 如果 less(x, y) = false, 返回最大堆

func NewHeap

func NewHeap[T any](data []T, less func(x, y T) bool) *Heap[T]

NewHeap

根据 data 和 less 初始化堆

当 x < y 时, 如果 less(x, y) = true, 返回最小堆; 如果 less(x, y) = false, 返回最大堆

func NewMaxIntHeap

func NewMaxIntHeap(data ...int) *Heap[int]

NewMaxIntHeap return a max-heap of ints.

func NewMinIntHeap

func NewMinIntHeap(data ...int) *Heap[int]

NewMinIntHeap return a min-heap of ints.

func (*Heap[T]) Empty

func (h *Heap[T]) Empty() bool

func (*Heap[T]) Len

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

func (*Heap[T]) Less

func (h *Heap[T]) Less(i, j int) bool

func (*Heap[T]) Peek

func (h *Heap[T]) Peek() T

Peek 仅返回堆的根节点的值,不作删除 非空的堆才可以调用,空堆调用会触发 panic(slices out of size)

func (*Heap[T]) Pop

func (h *Heap[T]) Pop() T

Pop 出队操作,弹出并返回 Heap 的根,等价于 Remove(0)

func (*Heap[T]) Push

func (h *Heap[T]) Push(value T)

Push 入队操作,将 value 插入 Heap 中

func (*Heap[T]) Remove

func (h *Heap[T]) Remove(i int) T

Remove 删除操作,从 Heap 中移除指定节点,并返回

func (*Heap[T]) Swap

func (h *Heap[T]) Swap(i, j int)

func (*Heap[T]) Update

func (h *Heap[T]) Update(i int, value T)

Update 更新操作,将 Heap 中的节点修改为给定的 value

func (*Heap[T]) Values

func (h *Heap[T]) Values() []T

Values 返回堆的值的拷贝

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T comparable](data ...T) *Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(values ...T)

func (*Set[T]) Clear

func (s *Set[T]) Clear()

func (Set[T]) Clone

func (s Set[T]) Clone() *Set[T]

func (*Set[T]) Contain

func (s *Set[T]) Contain(x T) bool

func (Set[T]) Empty

func (s Set[T]) Empty() bool

func (*Set[T]) Remove

func (s *Set[T]) Remove(values ...T)

func (Set[T]) Size

func (s Set[T]) Size() int

func (Set[T]) Values

func (s Set[T]) Values() (values []T)

Directories

Path Synopsis
tree

Jump to

Keyboard shortcuts

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