Weak.S(3) OCaml library Weak.S(3)

# [NAME](#NAME)

Weak.S - The output signature of the functor Weak.Make.

# [Module type](#Module_type)

Module type Weak.S

# [Documentation](#Documentation)

Module type **S**  
\= **sig end**

The output signature of the functor **Weak.Make** .

*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 using **output\_value** or the functions of the **Marshal** module.

*val create* : **int -&gt; t**

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

*val clear* : **t -&gt; unit**

Remove all elements from the table.

*val merge* : **t -&gt; data -&gt; data**

**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 -&gt; data -&gt; 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 -&gt; data -&gt; 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 -&gt; data -&gt; data**

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

**Raises Not\_found** if there is no such element.

*val find\_opt* : **t -&gt; data -&gt; data option**

**find\_opt t x** returns an instance of **x** found in **t** or **None** if there is no such element.

**Since** 4.05

*val find\_all* : **t -&gt; data -&gt; data list**

**find\_all t x** returns a list of all the instances of **x** found in **t** .

*val mem* : **t -&gt; data -&gt; bool**

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

*val iter* : **(data -&gt; unit) -&gt; t -&gt; 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 change **t** itself.

*val fold* : **(data -&gt; 'acc -&gt; 'acc) -&gt; t -&gt; 'acc -&gt; 'acc**

**fold f t init** computes **(f d1 (... (f dN init)))** where **d1 ... 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 -&gt; int**

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

*val stats* : **t -&gt; 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.

2026-10-01 OCamldoc

---

Document: Weak.S(3o) from ocaml 5.5.1-r1 (Chainguard OS)
Source: https://github.com/ocaml/ocaml
