Documentation ¶
Overview ¶
Package queue provides a fast, ring-buffer queue based on the version suggested by Dariusz Górecki. Using this instead of other, simpler, queue implementations (slice+append or linked list) provides substantial memory and time benefits, and fewer GC pauses.
The queue implemented here is as fast as it is for an additional reason: it is *not* thread-safe.
Index ¶
- type Item
- type PriorityQueue
- type PriorityQueueSlice
- func (pq PriorityQueueSlice) Len() int
- func (pq PriorityQueueSlice) Less(i, j int) bool
- func (pq *PriorityQueueSlice) Pop() interface{}
- func (pq *PriorityQueueSlice) Push(x interface{})
- func (pq PriorityQueueSlice) Swap(i, j int)
- func (pq *PriorityQueueSlice) Update(item *Item, value interface{}, priority int)
- type Queue
- type SyncQueue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct { Value interface{} // The Value of the item; arbitrary. Priority int // The Priority of the item in the queue. // The Index is needed by update and is maintained by the heap.Interface methods. Index int // The Index of the item in the heap. }
An Item is something we manage in a Priority queue.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
func (*PriorityQueue) Len ¶
func (pq *PriorityQueue) Len() int
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() *Item
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(item *Item)
func (*PriorityQueue) Remove ¶
func (pq *PriorityQueue) Remove(item *Item)
func (*PriorityQueue) Update ¶
func (pq *PriorityQueue) Update(item *Item, value interface{}, priority int)
type PriorityQueueSlice ¶
type PriorityQueueSlice []*Item
A PriorityQueueSlice implements heap.Interface and holds Items.
func (PriorityQueueSlice) Len ¶
func (pq PriorityQueueSlice) Len() int
func (PriorityQueueSlice) Less ¶
func (pq PriorityQueueSlice) Less(i, j int) bool
func (*PriorityQueueSlice) Pop ¶
func (pq *PriorityQueueSlice) Pop() interface{}
func (*PriorityQueueSlice) Push ¶
func (pq *PriorityQueueSlice) Push(x interface{})
func (PriorityQueueSlice) Swap ¶
func (pq PriorityQueueSlice) Swap(i, j int)
func (*PriorityQueueSlice) Update ¶
func (pq *PriorityQueueSlice) Update(item *Item, value interface{}, priority int)
update modifies the Priority and Value of an Item in the queue.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue represents a single instance of the queue data structure.
func (*Queue) Add ¶
func (q *Queue) Add(elem interface{})
Add puts an element on the end of the queue.
func (*Queue) Get ¶
Get returns the element at index i in the queue. If the index is invalid, the call will panic. This method accepts both positive and negative index values. Index 0 refers to the first element, and index -1 refers to the last.
type SyncQueue ¶
type SyncQueue struct {
// contains filtered or unexported fields
}
func NewSyncQueue ¶
func NewSyncQueue() *SyncQueue
func (*SyncQueue) RLockRange ¶
func (q *SyncQueue) RLockRange(f func(interface{}))