Library
Module
Module type
Parameter
Class
Class type
Signature of functional LRU maps.
Keys in t
.
Values 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 t
is empty.
val items : t -> int
items t
is the number of bindings in t
.
val size : t -> int
size t
is the combined weight of bindings in t
.
val capacity : t -> int
capacity t
is the maximum combined weight of bindings this map will hold before they start being discarded in least-recently-used order.
resize cap t
is a map with capacity cap
, holding the same bindings as t
. When the size
of t
is greater than cap
, least-recently-used bindings are discarded to fit cap
.
k
find k t
is (v, t')
, where v
is the value bound to k
and t'
is a map where the binding k -> v
has been promoted to most-recently-used. When k
is not bound in t
, the result in None
.
add k v t
is t
with the binding k -> v
. If k
is alread bound in t
, the old binding is replaced. In either case, the binding k -> v
is the most-recently-used.
unadd 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))
. Binding are folded over in key-increasing order.
iter f t
applies f
to all the bindings in t
in key-increasing order
of_list kvs
is a map with the bindings from kvs
. If there are multiple bindings for the same k
, it is unspecified which one is chosen.
~cap
is the capacity of the new map. It defaults to the total weight of bindings in kvs
. If given, and smaller than then total weight of v
s, bindings are discarded from the left of the list.
val pp :
?pp_size:(Format.formatter -> (int * int) -> unit) ->
?sep:(Format.formatter -> unit -> unit) ->
(Format.formatter -> (k * v) -> unit) ->
Format.formatter ->
t ->
unit