Module CCRingBuffer.Make
Buffer using regular arrays
Parameters
X : sig ... end
Signature
module Array : Array.S with type elt = X.t and type t = X.t arrayThe module type of Array for this ring buffer
val create : int -> tcreate sizecreates a new bounded buffer with given size. The underlying array is allocated immediately and no further (large) allocation will happen from now on.- raises Invalid_argument
if the argument is
< 1.
val capacity : t -> intLength of the inner buffer.
val length : t -> intNumber of elements currently stored in the buffer.
val is_full : t -> booltrueif pushing an element would erase another element.- since
- 1.3
val blit_from : t -> Array.t -> int -> int -> unitblit_from buf from_buf o lencopies the sliceo, ... o + len - 1from an input bufferfrom_bufto the end of the buffer. If the slice is too large for the buffer, only the last part of the array will be copied.- raises Invalid_argument
if
o,lenis not a valid slice ofs.
val blit_into : t -> Array.t -> int -> int -> intblit_into buf to_buf o lencopies at mostlenelements frombufintoto_bufstarting at offsetoins.- returns
the number of elements actually copied (
min len (length buf)).
- raises Invalid_argument
if
o,lenis not a valid slice ofs.
val append : t -> into:t -> unitappend b ~intocopies all data fromband adds it at the end ofinto. Erases data ofintoif there is not enough room.
val clear : t -> unitClear the content of the buffer
val is_empty : t -> boolIs the buffer empty (i.e. contains no elements)?
val junk_front : t -> unitDrop the front element from
t.- raises Empty
if the buffer is already empty.
val junk_back : t -> unitDrop the back element from
t.- raises Empty
if the buffer is already empty.
val skip : t -> int -> unitskip b lenremoveslenelements from the front ofb.- raises Invalid_argument
if
len > length b.
val iteri : t -> f:(int -> Array.elt -> unit) -> unititeri b ~fcallsf i tfor each elementtinbuf, withibeing its relative index withinbuf.
val get_front : t -> int -> Array.eltget_front buf ireturns thei-th element ofbuffrom the front, i.e. the one returned bytake_front bufafteri-1calls tojunk_front buf.- raises Invalid_argument
if the index is invalid (>
length buf).
val get_back : t -> int -> Array.eltget_back buf ireturns thei-th element ofbuffrom the back, i.e. the one returned bytake_back bufafteri-1calls tojunk_back buf.- raises Invalid_argument
if the index is invalid (>
length buf).
val push_back : t -> Array.elt -> unitPush value at the back of
t. Ift.bounded=false, the buffer will grow as needed, otherwise the oldest elements are replaced first.
val peek_front_exn : t -> Array.eltFirst value from front of
t, without modification.- raises Empty
if buffer is empty.
- since
- 1.3
val peek_back_exn : t -> Array.eltGet the last value from back of
t, without modification.- raises Empty
if buffer is empty.
- since
- 1.3
val take_back_exn : t -> Array.eltTake and remove the last value from back of
t.- raises Empty
if buffer is already empty.
val take_front_exn : t -> Array.eltTake and remove the first value from front of
t.- raises Empty
if buffer is already empty.