Library
Module
Module type
Parameter
Class
Class type
A MAKER
is a functor that instantiates CACHE
s based on a given type and its associated hash function.
A Mutable structure akin to a hash-table, 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.
module H : Hashtbl.HashedType
type key = H.t
The type of keys on which values in the cache are indexed.
val create : int -> 'a t
create n
creates a cache with a size-bound of n
. Remember that the size-bound is not upheld strictly by all caches.
add c k v
binds the key k
to the value v
in the cache c
. This may or may not cause another binding to be removed from the cache, depending on the number of bindings 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 k
is already bound to a value in c
, the previous binding disappears and is replaced by the new binding to v
. Note that in some caches, the old binding is erased but may still count towards the size bound for some time. In other words: apart for size bound in some cases, the following sequences of operations are undistinguishable: add c k v; add c k u
and add c k v; remove c k; add c k u
fold f c init
folds the function f
and value init
over the bindings of c
.
Note that for some cache, this function may fold over a subset of the bindings of c
. See Functors
for more details.
iter f c
iterates the function f
over the bindings of c
.
Note that for some cache, this function may iterate over a subset of the bindings of c
. See Functors
for more details.
find_opt c k
is Some v
if k
is bound to v
in c
. It is None
otherwise.
Note that the in some caches, this may have a side effect on the k
-to-v
binding. Specifically, in some caches, it might make it less likely to be removed when supernumerary bindings are inserted.
remove c k
removes the binding from k
in c
. If k
is not bound in c
, it does nothing.
Note that in some caches, removed bindings can still count towards the size bound for some time.
val length : 'a t -> int
length c
is the number of bindings held by c
.