package containers-data
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=eb9b26eb2c3cf04fc5157d256eb49c43552ccb5c59c568772d70315db9669784
sha512=7f4cf5112c8047fd789c04129745dbe9783aa94390e8983f86408053b0af637e2a9cfce1559ce466b1b6ff7c01fd52d8685f5db1d1c0dda2c0aa138f90606a50
doc/containers-data/CCRingBuffer/module-type-S/index.html
Module type CCRingBuffer.S
Source
Ring Buffer
The abstract ring buffer type, made concrete by choice of ARRAY
module implementation
Defines the bounded ring buffer type
Raised in querying functions when the buffer is empty
create size
creates a new bounded buffer with given size. The underlying array is allocated immediately and no further (large) allocation will happen from now on.
blit_from buf from_buf o len
copies the slice o, ... o + len - 1
from an input buffer from_buf
to the end of the buffer. If the slice is too large for the buffer, only the last part of the array will be copied.
blit_into buf to_buf o len
copies at most len
elements from buf
into to_buf
starting at offset o
in s
.
append b ~into
copies all data from b
and adds it at the end of into
. Erases data of into
if there is not enough room.
iteri b ~f
calls f i t
for each element t
in buf
, with i
being its relative index within buf
.
get_front buf i
returns the i
-th element of buf
from the front, i.e. the one returned by take_front buf
after i-1
calls to junk_front buf
.
get_back buf i
returns the i
-th element of buf
from the back, i.e. the one returned by take_back buf
after i-1
calls to junk_back buf
.
Push value at the back of t
. If t.bounded=false
, the buffer will grow as needed, otherwise the oldest elements are replaced first.
Take and remove the first value from front of t
, if any.
Create a buffer from an initial array, but doesn't take ownership of it (still allocates a new internal array).