package ringo

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Imperative Ring Buffer

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

type 'a t
val create : int -> 'a t

Allocates a ring buffer for a given number of values.

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

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

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

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

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

Adds the values of a list, in order.

val clear : 'a t -> unit

Removes all values in the ring buffer.

val last : 'a t -> 'a option

Retrieves the most recent value, or None when empty.

val last_exn : 'a t -> 'a

Same as last, but raises Empty when empty.

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

Iterates over the elements, oldest to newest.

val elements : 'a t -> 'a list

Retrieves the elements as a list, oldest first..

module type TABLE = sig ... end

Ring Buffer Table

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

Innovation. Community. Security.