Documentation ¶
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 thread-safe fixed buffer of elements with FIFO semantics. When the buffer is full, adding a new element overwrites the oldest element.
func NewRingBuffer ¶
func NewRingBuffer[T any](capacity int) *RingBuffer[T]
NewRingBuffer creates a new RingBuffer with a maximum size of capacity.
func (*RingBuffer[T]) Add ¶
func (r *RingBuffer[T]) Add(element T)
Add adds an element to the buffer, overwriting the oldest element if the buffer is full.
func (*RingBuffer[T]) Elements ¶
func (r *RingBuffer[T]) Elements() []T
Elements returns all the elements currently in the buffer, from newest to oldest.
Click to show internal directories.
Click to hide internal directories.