Skip to content

Commit dc95a16

Browse files
committed
Sync belt_HashSet.mli
1 parent 2e994cb commit dc95a16

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

jscomp/others/belt_HashSet.mli

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,50 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525
(**
26-
A **mutable** Hash set which allows customized [`hash`]() behavior.
26+
A **mutable** Hash set which allows customized `hash` behavior.
2727
2828
All data are parameterized by not its only type but also a unique identity in
29-
the time of initialization, so that two _HashSets of ints_ initialized with different
30-
_hash_ functions will have different type.
29+
the time of initialization, so that two _HashSets of ints_ initialized with
30+
different _hash_ functions will have different type.
3131
3232
For example:
3333
34-
```
35-
type t = int
36-
module I0 =
37-
(val Belt.Id.hashableU
38-
~hash:(fun[@bs] (a : t) -> a & 0xff_ff)
39-
~eq:(fun[@bs] a b -> a = b)
40-
)
41-
let s0 = make ~id:(module I0) ~hintSize:40
42-
module I1 =
43-
(val Belt.Id.hashableU
44-
~hash:(fun[@bs] (a : t) -> a & 0xff)
45-
~eq:(fun[@bs] a b -> a = b)
34+
```res prelude
35+
module I0 = unpack(
36+
Belt.Id.hashableU(
37+
~hash=(. a: int) => land(a, 65535),
38+
~eq=(. a, b) => a == b,
4639
)
47-
let s1 = make ~id:(module I1) ~hintSize:40
48-
```
40+
)
4941
50-
The invariant must be held: for two elements who are _equal_,
51-
their hashed value should be the same
42+
let s0 = Belt.HashSet.make(~id=module(I0), ~hintSize=40)
5243
53-
Here the compiler would infer `s0` and `s1` having different type so that
54-
it would not mix.
44+
module I1 = unpack(
45+
Belt.Id.hashableU(
46+
~hash=(. a: int) => land(a, 255),
47+
~eq=(. a, b) => a == b,
48+
)
49+
)
5550
56-
```
57-
val s0 : (int, I0.identity) t
58-
val s1 : (int, I1.identity) t
51+
let s1 = Belt.HashSet.make(~id=module(I1), ~hintSize=40)
52+
53+
Belt.HashSet.add(s1, 0)
54+
Belt.HashSet.add(s1, 1)
5955
```
6056
61-
We can add elements to the collection:
57+
The invariant must be held: for two elements who are equal, their hashed
58+
value should be the same.
6259
63-
```
64-
let () =
65-
add s1 0;
66-
add s1 1
60+
Here the compiler would infer `s0` and `s1` having different type so that it
61+
would not mix.
62+
63+
```res sig
64+
let s0: Belt.HashSet.t<int, I0.identity>
65+
let s1: Belt.HashSet.t<int, I1.identity>
6766
```
6867
69-
Since this is an mutable data strucure, `s1` will contain two pairs.
68+
We can add elements to the collection (see last two lines in the example
69+
above). Since this is an mutable data structure, `s1` will contain two pairs.
7070
*)
7171

7272

@@ -88,7 +88,6 @@ module String = Belt_HashSetString
8888
type ('a, 'id) t
8989

9090
(** The type of hash tables from type `'a` to type `'b`. *)
91-
9291
type ('a, 'id) id = ('a, 'id) Belt_Id.hashable
9392

9493
val make: hintSize:int -> id:('a,'id) id -> ('a, 'id) t

0 commit comments

Comments
 (0)