Documentation
¶
Index ¶
- Constants
- Variables
- type Comparator
- type Heap
- func (x *Heap[T]) Clear()
- func (x *Heap[T]) ExportDotLanguage() string
- func (x *Heap[T]) IsEmpty() bool
- func (x *Heap[T]) IsNotEmpty() bool
- func (x *Heap[T]) Peek() T
- func (x *Heap[T]) PeekE() (T, error)
- func (x *Heap[T]) Pop() T
- func (x *Heap[T]) PopE() (T, error)
- func (x *Heap[T]) PopEach(eachFunc func(v T) bool)
- func (x *Heap[T]) PopToSlice() []T
- func (x *Heap[T]) PopTopN(n int) []T
- func (x *Heap[T]) Push(valueSlice ...T)
- func (x *Heap[T]) Size() int
- type Interface
- type Options
- type SyncHeap
- func (x *SyncHeap[T]) Clear()
- func (x *SyncHeap[T]) IsEmpty() bool
- func (x *SyncHeap[T]) IsNotEmpty() bool
- func (x *SyncHeap[T]) Peek() T
- func (x *SyncHeap[T]) PeekE() (T, error)
- func (x *SyncHeap[T]) Pop() T
- func (x *SyncHeap[T]) PopE() (T, error)
- func (x *SyncHeap[T]) PopEach(eachFunc func(v T) bool)
- func (x *SyncHeap[T]) PopTopN(n int) []T
- func (x *SyncHeap[T]) Push(valueSlice ...T)
- func (x *SyncHeap[T]) Size() int
Constants ¶
View Source
const DefaultAryHeap = 2
DefaultAryHeap 默认是2叉堆
Variables ¶
View Source
var ( // ErrHeapIsEmpty 堆是空的时候不能进行某些操作,会返回此错误 ErrHeapIsEmpty = errors.New("heap is empty") )
Functions ¶
This section is empty.
Types ¶
type Comparator ¶
Comparator 用于比较堆中元素的大小
func Float32Comparator ¶
func Float32Comparator() Comparator[float32]
func Float64Comparator ¶
func Float64Comparator() Comparator[float64]
func IntComparator ¶
func IntComparator() Comparator[int]
func StringComparator ¶
func StringComparator() Comparator[string]
func UintComparator ¶
func UintComparator() Comparator[uint]
type Heap ¶
type Heap[T any] struct { // contains filtered or unexported fields }
func New ¶
func New[T any](comparator Comparator[T]) *Heap[T]
func NewWithOptions ¶
func (*Heap[T]) ExportDotLanguage ¶
ExportDotLanguage 导出为dot language,拿出去画图以便可视化
func (*Heap[T]) PopToSlice ¶
func (x *Heap[T]) PopToSlice() []T
type Interface ¶
type Interface[T any] interface { Clear() Push(v ...T) PeekE() (T, error) Peek() T PopE() (T, error) Pop() T Size() int IsEmpty() bool IsNotEmpty() bool PopTopN(n int) []T PopEach(eachFunc func(v T) bool) }
Interface 用于定义堆提供的API
type Options ¶
type Options[T any] struct { // 必选项,比较器,用来决定堆中数据之前的相对大小 Comparator Comparator[T] // 可选项,堆是几叉堆,默认是二叉堆 Ary int // 可选项,可以从指定的数组初始化堆,不指定的话默认为空堆 InitSlice []T }
Options 堆排序的选项
type SyncHeap ¶
type SyncHeap[T any] struct { // contains filtered or unexported fields }
SyncHeap 线程安全的堆
func NewSync ¶
func NewSync[T any](comparator Comparator[T]) *SyncHeap[T]
func NewSyncWithOptions ¶
func (*SyncHeap[T]) IsNotEmpty ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.