Module type Ringo.CACHE_SET
val create : int -> t
create n
creates a unit-cache with a size-bound ofn
. Remember that the size-bound is not upheld strictly by all caches.
val add : t -> elt -> unit
add c v
adds the valuev
to the cachec
. This may or may not cause another element to be removed from the cache, depending on the number of elements already present in the cachec
, the size-bound of the cachec
, and the policy of the cachec
towards its size-bound.Note that after the
add c v
call returns,v
is the most recent element in the cache. This is true whether or not the element was already in the cache before the call. This is true for whichever replacement policy (seeRingo.replacement
) the cache has.If
v
is already present inc
, and the accounting policy of the cache isSloppy
, the element may or may not count twice towards the size bound for some time. On the other hand, if the cache accounting isPrecise
then the elementv
only counts once. SeeRingo.accounting
for more details.
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
fold f c init
folds the functionf
and valueinit
over the elements ofc
.Note that for caches with a
Weak
overflow policy, this function may fold over a subset of the elements ofc
. SeeRingo
(orFunctors
) for more details.
val mem : t -> elt -> bool
mem c v
istrue
ifv
is present inc
. It isfalse
otherwise.Note that the in caches with a non-
FIFO
replacement policy, this may have a side effect on thev
element. Specifically, in those 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 elementv
fromc
. Ifv
is not present inc
, it does nothing.Note that in caches with a
Sloppy
accounting policy, removed elements can still count towards the size bound for some time. On the other hand, if the cache's accounting policy isPrecise
then the element immediately stops counting towards the size bound.
val length : t -> int
length c
is the number of elements present inc
.
val capacity : t -> int
capacity c
is the number of bindingsc
can hold:capacity (create n) = n
val clear : t -> unit
clear c
removes all elements fromc
.