Documentation
¶
Overview ¶
Package queue implements a priority queue.
Index ¶
- type Entry
- type PriorityQueue
- func (q *PriorityQueue) Dequeue() interface{}
- func (q *PriorityQueue) DequeueIndex(index int) *Entry
- func (q *PriorityQueue) DequeueRandom(r *rand.Rand) *Entry
- func (q *PriorityQueue) Enqueue(priority uint64, value interface{})
- func (q *PriorityQueue) Len() int
- func (q PriorityQueue) Less(i, j int) bool
- func (q *PriorityQueue) Peek() *Entry
- func (q *PriorityQueue) PeekIndex(i int) *Entry
- func (q *PriorityQueue) Pop() interface{}
- func (q *PriorityQueue) Push(x interface{})
- func (q *PriorityQueue) Remove(index int) interface{}
- func (q PriorityQueue) Swap(i, j int)
- type TimerQueue
- func (t *TimerQueue) Cancel(value interface{}) bool
- func (t *TimerQueue) EnqueueDirect(priority uint64, value interface{})
- func (t *TimerQueue) Len() int
- func (t *TimerQueue) Peek() *Entry
- func (t *TimerQueue) Pop() interface{}
- func (t *TimerQueue) Push(priority uint64, value interface{})
- func (t *TimerQueue) PushChLen() int
- func (t *TimerQueue) Start()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
Value interface{}
Priority uint64
}
Entry is a PriorityQueue entry.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue is a priority queue instance.
func (*PriorityQueue) Dequeue ¶ added in v0.0.73
func (q *PriorityQueue) Dequeue() interface{}
Dequeue removes and returns the lowest priority entry, maintaining heap order.
func (*PriorityQueue) DequeueIndex ¶
func (q *PriorityQueue) DequeueIndex(index int) *Entry
DequeueIndex removes the specified entry from the queue.
func (*PriorityQueue) DequeueRandom ¶
func (q *PriorityQueue) DequeueRandom(r *rand.Rand) *Entry
DequeueRandom removes a random entry from the queue.
func (*PriorityQueue) Enqueue ¶
func (q *PriorityQueue) Enqueue(priority uint64, value interface{})
Enqueue inserts the provided value, into the queue with the specified priority.
func (*PriorityQueue) Len ¶
func (q *PriorityQueue) Len() int
Len returns the current length of the priority queue.
func (PriorityQueue) Less ¶
func (q PriorityQueue) Less(i, j int) bool
Less implements sort.Interface Less method
func (*PriorityQueue) Peek ¶
func (q *PriorityQueue) Peek() *Entry
Peek returns the 0th entry (lowest priority) if any, leaving the PriorityQueue unaltered. Callers MUST NOT alter the Priority of the returned entry.
func (*PriorityQueue) PeekIndex ¶
func (q *PriorityQueue) PeekIndex(i int) *Entry
PeekIndex peeks at the specified index.
func (*PriorityQueue) Pop ¶
func (q *PriorityQueue) Pop() interface{}
Pop implements heap.Interface Pop method. It removes and returns the last element (used internally by container/heap). External callers should use Dequeue() instead for correct min-priority ordering.
func (*PriorityQueue) Push ¶
func (q *PriorityQueue) Push(x interface{})
Push implements heap.Interface Push method
func (*PriorityQueue) Remove ¶
func (q *PriorityQueue) Remove(index int) interface{}
Remove removes and returns element from the heap with given index
func (PriorityQueue) Swap ¶
func (q PriorityQueue) Swap(i, j int)
Swap implements sort.Interface Swap method
type TimerQueue ¶ added in v0.0.74
func NewTimerQueue ¶ added in v0.0.74
func NewTimerQueue(action func(interface{})) *TimerQueue
func (*TimerQueue) Cancel ¶ added in v0.0.74
func (t *TimerQueue) Cancel(value interface{}) bool
Cancel removes the first queued entry whose Value is equal to the supplied value (Go == comparison, which for pointer values is pointer identity), and returns true if an entry was removed. Entries already popped by the worker are not cancellable; callers that need to defend against the popped-but-action-not-yet-run race must handle that at the action callback.
func (*TimerQueue) EnqueueDirect ¶ added in v0.0.74
func (t *TimerQueue) EnqueueDirect(priority uint64, value interface{})
EnqueueDirect inserts an entry directly into the internal heap, bypassing the push channel and any worker buffering. Intended for tests that wish to populate the heap without running the worker. Holds the queue's write lock for the duration of the call.
func (*TimerQueue) Len ¶ added in v0.0.74
func (t *TimerQueue) Len() int
func (*TimerQueue) Peek ¶ added in v0.0.74
func (t *TimerQueue) Peek() *Entry
func (*TimerQueue) Pop ¶ added in v0.0.74
func (t *TimerQueue) Pop() interface{}
func (*TimerQueue) Push ¶ added in v0.0.74
func (t *TimerQueue) Push(priority uint64, value interface{})
func (*TimerQueue) PushChLen ¶ added in v0.0.74
func (t *TimerQueue) PushChLen() int
PushChLen reports the number of items presently buffered in the push channel waiting to be ingested by the worker. Intended for tests that wish to assert "items were pushed but the worker has not yet drained them"; production callers should not depend on this value.
func (*TimerQueue) Start ¶ added in v0.0.74
func (t *TimerQueue) Start()