forked from nu7hatch/gopqueue
Simple priority queue in Go with unique feature
License
mileusna/gopqueue
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
Priority Queue in Go ==================== This package provides a priority queue implementation and scaffold interfaces. Additional to original package, you can enqueue only items which haven't been already enqueued Installation ------------ $ go get github.com/mileusna/gopqueue Usage ----- Here's trivial example of the fast queue usage: Hope to post more examples soon package main import pqueue "github.com/mileusna/gopqueue" type Task struct { Name string priority int } // interface functions for queue items func (t *Task) Less(other interface{}) bool { return t.priority < other.(*Task).priority } // this should return unique id from struct // to check weather item has already been into queue func (t *Task) Id() interface{} { return t.Name } func main() { q := pqueue.New(0) q.EnqueueUnique(&Task{"one", 10}) q.EnqueueUnique(&Task{"two", 2}) q.EnqueueUnique(&Task{"three", 5}) q.EnqueueUnique(&Task{"four", 7}) q.EnqueueUnique(&Task{"two", 5}) q.EnqueueUnique(&Task{"two", 6}) q.EnqueueUnique(&Task{"two", 7}) q.EnqueueUnique(&Task{"two", 8}) println(q.Len()) // there will be only 4 items in queue for i := 0; i < 4; i += 1 { task := q.Dequeue() println(task.(*Task).Name) } } // Produces: // 4 // two // three // four // one For more information and examples check the package documentation. Copyright --------- Copyright (C) 2015 by Milos Mileusnic <milos@groowe.com> Copyright (C) 2011 by Krzysztof Kowalik <chris@nu7hat.ch> See COPYING file for details.
About
Simple priority queue in Go with unique feature
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- Go 98.4%
- Makefile 1.6%