Documentation ¶
Overview ¶
Package ringbuffer contains a fixed-size concurrency-safe generic ring buffer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RingBuffer ¶
type RingBuffer[T any] struct { // contains filtered or unexported fields }
RingBuffer is a concurrency-safe ring buffer.
func New ¶
func New[T any](max int) *RingBuffer[T]
New creates a new RingBuffer containing at most max items.
func (*RingBuffer[T]) Add ¶
func (rb *RingBuffer[T]) Add(t T)
Add appends a new item to the RingBuffer, possibly overwriting the oldest item in the buffer if it is already full.
func (*RingBuffer[T]) GetAll ¶
func (rb *RingBuffer[T]) GetAll() []T
GetAll returns a copy of all the entries in the ring buffer in the order they were added.
func (*RingBuffer[T]) Len ¶
func (rb *RingBuffer[T]) Len() int
Len returns the number of elements in the ring buffer. Note that this value could change immediately after being returned if a concurrent caller modifies the buffer.
Click to show internal directories.
Click to hide internal directories.