OCaml library : Weak.Make (original) (raw)

Functor Weak.Make

module Make:

Functor building an implementation of the weak hash set structure.H.equal can't be the physical equality, since only shallow copies of the elements in the set are given to it.


type ``data

The type of the elements stored in the table.

type ``t

The type of tables that contain elements of type data. Note that weak hash sets cannot be marshaled usingoutput_value or the functions of the Marshal module.

val create : int -> [t](Weak.S.html#TYPEt)

create n creates a new empty weak hash set, of initial size n. The table will grow as needed.

val clear : [t](Weak.S.html#TYPEt) -> unit

Remove all elements from the table.

val merge : [t](Weak.S.html#TYPEt) -> [data](Weak.S.html#TYPEdata) -> [data](Weak.S.html#TYPEdata)

merge t x returns an instance of x found in t if any, or else adds x to t and return x.

val add : [t](Weak.S.html#TYPEt) -> [data](Weak.S.html#TYPEdata) -> unit

add t x adds x to t. If there is already an instance of x in t, it is unspecified which one will be returned by subsequent calls to find and merge.

val remove : [t](Weak.S.html#TYPEt) -> [data](Weak.S.html#TYPEdata) -> unit

remove t x removes from t one instance of x. Does nothing if there is no instance of x in t.

val find : [t](Weak.S.html#TYPEt) -> [data](Weak.S.html#TYPEdata) -> [data](Weak.S.html#TYPEdata)

find t x returns an instance of x found in t.

val find_opt : [t](Weak.S.html#TYPEt) -> [data](Weak.S.html#TYPEdata) -> [data](Weak.S.html#TYPEdata) option

find_opt t x returns an instance of x found in t or None if there is no such element.

val find_all : [t](Weak.S.html#TYPEt) -> [data](Weak.S.html#TYPEdata) -> [data](Weak.S.html#TYPEdata) list

find_all t x returns a list of all the instances of x found in t.

val mem : [t](Weak.S.html#TYPEt) -> [data](Weak.S.html#TYPEdata) -> bool

mem t x returns true if there is at least one instance of x in t, false otherwise.

val iter : ([data](Weak.S.html#TYPEdata) -> unit) -> [t](Weak.S.html#TYPEt) -> unit

iter f t calls f on each element of t, in some unspecified order. It is not specified what happens if f tries to changet itself.

val fold : ([data](Weak.S.html#TYPEdata) -> 'acc -> 'acc) -> [t](Weak.S.html#TYPEt) -> 'acc -> 'acc

fold f t init computes (f d1 (... (f dN init))) whered1 ... dN are the elements of t in some unspecified order. It is not specified what happens if f tries to change t itself.

val count : [t](Weak.S.html#TYPEt) -> int

Count the number of elements in the table. count t gives the same result as fold (fun _ n -> n+1) t 0 but does not delay the deallocation of the dead elements.

val stats : [t](Weak.S.html#TYPEt) -> 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.