https://github.com/sysread/skewer
A priority queue for Go implemented using a skew heap
https://github.com/sysread/skewer
binary data go heap min minqueue priority queue skew structure
Last synced: 5 months ago
JSON representation
A priority queue for Go implemented using a skew heap
- Host: GitHub
- URL: https://github.com/sysread/skewer
- Owner: sysread
- License: other
- Created: 2018-07-30T19:52:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-11-19T15:42:01.000Z (about 5 years ago)
- Last Synced: 2025-08-23T12:28:22.267Z (5 months ago)
- Topics: binary, data, go, heap, min, minqueue, priority, queue, skew, structure
- Language: Go
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# skewer
[](http://pkg.go.dev/github.com/sysread/skewer)
Package skewer - a mergable priority queue
Skew heaps implement a priority queue (min heap) using a binary heap which
is continually rebalanced with each Put and Take operation. Skew heaps have
an ammortized performance slighter better than O(log n).
The key feature of a skew heap is that it may be quickly and trivially
merged with another skew heap. All heap operations are defined in terms of
the merge operation.
Mutable operations on the skew heap are atomic.
For more details, see [https://en.wikipedia.org/wiki/Skew_heap](https://en.wikipedia.org/wiki/Skew_heap)
## Examples
```golang
package main
import (
"fmt"
"github.com/sysread/skewer"
)
// Define a type that implements SkewItem. A SkewItem need only provide a
// single method, 'Priority', which returns the relative priority for an item
// in the queue. This value becomes the sorting mechanism for items in the
// heap. A lower value indicates a higher priority.
type Item int
func (item Item) Priority() int {
// Negate the item's value so that a higher number will be given a higher
// priority.
return 0 - int(item)
}
func main() {
heap := skewer.New()
fmt.Println(heap.Top())
for i := 0; i < 5; i++ {
heap.Put(Item(i))
}
for i := 0; i < 5; i++ {
fmt.Println(heap.Take())
}
}
```
---
Readme created from Go doc with [goreadme](https://github.com/posener/goreadme)