Module type Ringo.CACHE_MAP
val create : int -> 'a t
create n
creates a cache with a size-bound ofn
. Remember that the size-bound is not upheld strictly by all caches.
val replace : 'a t -> key -> 'a -> unit
replace c k v
binds the keyk
to the valuev
in the cachec
. This may or may not cause another binding to be removed from the cache, depending on the number of bindings already present in the cachec
, the size-bound of the cachec
, and the policy of the cachec
towards its size-bound.If
k
is already bound to a value inc
, the previous binding disappears and is replaced by the new binding tov
.Note that in caches with a
Sloppy
accounting policy, the old (removed) binding may still count towards the size bound for some time.
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
fold f c init
folds the functionf
and valueinit
over the bindings ofc
.Note that for caches with a
Weak
overflow policy, this function may fold over a subset of the bindings ofc
. SeeRingo
(orFunctors
) for more details.
val fold_v : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
fold_v f c init
folds the functionf
and valueinit
over the values held by the bindings ofc
.It is less powerful than
fold
in that it does not grant access to the bindings' keys, but it does fold over all the values bound inc
, even when thec
has aWeak
overflow policy.
val find_opt : 'a t -> key -> 'a option
find_opt c k
isSome v
ifk
is bound tov
inc
. It isNone
otherwise.Note that the in caches with a non-
FIFO
replacement policy, this may have a side effect on thek
-to-v
binding. Specifically, in those caches, it might make it less likely to be removed when supernumerary bindings are inserted.
val remove : 'a t -> key -> unit
remove c k
removes the binding fromk
inc
. Ifk
is not bound inc
, it does nothing.Note that in caches with a
Sloppy
accounting policy, 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 byc
.
val capacity : 'a t -> int
capacity c
is the number of bindingsc
can hold:capacity (create n) = n
val clear : 'a t -> unit
clear c
removes all bindings fromc
.