queue

package module
v0.0.0-...-fd9e7ea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CircularBuffer

type CircularBuffer struct {
	// contains filtered or unexported fields
}

CircularBuffer is a buffer which retains a set of values in memory, and overwrites the oldest item in the buffer when a new item needs to be written.

func NewCircularBuffer

func NewCircularBuffer(size int) (*CircularBuffer, error)

NewCircularBuffer returns a new circular buffer with the size provided. It will fail if a zero or negative size parameter is provided.

func (*CircularBuffer) Add

func (c *CircularBuffer) Add(item interface{})

Add adds an item to the buffer, overwriting the oldest item if the buffer is full.

func (*CircularBuffer) Latest

func (c *CircularBuffer) Latest() interface{}

Latest returns the item that was most recently added to the buffer.

func (*CircularBuffer) List

func (c *CircularBuffer) List() []interface{}

List returns a copy of the items in the buffer ordered from the oldest to newest item.

func (*CircularBuffer) Total

func (c *CircularBuffer) Total() int

Total returns the total number of items that have been added to the buffer.

type ConcurrentQueue

type ConcurrentQueue struct {
	// contains filtered or unexported fields
}

ConcurrentQueue is a concurrent-safe FIFO queue with unbounded capacity. Clients interact with the queue by pushing items into the in channel and popping items from the out channel. There is a goroutine that manages moving items from the in channel to the out channel in the correct order that must be started by calling Start().

func NewConcurrentQueue

func NewConcurrentQueue(bufferSize int) *ConcurrentQueue

NewConcurrentQueue constructs a ConcurrentQueue. The bufferSize parameter is the capacity of the output channel. When the size of the queue is below this threshold, pushes do not incur the overhead of the less efficient overflow structure.

func (*ConcurrentQueue) ChanIn

func (cq *ConcurrentQueue) ChanIn() chan<- interface{}

ChanIn returns a channel that can be used to push new items into the queue.

func (*ConcurrentQueue) ChanOut

func (cq *ConcurrentQueue) ChanOut() <-chan interface{}

ChanOut returns a channel that can be used to pop items from the queue.

func (*ConcurrentQueue) Start

func (cq *ConcurrentQueue) Start()

Start begins a goroutine that manages moving items from the in channel to the out channel. The queue tries to move items directly to the out channel minimize overhead, but if the out channel is full it pushes items to an overflow queue. This must be called before using the queue.

func (*ConcurrentQueue) Stop

func (cq *ConcurrentQueue) Stop()

Stop ends the goroutine that moves items from the in channel to the out channel. This does not clear the queue state, so the queue can be restarted without dropping items.

type GCQueue

type GCQueue struct {
	// contains filtered or unexported fields
}

GCQueue is garbage collecting queue, which dynamically grows and contracts based on load. If the queue has items which have been returned, the queue will check every gcInterval amount of time to see if any elements are eligible to be released back to the runtime. Elements that have been in the queue for a duration of least expiryInterval will be released upon the next iteration of the garbage collection, thus the maximum amount of time an element remain in the queue is expiryInterval+gcInterval. The gc ticker will be disabled after all items in the queue have been taken or released to ensure that the GCQueue becomes quiescent, and imposes minimal overhead in the steady state.

func NewGCQueue

func NewGCQueue(newItem func() interface{}, returnQueueSize int,
	gcInterval, expiryInterval time.Duration) *GCQueue

NewGCQueue creates a new garbage collecting queue, which dynamically grows and contracts based on load. If the queue has items which have been returned, the queue will check every gcInterval amount of time to see if any elements are eligible to be released back to the runtime. Elements that have been in the queue for a duration of least expiryInterval will be released upon the next iteration of the garbage collection, thus the maximum amount of time an element remain in the queue is expiryInterval+gcInterval. The gc ticker will be disabled after all items in the queue have been taken or released to ensure that the GCQueue becomes quiescent, and imposes minimal overhead in the steady state. The returnQueueSize parameter is used to size the maximal number of items that can be returned without being dropped during large bursts in attempts to return items to the GCQUeue.

func (*GCQueue) Return

func (q *GCQueue) Return(item interface{})

Return adds the returned item to freelist if the queue's returnBuffer has available capacity. Under load, items may be dropped to ensure this method does not block.

func (*GCQueue) Take

func (q *GCQueue) Take() interface{}

Take returns either a recycled element from the queue, or creates a new item if none are available.

type PriorityQueue

type PriorityQueue struct {
	// contains filtered or unexported fields
}

PriorityQueue wraps a standard heap into a self contained class.

func (*PriorityQueue) Empty

func (pq *PriorityQueue) Empty() bool

Empty returns true if the queue is empty.

func (*PriorityQueue) Len

func (pq *PriorityQueue) Len() int

Len returns the length of the queue.

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() PriorityQueueItem

Pop removes the top most item from the queue.

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(item PriorityQueueItem)

Push adds an item to the priority queue.

func (*PriorityQueue) Top

func (pq *PriorityQueue) Top() PriorityQueueItem

Top returns the top most item from the queue without removing it.

type PriorityQueueItem

type PriorityQueueItem interface {
	// Less must return true if this item is ordered before other and false
	// otherwise.
	Less(other PriorityQueueItem) bool
}

PriorityQueueItem is an interface that represents items in a PriorityQueue. Users of PriorityQueue will need to define a Less function such that PriorityQueue will be able to use that to build and restore an underlying heap.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL