package ringo

  1. Overview
  2. Docs

Module Ringo.RingSource

Imperative Ring Buffer

Sourceexception Empty

An imperative ring buffer: a mutable structure that holds at most a fixed number of values of a same type. Values are never removed, once the limit is reached, adding a value replaces the oldest one in the ring buffer.

Sourcetype 'a t
Sourceval create : int -> 'a t

Allocates a ring buffer for a given number of values.

Sourceval add : 'a t -> 'a -> unit

Adds a value, dropping the oldest present one if full.

Sourceval add_and_return_erased : 'a t -> 'a -> 'a option

Same as add, but returns the dropped value if any.

Sourceval add_list : 'a t -> 'a list -> unit

Adds the values of a list, in order.

Sourceval clear : 'a t -> unit

Removes all values in the ring buffer.

Sourceval last : 'a t -> 'a option

Retrieves the most recent value, or None when empty.

Sourceval last_exn : 'a t -> 'a

Same as last, but raises Empty when empty.

Sourceval fold : 'a t -> init:'b -> f:('b -> 'a -> 'b) -> 'b

Iterates over the elements, oldest to newest.

Sourceval elements : 'a t -> 'a list

Retrieves the elements as a list, oldest first..

Sourcemodule type TABLE = sig ... end

Ring Buffer Table

Sourcemodule MakeTable (V : Hashtbl.HashedType) : TABLE with type v = V.t