chanx

package
v0.0.0-...-58a2b35 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIsEmpty = errors.New("ringbuffer is empty")

Functions

This section is empty.

Types

type RingBuffer

type RingBuffer[T any] struct {
	// contains filtered or unexported fields
}

RingBuffer is a ring buffer for common types. It never is full and always grows if it will be full. It is not thread-safe(goroutine-safe) so you must use the lock-like synchronization primitive to use it in multiple writers and multiple readers.

func NewRingBuffer

func NewRingBuffer[T any](initialSize int, maxQueue int) *RingBuffer[T]

func (*RingBuffer[T]) Capacity

func (r *RingBuffer[T]) Capacity() int

Capacity returns the size of the underlying buffer.

func (*RingBuffer[T]) IsEmpty

func (r *RingBuffer[T]) IsEmpty() bool

func (*RingBuffer[T]) Len

func (r *RingBuffer[T]) Len() int

func (*RingBuffer[T]) Peek

func (r *RingBuffer[T]) Peek() T

func (*RingBuffer[T]) Pop

func (r *RingBuffer[T]) Pop() T

func (*RingBuffer[T]) Read

func (r *RingBuffer[T]) Read() (T, error)

func (*RingBuffer[T]) Reset

func (r *RingBuffer[T]) Reset()

func (*RingBuffer[T]) Write

func (r *RingBuffer[T]) Write(v T)

type UnboundedChan

type UnboundedChan[T any] struct {
	In  chan<- T // channel for write
	Out <-chan T // channel for read
	// contains filtered or unexported fields
}

UnboundedChan is an unbounded chan. In is used to write without blocking, which supports multiple writers. and Out is used to read, which supports multiple readers. You can close the in channel if you want.

func NewUnboundedChan

func NewUnboundedChan[T any](ctx context.Context, initCapacity int, maxQueue int) *UnboundedChan[T]

NewUnboundedChan creates the unbounded chan. in is used to write without blocking, which supports multiple writers. and out is used to read, which supports multiple readers. You can close the in channel if you want.

func NewUnboundedChanSize

func NewUnboundedChanSize[T any](ctx context.Context, initInCapacity, initOutCapacity, initBufCapacity int, maxQueue int) *UnboundedChan[T]

NewUnboundedChanSize is like NewUnboundedChan but you can set initial capacity for In, Out, Buffer.

func (UnboundedChan[T]) BufLen

func (c UnboundedChan[T]) BufLen() int

BufLen returns len of the buffer. It is not accurate and only for your evaluating approximate number of elements in this chan, see https://github.com/smallnest/chanx/issues/7.

func (UnboundedChan[T]) Len

func (c UnboundedChan[T]) Len() int

Len returns len of In plus len of Out plus len of buffer. It is not accurate and only for your evaluating approximate number of elements in this chan, see https://github.com/smallnest/chanx/issues/7.

Jump to

Keyboard shortcuts

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