package containers

  1. Overview
  2. Docs
On This Page
  1. Ring Buffer
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module type CCRingBuffer.SSource

Ring Buffer

The abstract ring buffer type, made concrete by choice of ARRAY module implementation

The module type of Array for this ring buffer

Sourcetype t

Defines the bounded ring buffer type

Sourceexception Empty

Raised in querying functions when the buffer is empty

Sourceval 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.

Sourceval copy : t -> t

Make a fresh copy of the buffer.

Sourceval capacity : t -> int

Length of the inner buffer.

Sourceval length : t -> int

Number of elements currently stored in the buffer.

Sourceval is_full : t -> bool

true if pushing an element would erase another element.

  • since 1.3
Sourceval blit_from : t -> Array.t -> int -> int -> unit

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.

Sourceval blit_into : t -> Array.t -> int -> int -> int

blit_into buf to_buf o len copies at most len elements from buf into to_buf starting at offset o in s.

  • returns

    the number of elements actually copied (min len (length buf)).

Sourceval append : t -> into:t -> unit

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.

Sourceval to_list : t -> Array.elt list

Extract the current content into a list.

Sourceval clear : t -> unit

Clear the content of the buffer

Sourceval is_empty : t -> bool

Is the buffer empty (i.e. contains no elements)?

Sourceval junk_front : t -> unit

Drop the front element from t.

  • raises Empty

    if the buffer is already empty.

Sourceval junk_back : t -> unit

Drop the back element from t.

  • raises Empty

    if the buffer is already empty.

Sourceval skip : t -> int -> unit

skip b len removes len elements from the front of b.

Sourceval iter : t -> f:(Array.elt -> unit) -> unit

iter b ~f calls f i t for each element t in buf.

Sourceval iteri : t -> f:(int -> Array.elt -> unit) -> unit

iteri b ~f calls f i t for each element t in buf, with i being its relative index within buf.

Sourceval get_front : t -> int -> Array.elt

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.

Sourceval get_back : t -> int -> Array.elt

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.

Sourceval 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.

Sourceval peek_front : t -> Array.elt option

First value from front of t, without modification.

Sourceval peek_front_exn : t -> Array.elt

First value from front of t, without modification.

  • raises Empty

    if buffer is empty.

  • since 1.3
Sourceval peek_back : t -> Array.elt option

Get the last value from back of t, without modification.

Sourceval 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
Sourceval take_back : t -> Array.elt option

Take and remove the last value from back of t, if any.

Sourceval take_back_exn : t -> Array.elt

Take and remove the last value from back of t.

  • raises Empty

    if buffer is already empty.

Sourceval take_front : t -> Array.elt option

Take and remove the first value from front of t, if any.

Sourceval take_front_exn : t -> Array.elt

Take and remove the first value from front of t.

  • raises Empty

    if buffer is already empty.

Sourceval of_array : Array.t -> t

Create a buffer from an initial array, but doesn't take ownership of it (still allocates a new internal array).

  • since 0.11
Sourceval to_array : t -> Array.t

Create an array from the elements, in order.

  • since 0.11
OCaml

Innovation. Community. Security.