Documentation ¶
Overview ¶
ring implements RingBuffer
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RingBuffer ¶
type RingBuffer[T Numeric] struct { // contains filtered or unexported fields }
RingBuffer is a generic fixed-size circular buffer for numeric types.
func NewRingBuffer ¶
func NewRingBuffer[T Numeric](size int) *RingBuffer[T]
NewRingBuffer creates a new RingBuffer of the given size.
func (*RingBuffer[T]) Add ¶
func (rb *RingBuffer[T]) Add(value T)
Add adds a new element to the buffer.
func (*RingBuffer[T]) AverageNonZero ¶
func (rb *RingBuffer[T]) AverageNonZero() T
AverageNonZero calculates the average of non-zero elements in the buffer.
func (*RingBuffer[T]) GetAll ¶
func (rb *RingBuffer[T]) GetAll() []T
GetAll retrieves all elements from the buffer in order.
func (*RingBuffer[T]) GetLast ¶
func (rb *RingBuffer[T]) GetLast() T
GetLast retrieves the last element from the buffer. If the buffer is empty, it returns the zero value of the type.
func (*RingBuffer[T]) GetSecondLast ¶ added in v1.1.3
func (rb *RingBuffer[T]) GetSecondLast() T
GetSecondLast retrieves the second-to-last element from the buffer. If the buffer has fewer than two elements, it returns the zero value of the type.
Click to show internal directories.
Click to hide internal directories.