type t
The type of tables that contain elements of type
data
. Note that weak hash sets cannot be marshaled usingStdlib.output_value
or the functions of theMarshal
module.
val create : int -> t
create n
creates a new empty weak hash set, of initial sizen
. The table will grow as needed.
val clear : t -> unit
Remove all elements from the table.
val merge : t -> data -> data
merge t x
returns an instance ofx
found int
if any, or else addsx
tot
and returnx
.
val add : t -> data -> unit
add t x
addsx
tot
. If there is already an instance ofx
int
, it is unspecified which one will be returned by subsequent calls tofind
andmerge
.
val remove : t -> data -> unit
remove t x
removes fromt
one instance ofx
. Does nothing if there is no instance ofx
int
.
val find : t -> data -> data
find t x
returns an instance ofx
found int
. RaiseNot_found
if there is no such element.
val find_opt : t -> data -> data option
find_opt t x
returns an instance ofx
found int
orNone
if there is no such element.- since
- 4.05
val find_all : t -> data -> data list
find_all t x
returns a list of all the instances ofx
found int
.
val mem : t -> data -> bool
mem t x
returnstrue
if there is at least one instance ofx
int
, false otherwise.
val iter : (data -> unit) -> t -> unit
iter f t
callsf
on each element oft
, in some unspecified order. It is not specified what happens iff
tries to changet
itself.
val fold : (data -> 'a -> 'a) -> t -> 'a -> 'a
fold f t init
computes(f d1 (... (f dN init)))
whered1 ... dN
are the elements oft
in some unspecified order. It is not specified what happens iff
tries to changet
itself.
val count : t -> int
Count the number of elements in the table.
count t
gives the same result asfold (fun _ n -> n+1) t 0
but does not delay the deallocation of the dead elements.
val stats : t -> int * int * int * int * int * int
Return statistics on the table. The numbers are, in order: table length, number of entries, sum of bucket lengths, smallest bucket length, median bucket length, biggest bucket length.