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 growable FIFO queue that reuses its backing storage. The slice length stores the queue length, so wrapped positions are accessed by reslicing to capacity.
func (*RingBuffer[T]) Clear ¶
func (r *RingBuffer[T]) Clear()
Clear removes all elements while retaining the allocated storage.
func (*RingBuffer[T]) Empty ¶
func (r *RingBuffer[T]) Empty() bool
Empty says if the ring buffer is empty.
func (*RingBuffer[T]) Init ¶
func (r *RingBuffer[T]) Init(size int)
Init preallocates a buffer with a certain size.
func (*RingBuffer[T]) Len ¶
func (r *RingBuffer[T]) Len() int
Len returns the number of elements in the ring buffer.
func (*RingBuffer[T]) PeekFront ¶
func (r *RingBuffer[T]) PeekFront() T
PeekFront returns the next element. It must not be called when the buffer is empty, that means that callers might need to check if there are elements in the buffer first.
func (*RingBuffer[T]) PopFront ¶
func (r *RingBuffer[T]) PopFront() T
PopFront returns the next element. It must not be called when the buffer is empty, that means that callers might need to check if there are elements in the buffer first.
func (*RingBuffer[T]) PushBack ¶
func (r *RingBuffer[T]) PushBack(t T)
PushBack adds a new element. If the ring buffer is full, its capacity is increased first.