package aches
Install
Dune Dependency
Authors
Maintainers
Sources
md5=c9c5400e7ae19100b945279835ff3e5c
sha512=7f37b721e2ca32e5e96fbf8df1bbd72c9060b6826bd95a21ea81af5fdd0c1961d3d7fb41210966aac7c277ec7f91fd32e3e284b583cb02121dc589646642f5c0
doc/aches.vache/Vache/module-type-SET/index.html
Module type Vache.SET
Source
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 Vache are intended to be used in settings that do not require strict, by-the-number, extremely-predictable behaviors.
See Vache
(or Functors
) for more information.
The type of values held by the cache.
The type of caches holding values of type elt
.
create n
creates a unit-cache with a size-bound of n
. Remember that size-bound is not upheld strictly by all caches. Moreover, caches instantiated with a specialised size (i.e., empty and singleton caches) ignore the size parameter entirely.
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.
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 (see Vache.replacement
) the cache has.
If v
is already present in c
, and the accounting policy of the cache is Sloppy
, the element may or may not count twice towards the size bound for some time. On the other hand, if the cache accounting is Precise
then the element v
only counts once. See Vache.accounting
for more details.
fold f c init
folds the function f
and value init
over the elements of c
from newest to oldest.
Note that for caches with a Weak
overflow policy, this function may fold over a subset of the elements of c
. See Vache
(or Functors
) for more details.
fold_oldest_first
is like fold
but in reversed order: oldest elements of c
first. This function has the same limitation as fold
.
mem c v
is true
if v
is present in c
. It is false
otherwise.
Note that the in caches with a non-FIFO
replacement policy, this may have a side effect on the v
element. Specifically, in those caches, it might make it less likely to be removed when supernumerary elements are inserted.
remove c v
removes the element v
from c
. If v
is not present in c
, 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 is Precise
then the element immediately stops counting towards the size bound.
capacity c
is the number of bindings c
can hold: capacity (create n) = n