Library
Module
Module type
Parameter
Class
Class type
Make(K)(V)
is the LRU map with bindings K.t -> V.t
. The weight of an individual binding is the Weighted.weight
of V.t
.
Keys in t
.
val empty : int -> t
empty cap
is an empty map with capacity cap
.
val is_empty : t -> bool
is_empty t
is true
iff there are no bindings in t
.
val size : t -> int
size t
is the number of bindings in t
.
val weight : t -> int
weight t
is the combined weight of bindings in t
.
resize cap t
sets t
's capacity to cap
, while leaving the bindings unchanged.
trim t
is t'
, where weight t' <= capacity t'
.
This is achieved by discarding bindings in LRU-to-MRU order.
k
promote k t
is t
with the binding for k
promoted to most-recently-used, or t
if k
is not bound in t
.
add k v t
adds the binding k -> v
to t
as the most-recently-used binding.
Note add
does not remove bindings. To ensure that the resulting map is not over capacity, compose with trim
.
pop k t
is (v, t')
, where v
is the value bound to k
, and t'
is t
without the binding k -> t
, or None
if k
is not bound in t
.
lru t
is the least-recently-used binding in t
, or None
, when t
is empty.
pop_lru t
is ((k, v), t'
, where (k, v)
is lru t
, and t'
is t
without that binding.
fold f z t
is f k0 v0 (... (f kn vn z))
, where k0 -> v0
is LRU and kn -> vn
is MRU.
fold_k f z t
folds in key-increasing order, ignoring the recently-used ordering.
Note fold_k
is faster than fold
.
iter f t
applies f
to all the bindings in t
in in LRU-to-MRU order.
iter_k f t
applies f in key-increasing order, ignoring the recently-used ordering.
Note iter_k
is faster than iter
.