https://github.com/anjulapaulus/tinyqueue
A simple and smallest binary heap priority queue in golang
https://github.com/anjulapaulus/tinyqueue
algorithm binary-heap datastructure go golang priority-queue
Last synced: 13 days ago
JSON representation
A simple and smallest binary heap priority queue in golang
- Host: GitHub
- URL: https://github.com/anjulapaulus/tinyqueue
- Owner: anjulapaulus
- Created: 2020-04-10T17:53:23.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-17T19:16:46.000Z (almost 6 years ago)
- Last Synced: 2024-06-20T03:38:33.775Z (over 1 year ago)
- Topics: algorithm, binary-heap, datastructure, go, golang, priority-queue
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.com/anjulapaulus/tinyqueue)
[](https://codecov.io/gh/anjulapaulus/config)
[](http://hits.dwyl.com/anjulapaulus/tinyqueue)
# tinyqueue
A simple and smallest binary heap priority queue in golang.
#### Installation
````
go get -u github.com/anjulapaulus/tinyqueue
````
#### Acknowledgement
The current implementation is inspired on the javascript library [tinyqueue](https://github.com/mourner/tinyqueue) by Vladimir Agafonkin.
#### Implementation
````
package main
import queue "github.com/anjulapaulus/tinyqueue"
type Val int64
func (a Val) Compare (b queue.Item) bool{
return a <= b.(Val)
}
func main(){
q:= queue.Queue{} //Initialize Queue
q.Push(Val(2)) //Insert Items to queue
q.Push(Val(5))
q.Push(Val(10))
array := q.All() //returns array of elemeents in queue
q.Peek() //returns the top item without removal
q.Len() //length of queue
q.Pop() //removes the top item and displays
}