package ringo

  1. Overview
  2. Docs

A SET_MAKER is a functor that instantiates CACHE_SETs based on a given type and its associated hash function.

A Mutable structure akin to a set, but with a size bound. Note that, different caches have different policies towards the size bounds: some uphold the bound strictly, some treat the bound as a suggestion. In addition, some caches count their elements somewhat sloppily.

In general, the caches of ringo are intended to be used in settings that do not require strict, by-the-number, extremely-predictable behaviors.

See Functors for more information.

Parameters

module H : Stdlib.Hashtbl.HashedType

Signature

type elt = H.t

The type of values held by the cache.

type t

The type of caches holding values of type elt.

val create : int -> t

create n creates a unit-cache with a size-bound of n. Remember that the size-bound is not upheld strictly by all caches.

val add : t -> elt -> unit

add c v adds the value v to the cache c. This may or may not cause another element to be removed from the cache, depending on the number of elements already present in the cache c, the size-bound of the cache c, and the policy of the cache c towards its size-bound.

If v is already present in c, the element may count twice towards the size bound for some time. In other words: apart for size bound in some cases, the following sequences of operations are indistinguishable: add c v; add c u and add c v; remove c v; add c u

val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a

fold f c init folds the function f and value init over the elements of c.

Note that for some cache, this function may fold over a subset of the elements of c. See Functors for more details.

val iter : (elt -> unit) -> t -> unit

iter f c iterates the function f over the elements of c.

Note that for some cache, this function may iterate over a subset of the elements of c. See Functors for more details.

val mem : t -> elt -> bool

mem c v is true if v is present in c. It is false otherwise.

Note that the in some caches, this may have a side effect on the v element. Specifically, in some caches, it might make it less likely to be removed when supernumerary elements are inserted.

val remove : t -> elt -> unit

remove c v removes the element v from c. If v is not present in c, it does nothing.

Note that in some caches, removed elements can still count towards the size bound for some time.

val length : t -> int

length c is the number of elements present in c.

val clear : t -> unit

clear c removes all elements from c.

OCaml

Innovation. Community. Security.