CCRingBuffer.MakeFromArray
Makes a ring buffer module with the given array type
module Array = A
The module type of Array for this ring buffer
val create : int -> t
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.
val capacity : t -> int
Length of the inner buffer.
val length : t -> int
Number of elements currently stored in the buffer.
val is_full : t -> bool
true
if pushing an element would erase another element.
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.
val clear : t -> unit
Clear the content of the buffer
val is_empty : t -> bool
Is the buffer empty (i.e. contains no elements)?
val junk_front : t -> unit
Drop the front element from t
.
val junk_back : t -> unit
Drop the back element from t
.
val skip : t -> int -> unit
skip b len
removes len
elements from the front of b
.
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.
Create a buffer from an initial array, but doesn't take ownership of it (still allocates a new internal array).