forked from bjarneh/binheap
golang binary heap with a simple interface
License
newblue/binheap
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
[ What ] A small binary-heap for golang with a simple interface <code> type Heapable struct { Priority() int } if a.Priority() < b.Priority() { fmt.Println(" a is more urgent than b") } </code> [ Install ] goinstall github.com/bjarneh/binheap [ Example ] <code> type Job struct { priority int // probably more stuff.. } func (j *Job) Priority() int { return j.priority } heap := binheap.New() heap.Add(&Job{4}) heap.Add(&Job{1}) heap.Add(&Job{10}) . . mostUrgent := heap.Remove() // Job{1} // a slice of Heapable elements can be added as well var jobs []Heapable = make([]Heapable, 0) jobs = append(jobs, &Job{8}) jobs = append(jobs, &Job{19}) . . heap.AddSlice(jobs) // heap-sort, slower than sort.Sort (quick-sort) binheap.Sort(jobs) // any []Heapable slice will do </code>
About
golang binary heap with a simple interface
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published