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 fixed-size circular buffer for data. It supports concurrent writes and a "Drain" operation that returns all values since the last drain.
func NewRingBuffer ¶
func NewRingBuffer[T any](capacity int) *RingBuffer[T]
NewRingBuffer creates a new RingBuffer with the given capacity.
func (*RingBuffer[T]) Capacity ¶
func (r *RingBuffer[T]) Capacity() int
Capacity returns the total capacity of the buffer.
func (*RingBuffer[T]) Count ¶
func (r *RingBuffer[T]) Count() int
Count returns the number of unread data points currently in the buffer.
func (*RingBuffer[T]) Drain ¶
func (r *RingBuffer[T]) Drain() []T
Drain returns all unread data points and marks them as read.
func (*RingBuffer[T]) Snapshot ¶
func (r *RingBuffer[T]) Snapshot() []T
Snapshot returns all unread data points without marking them as read.
func (*RingBuffer[T]) WalkReverse ¶
func (r *RingBuffer[T]) WalkReverse(fn func(T) bool)
WalkReverse iterates over the buffer from newest to oldest. The callback function 'fn' is called for each item. If 'fn' returns false, iteration stops.
func (*RingBuffer[T]) Write ¶
func (r *RingBuffer[T]) Write(v T)
Write adds a new data point to the buffer. If the buffer is full, it overwrites the oldest unread value and advances the tail pointer.
type TimeValue ¶
TimeValue represents a timestamped numeric value for interpolation.
func Interpolate ¶
Interpolate aligns a series of raw data points to a fixed time grid.
raw: Input points, sorted by timestamp (oldest first). step: The desired time interval (e.g., 1s). alignTo: The timestamp to align the grid to (usually start of minute or epoch). maxGap: Maximum time gap allowed between points before interpolation stops (creates a gap).
Returns a slice of aligned TimeValues.