Documentation
¶
Overview ¶
The priority queue is almost a spitting image of the logic used for a regular queue. In order to keep the logic fast, this code is repeated instead of using casts to cast to interface{} back and forth. If Go had inheritance and generics, this problem would be easier to solve.
Index ¶
- func ExecuteInParallel(q *Queue, fn func(interface{}))
- type DisposedError
- type Item
- type PriorityQueue
- type Queue
- func (q *Queue) Dispose()
- func (q *Queue) Disposed() bool
- func (q *Queue) Empty() bool
- func (q *Queue) Get(number int64) ([]interface{}, error)
- func (q *Queue) Len() int64
- func (q *Queue) Put(items ...interface{}) error
- func (q *Queue) TakeUntil(checker func(item interface{}) bool) ([]interface{}, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecuteInParallel ¶
func ExecuteInParallel(q *Queue, fn func(interface{}))
ExecuteInParallel will (in parallel) call the provided function with each item in the queue until the queue is exhausted. When the queue is exhausted execution is complete and all goroutines will be killed. This means that the queue will be disposed so cannot be used again.
Types ¶
type DisposedError ¶
type DisposedError struct{}
func (DisposedError) Error ¶
func (de DisposedError) Error() string
type Item ¶
type Item interface {
// Compare returns a bool that can be used to determine
// ordering in the priority queue. Assuming the queue
// is in ascending order, this should return > logic.
// Return 1 to indicate this object is greater than the
// the other logic, 0 to indicate equality, and -1 to indicate
// less than other.
Compare(other Item) int
}
Item is an item that can be added to the priority queue.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue is similar to queue except that it takes items that implement the Item interface and adds them to the queue in priority order.
func NewPriorityQueue ¶
func NewPriorityQueue(hint int) *PriorityQueue
NewPriorityQueue is the constructor for a priority queue.
func (*PriorityQueue) Dispose ¶
func (pq *PriorityQueue) Dispose()
Dispose will prevent any further reads/writes to this queue and frees available resources.
func (*PriorityQueue) Disposed ¶
func (pq *PriorityQueue) Disposed() bool
Disposed returns a bool indicating if this queue has been disposed.
func (*PriorityQueue) Empty ¶
func (pq *PriorityQueue) Empty() bool
Empty returns a bool indicating if there are any items left in the queue.
func (*PriorityQueue) Get ¶
func (pq *PriorityQueue) Get(number int) ([]Item, error)
Get retrieves items from the queue. If the queue is empty, this call blocks until the next item is added to the queue. This will attempt to retrieve number of items.
func (*PriorityQueue) Len ¶
func (pq *PriorityQueue) Len() int
Len returns a number indicating how many items are in the queue.
func (*PriorityQueue) Peek ¶
func (pq *PriorityQueue) Peek() Item
Peek will look at the next item without removing it from the queue.
func (*PriorityQueue) Put ¶
func (pq *PriorityQueue) Put(items ...Item) error
Put adds items to the queue.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is the struct responsible for tracking the state of the queue.
func (*Queue) Dispose ¶
func (q *Queue) Dispose()
Dispose will dispose of this queue. Any subsequent calls to Get or Put will return an error.
func (*Queue) Disposed ¶
Disposed returns a bool indicating if this queue has had disposed called on it.
func (*Queue) Get ¶
Get will add an item to the queue. If there are some items in the queue, get will return a number UP TO the number passed in as a parameter. If no items are in the queue, this method will pause until items are added to the queue.