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 ¶ added in v1.1.23
type FIx struct { Zi int `desc:"the zero index position -- where logical 0 is in physical buffer"` Len int `desc:"the length of the buffer -- wraps around at this modulus"` }
FIx is a fixed-length ring index structure -- does not grow or shrink dynamically.
func (*FIx) Idx ¶ added in v1.1.23
Idx returns the physical index of the logical index i. i must be < Len.
func (*FIx) IdxIsValid ¶ added in v1.1.23
IdxIsValid returns true if given index is valid: >= 0 and < Len
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