Library
Module
Module type
Parameter
Class
Class type
A bounded table which optimistically cheats on the bound and sometimes counts wrong. Specifically, the table retains a bounded number of elements. It will also retain more if given more than that, but it will always drop back to the bound if the garbage collector intervenes.
module K : Hashtbl.HashedType
type key = K.t
val create : int -> 'a t
create n
is a table with at most n
elements except when it has more.
add t k v
adds a mapping from key k
to value v
in the table. NOTE: when n values are bound to the same key, it may count as up to n elements. However, NOTE: when n values are bound to the same key, only the last binding can be found with find_opt
or traversed with fold
.
fold f t acc
folds the function f
and value acc
through the recently added elements of t
. It never folds over more elements than the size bound of the table, even if the table temporarily holds more elements.
find_opt t k
is Some v
if k
is bound to v
in t
and None
otherwise. A key k
is bound to a value v
in t
if add t k v
has been called and not too many other bindings have been added since then.
remove t k
removes the binding from key
to the associated element in t
. Note that you may still be able to find the element using find_opt
for some time.
val length : 'a t -> int
length t
is the number of elements currently in t
, including those that may be garbage collected.