Documentation
¶
Overview ¶
Package ringidx provides circular indexing logic for writing a given length of data into a fixed-sized buffer and wrapping around this buffer, overwriting the oldest data. No copying is required so it is highly efficient
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FIx ¶
type FIx struct {
// the zero index position -- where logical 0 is in physical buffer
Zi uint32
// the length of the buffer -- wraps around at this modulus
Len uint32
// contains filtered or unexported fields
}
FIx is a fixed-length ring index structure -- does not grow or shrink dynamically.
func (*FIx) IndexIsValid ¶
IndexIsValid returns true if given index is valid: >= 0 and < Len
type Index ¶
type Index struct {
// Start the starting index where current data starts.
// The oldest data is at this index, and continues for Len items,
// wrapping around at Max, coming back up at most to Start-1.
Start int
// Len is the number of items stored starting at Start. Capped at Max.
Len int
// Max is the maximum number of items that can be stored in this ring.
Max int
}
Index is the ring index structure for a dynamically-sized ring buffer, maintaining starting index and length into a ring-buffer with maximum length Max. Max must be > 0 and Len <= Max. When adding new items would overflow Max, starting index is shifted over to overwrite the oldest items with the new ones. No moving is ever required: just a fixed-length buffer of size Max.
func (*Index) Add ¶
Add adds given number of items to the ring (n <= Len. Shift is called for Len+n - Max extra items to make room.
func (*Index) Index ¶
Index returns the index of the i'th item starting from Start. i must be < Len.
func (*Index) IndexIsValid ¶
IndexIsValid returns true if given index is valid: >= 0 and < Len