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 Idx ¶
type Idx struct { StIdx int `` /* 175-byte string literal not displayed */ Len int `desc:"the number of items stored starting at StIdx. Capped at Max"` Max int `desc:"the maximum number of items that can be stored in this ring"` }
Idx 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 (*Idx) 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 (*Idx) IdxIsValid ¶
IdxIsValid returns true if given index is valid: >= 0 and < Len