Documentation
¶
Overview ¶
Package piring provides a ring buffer implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer[E any] struct { // contains filtered or unexported fields }
Buffer is a ring buffer (circular queue) that allows reusing elements stored in the buffer.
It supports writing new elements. When full, the oldest element is overwritten with the new one. All elements can be accessed at any time by index.
func (*Buffer[E]) NextWritePointer ¶
func (b *Buffer[E]) NextWritePointer() *E
NextWritePointer returns a pointer to the next write location.
If there is no space left, the oldest element is returned. This allows reusing the oldest element and can help avoid allocations.
func (*Buffer[E]) PointerTo ¶
PointerTo returns a pointer to the element at the given index.
PointerTo(0) returns the oldest element, while PointerTo(Len()-1) returns the newest. The index can be out of range — negative or greater than Len or Cap. In such cases, the index is wrapped until it fits within the buffer and corresponds to a valid element.
PointerTo always returns a pointer to an element in the buffer.