Documentation
¶
Overview ¶
This package provides a priority queue implementation and scaffold interfaces.
Addition to original package, this package adds method and other internals for inserting only unique items in queue
Copyright (C) 2015 by Milos Mileusnic <milos@groowe.com>
Copyright (C) 2011 by Krzysztof Kowalik <chris@nu7hat.ch>
Index ¶
- type Queue
- func (q *Queue) ChangeLimit(newLimit int)
- func (q *Queue) ClearHistory()
- func (q *Queue) Dequeue() (item QueueItem)
- func (q *Queue) Enqueue(item QueueItem) (err error)
- func (q *Queue) EnqueueUnique(item QueueItem) (added bool, err error)
- func (q *Queue) IdExists(id interface{}) bool
- func (q *Queue) IsEmpty() bool
- func (q *Queue) ItemExists(item QueueItem) bool
- func (q *Queue) Len() int
- func (q *Queue) RemoveFromHistory(element interface{})
- type QueueItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue struct { Limit int // contains filtered or unexported fields }
Queue is a threadsafe priority queue exchange. Here's a trivial example of usage:
q := pqueue.New(0) go func() { for { task := q.Dequeue() println(task.(*CustomTask).Name) } }() for i := 0; i < 100; i := 1 { task := CustomTask{Name: "foo", priority: rand.Intn(10)} q.Enqueue(&task) }
func New ¶
New creates and initializes a new priority queue, taking a limit as a parameter. If 0 given, then queue will be unlimited.
func (*Queue) ChangeLimit ¶
Safely changes enqueued items limit. When limit is set to 0, then queue is unlimited.
func (*Queue) ClearHistory ¶
func (q *Queue) ClearHistory()
Clear queue history so the elements can be EnqueueUnique again
func (*Queue) Dequeue ¶
Dequeue takes an item from the queue. If queue is empty then should block waiting for at least one item.
func (*Queue) EnqueueUnique ¶
Enqueue puts item in queue only if it hasn't already been in queue
func (*Queue) ItemExists ¶
check if item already exists in queue (or it has been into queue)
func (*Queue) RemoveFromHistory ¶
func (q *Queue) RemoveFromHistory(element interface{})