# README
Go 堆排序
Install
go get github.com/golang-infrastructure/go-heap
Example
package main
import (
"fmt"
"github.com/golang-infrastructure/go-heap"
"math/rand"
)
func main() {
options := &heap.Options[int]{
Comparator: heap.IntComparator(),
// 支持N叉堆,默认是2叉堆
Ary: 4,
}
// 非线程安全的堆,仅限于单个goroutine里使用
//heap :=heap.New(heap.IntComparator())
heap := heap.NewWithOptions(options)
// 创建线程安全的堆
//heap :=heap.NewSync(heap.IntComparator())
//heap := heap.NewSyncWithOptions(options)
for i := 0; i < 10; i++ {
n := rand.Int() % 100
heap.Push(n)
}
heapNumSlice := heap.PopToSlice()
fmt.Println(heapNumSlice) // [10 16 20 21 37 48 49 51 51 58]
}
# Packages
No description provided by the author
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
DefaultAryHeap 默认是2叉堆.
# Variables
ErrHeapIsEmpty 堆是空的时候不能进行某些操作,会返回此错误.
# Interfaces
Interface 用于定义堆提供的API.
# Type aliases
Comparator 用于比较堆中元素的大小.