Module type CCRingBuffer.S
Ring Buffer
The abstract ring buffer type, made concrete by choice of ARRAY module implementation
- val create : int -> t
- create 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 -> int
- Length of the inner buffer. 
- val length : t -> int
- Number of elements currently stored in the buffer. 
- val is_full : t -> bool
- trueif pushing an element would erase another element.- since
- 1.3
 
- val blit_from : t -> Array.t -> int -> int -> unit
- blit_from buf from_buf o lencopies the slice- o, ... o + len - 1from an input buffer- from_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 of- s.
 
- val blit_into : t -> Array.t -> int -> int -> int
- blit_into buf to_buf o lencopies at most- lenelements from- bufinto- to_bufstarting at offset- oin- s.- returns
- the number of elements actually copied ( - min len (length buf)).
 - raises Invalid_argument
- if - o,lenis not a valid slice of- s.
 
- val append : t -> into:t -> unit
- append b ~intocopies all data from- band adds it at the end of- into. Erases data of- intoif 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.- raises Empty
- if the buffer is already empty. 
 
- val junk_back : t -> unit
- Drop the back element from - t.- raises Empty
- if the buffer is already empty. 
 
- val skip : t -> int -> unit
- skip b lenremoves- lenelements from the front of- b.- raises Invalid_argument
- if - len > length b.
 
- val iteri : t -> f:(int -> Array.elt -> unit) -> unit
- iteri b ~fcalls- f i tfor each element- tin- buf, with- ibeing its relative index within- buf.
- val get_front : t -> int -> Array.elt
- get_front buf ireturns the- i-th element of- buffrom the front, i.e. the one returned by- take_front bufafter- i-1calls to- junk_front buf.- raises Invalid_argument
- if the index is invalid (> - length buf).
 
- val get_back : t -> int -> Array.elt
- get_back buf ireturns the- i-th element of- buffrom the back, i.e. the one returned by- take_back bufafter- i-1calls to- junk_back buf.- raises Invalid_argument
- if the index is invalid (> - length buf).
 
- val push_back : t -> Array.elt -> unit
- Push value at the back of - t. If- t.bounded=false, the buffer will grow as needed, otherwise the oldest elements are replaced first.
- val peek_front_exn : t -> Array.elt
- First value from front of - t, without modification.- raises Empty
- if buffer is empty. 
 - since
- 1.3
 
- val peek_back_exn : t -> Array.elt
- Get the last value from back of - t, without modification.- raises Empty
- if buffer is empty. 
 - since
- 1.3
 
- val take_back_exn : t -> Array.elt
- Take and remove the last value from back of - t.- raises Empty
- if buffer is already empty. 
 
- val take_front_exn : t -> Array.elt
- Take and remove the first value from front of - t.- raises Empty
- if buffer is already empty.