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 { // 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 StIndex-1 StIndex int // the number of items stored starting at StIndex. Capped at Max Len int // the maximum number of items that can be stored in this ring Max int }
Index is the ring index structure, 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 StIndex. i must be < Len.
func (*Index) IndexIsValid ¶
IndexIsValid returns true if given index is valid: >= 0 and < Len