cb

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

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

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

type Queue

type Queue[T any] interface {
	Empty() bool
	Full() bool
	Size() int
	Capacity() int
	Push(item T) bool
	Pop() (value T, ok bool)
	PushBlocking(item T)
	PopBlocking() (value T)
}

Jump to

Keyboard shortcuts

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