Documentation ¶
Overview ¶
First In First Out (FIFO) Queue with fixed capacity. Circular Buffer implementation in Go with both pub/sub thread safe blocking API and pure FIFO queue with set capacity unsynchronized base. Two versions of the same Queue interface: one actually a circular buffer CircularBuffer, the other using a channel CircularBufferChan, created using cb.New or cb.NewC respectively.
Index ¶
- type CircularBuffer
- func (cb *CircularBuffer[T]) Capacity() int
- func (cb *CircularBuffer[T]) Empty() bool
- func (cb *CircularBuffer[T]) Full() bool
- func (cb *CircularBuffer[T]) Pop() (T, bool)
- func (cb *CircularBuffer[T]) PopBlocking() T
- func (cb *CircularBuffer[T]) Push(item T) bool
- func (cb *CircularBuffer[T]) PushBlocking(item T)
- func (cb *CircularBuffer[T]) Size() int
- type CircularBufferChan
- func (cb *CircularBufferChan[T]) Capacity() int
- func (cb *CircularBufferChan[T]) Empty() bool
- func (cb *CircularBufferChan[T]) Full() bool
- func (cb *CircularBufferChan[T]) Pop() (value T, ok bool)
- func (cb *CircularBufferChan[T]) PopBlocking() T
- func (cb *CircularBufferChan[T]) Push(item T) bool
- func (cb *CircularBufferChan[T]) PushBlocking(item T)
- func (cb *CircularBufferChan[T]) Size() int
- type Queue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircularBuffer ¶
type CircularBuffer[T any] struct { // contains filtered or unexported fields }
FIFO Queue with fixed capacity. Fixed array implementation.
func New ¶
func New[T any](capacity int) *CircularBuffer[T]
New returns the fixed array version of 0 alloc fixed capacity (optionally blocking) Queue.
func (*CircularBuffer[T]) Capacity ¶
func (cb *CircularBuffer[T]) Capacity() int
func (*CircularBuffer[T]) Empty ¶
func (cb *CircularBuffer[T]) Empty() bool
func (*CircularBuffer[T]) Full ¶
func (cb *CircularBuffer[T]) Full() bool
func (*CircularBuffer[T]) Pop ¶
func (cb *CircularBuffer[T]) Pop() (T, bool)
Pop removes an item from the queue. returns false if queue is empty.
func (*CircularBuffer[T]) PopBlocking ¶
func (cb *CircularBuffer[T]) PopBlocking() T
Pop removes an item from the queue. blocks if queue is empty.
func (*CircularBuffer[T]) Push ¶
func (cb *CircularBuffer[T]) Push(item T) bool
Push adds an item to the queue. returns false if queue is full.
func (*CircularBuffer[T]) PushBlocking ¶
func (cb *CircularBuffer[T]) PushBlocking(item T)
Push adds an item to the queue. blocks if queue is full.
func (*CircularBuffer[T]) Size ¶
func (cb *CircularBuffer[T]) Size() int
type CircularBufferChan ¶
type CircularBufferChan[T any] struct { // contains filtered or unexported fields }
FIFO Queue with fixed capacity. Channel / go idiomatic version (blocking, multi thread safe), use CircularBufferChan for low/no contention cases as it is faster.
func NewC ¶
func NewC[T any](capacity int) *CircularBufferChan[T]
NewC returns a channel (CircularBufferChan) version of 0 alloc pub/sub fixed capacity blocking queue.
func (*CircularBufferChan[T]) Capacity ¶
func (cb *CircularBufferChan[T]) Capacity() int
func (*CircularBufferChan[T]) Empty ¶
func (cb *CircularBufferChan[T]) Empty() bool
func (*CircularBufferChan[T]) Full ¶
func (cb *CircularBufferChan[T]) Full() bool
func (*CircularBufferChan[T]) Pop ¶
func (cb *CircularBufferChan[T]) Pop() (value T, ok bool)
Pop removes an item from the queue. returns false if queue is empty. Note: might block and not return false at times. Use PopBlocking for correct version.
func (*CircularBufferChan[T]) PopBlocking ¶
func (cb *CircularBufferChan[T]) PopBlocking() T
Pop removes an item from the queue. blocks if queue is empty.
func (*CircularBufferChan[T]) Push ¶
func (cb *CircularBufferChan[T]) Push(item T) bool
Push adds an item to the queue. returns false if queue is full. Note: might block and not return false at times. Use PushBlocking for correct version.
func (*CircularBufferChan[T]) PushBlocking ¶
func (cb *CircularBufferChan[T]) PushBlocking(item T)
Push adds an item to the queue. blocks if queue is full.
func (*CircularBufferChan[T]) Size ¶
func (cb *CircularBufferChan[T]) Size() int