Skip to content

Commit 215f9f6

Browse files
committed
make API more consistent
1 parent 0e22703 commit 215f9f6

26 files changed

+737
-643
lines changed

jscomp/others/bs_Map.ml

+12-8
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ let rec merge0 s1 s2 f ~cmp =
172172

173173

174174

175-
let ofArray (type k) (type id) (dict : (k,id) Bs_Cmp.t) data =
175+
let ofArray (type k) (type id) data ~(dict : (k,id) Bs_Cmp.t) =
176176
let module M = (val dict ) in
177177
B.bag ~dict ~data:(N.ofArray0 ~cmp:M.cmp data)
178178

@@ -213,13 +213,13 @@ let merge (type k) (type id) (s1 : (k,_,id) t)
213213
B.bag ~data:(merge0 ~cmp:X.cmp s1_data s2_data f)
214214
~dict
215215

216-
let empty dict =
216+
let empty ~dict =
217217
B.bag ~dict ~data:N.empty0
218218

219219
let isEmpty map =
220220
N.isEmpty0 (B.data map)
221221

222-
let singleton dict k v =
222+
let singleton k v ~dict =
223223
B.bag ~dict ~data:(N.singleton0 k v)
224224

225225
let cmp (type k) (type id) (m1 : (k,'v,id) t) (m2 : (k,'v,id) t) cmp
@@ -270,10 +270,14 @@ let keysToArray m =
270270
let valuesToArray m =
271271
N.valuesToArray0 (B.data m)
272272

273-
let minKVOpt m = N.minKVOpt0 (B.data m)
274-
let minKVNull m = N.minKVNull0 (B.data m)
275-
let maxKVOpt m = N.maxKVOpt0 (B.data m)
276-
let maxKVNull m = N.maxKVNull0 (B.data m)
273+
let minKeyOpt m = N.minKeyOpt0 (B.data m)
274+
let minKeyNull m = N.minKeyNull0 (B.data m)
275+
let maxKeyOpt m = N.maxKeyOpt0 (B.data m)
276+
let maxKeyNull m = N.maxKeyNull0 (B.data m)
277+
let minKeyValueOpt m = N.minKVOpt0 (B.data m)
278+
let minKeyValueNull m = N.minKVNull0 (B.data m)
279+
let maxKeyValueOpt m = N.maxKVOpt0 (B.data m)
280+
let maxKeyValueNull m = N.maxKVNull0 (B.data m)
277281

278282
let findOpt (type k) (type id) (map : (k,_,id) t) x =
279283
let dict,map = B.(dict map, data map) in
@@ -331,4 +335,4 @@ let mapi0 = N.mapi0
331335
let map0 = N.map0
332336

333337
let filter0 = N.filterShared0
334-
let partition0 = N.partitionShared0
338+
let partition0 = N.partitionShared0

jscomp/others/bs_Map.mli

+52-64
Original file line numberDiff line numberDiff line change
@@ -47,57 +47,15 @@ type ('k,'v,'id) t =
4747
(* should not export [Bs_Cmp.compare].
4848
should only export [Bs_Cmp.t] or [Bs_Cmp.cmp] instead *)
4949

50-
51-
52-
53-
val empty: ('k, 'id) Bs_Cmp.t -> ('k, 'a, 'id) t
54-
55-
val ofArray:
56-
('k,'id) Bs_Cmp.t ->
57-
('k * 'a) array ->
58-
('k,'a,'id) t
59-
50+
val empty: dict:('k, 'id) Bs_Cmp.t -> ('k, 'a, 'id) t
6051
val isEmpty: _ t -> bool
61-
val mem:
62-
('k, 'a, 'id) t -> 'k -> bool
63-
64-
val update:
65-
('k, 'a, 'id) t -> 'k -> 'a -> ('k, 'a, 'id) t
66-
(** [update m x y ] returns a map containing the same bindings as
67-
[m], with a new binding of [x] to [y]. If [x] was already bound
68-
in [m], its previous binding disappears. *)
69-
val updateArray:
70-
('k, 'a, 'id) t -> ('k * 'a) array -> ('k, 'a, 'id) t
71-
val updateWithOpt:
72-
('k, 'a, 'id) t ->
73-
'k ->
74-
('k option -> 'a option [@bs]) ->
75-
('k, 'a, 'id) t
76-
77-
val singleton:
78-
('k,'id) Bs_Cmp.t ->
79-
'k -> 'a -> ('k, 'a, 'id) t
80-
81-
val remove: ('k, 'a, 'id) t -> 'k -> ('k, 'a, 'id) t
82-
(** [remove m x] when [x] is not in [m], [m] is returned reference unchanged *)
83-
84-
val merge:
85-
('k, 'a, 'id ) t ->
86-
('k, 'b,'id) t ->
87-
('k -> 'a option -> 'b option -> 'c option [@bs]) ->
88-
('k, 'c,'id) t
89-
(** [merge m1 m2 f] computes a map whose keys is a subset of keys of [m1]
90-
and of [m2]. The presence of each such binding, and the corresponding
91-
value, is determined with the function [f].
92-
*)
93-
52+
val singleton: 'k -> 'a -> dict:('k,'id) Bs_Cmp.t -> ('k, 'a, 'id) t
53+
val mem: ('k, 'a, 'id) t -> 'k -> bool
9454
val cmp:
9555
('k, 'v, 'id) t ->
9656
('k, 'v, 'id) t ->
9757
('v -> 'v -> int [@bs]) ->
9858
int
99-
100-
10159
val eq:
10260
('k, 'a, 'id) t ->
10361
('k, 'a, 'id) t ->
@@ -127,6 +85,55 @@ val exists: ('k, 'a, 'id) t -> ('k -> 'a -> bool [@bs]) -> bool
12785
(** [exists m p] checks if at least one binding of the map
12886
satisfy the predicate [p]. Order unspecified *)
12987

88+
val length: ('k, 'a, 'id) t -> int
89+
val toList: ('k, 'a, 'id) t -> ('k * 'a) list
90+
(** In increasing order*)
91+
val toArray: ('k, 'a, 'id) t -> ('k * 'a) array
92+
val ofArray: ('k * 'a) array -> dict:('k,'id) Bs_Cmp.t -> ('k,'a,'id) t
93+
val keysToArray: ('k, 'a, 'id) t -> 'k array
94+
val valuesToArray: ('k, 'a, 'id) t -> 'a array
95+
val minKeyOpt: ('k, _, _) t -> 'k option
96+
val minKeyNull: ('k, _, _) t -> 'k Js.null
97+
val maxKeyOpt: ('k, _, _) t -> 'k option
98+
val maxKeyNull: ('k, _, _) t -> 'k Js.null
99+
val minKeyValueOpt: ('k, 'a, _) t -> ('k * 'a) option
100+
val minKeyValueNull: ('k, 'a, _) t -> ('k * 'a) Js.null
101+
val maxKeyValueOpt: ('k, 'a, _) t -> ('k * 'a) option
102+
val maxKeyValueNull:('k, 'a, _) t -> ('k * 'a) Js.null
103+
val findOpt: ('k, 'a, 'id) t -> 'k -> 'a option
104+
val findNull: ('k, 'a, 'id) t -> 'k -> 'a Js.null
105+
val findWithDefault:
106+
('k, 'a, 'id) t -> 'k -> 'a -> 'a
107+
val findExn: ('k, 'a, 'id) t -> 'k -> 'a
108+
109+
(****************************************************************************)
110+
111+
val update:
112+
('k, 'a, 'id) t -> 'k -> 'a -> ('k, 'a, 'id) t
113+
(** [update m x y ] returns a map containing the same bindings as
114+
[m], with a new binding of [x] to [y]. If [x] was already bound
115+
in [m], its previous binding disappears. *)
116+
val updateArray:
117+
('k, 'a, 'id) t -> ('k * 'a) array -> ('k, 'a, 'id) t
118+
val updateWithOpt:
119+
('k, 'a, 'id) t ->
120+
'k ->
121+
('k option -> 'a option [@bs]) ->
122+
('k, 'a, 'id) t
123+
124+
val remove: ('k, 'a, 'id) t -> 'k -> ('k, 'a, 'id) t
125+
(** [remove m x] when [x] is not in [m], [m] is returned reference unchanged *)
126+
127+
val merge:
128+
('k, 'a, 'id ) t ->
129+
('k, 'b,'id) t ->
130+
('k -> 'a option -> 'b option -> 'c option [@bs]) ->
131+
('k, 'c,'id) t
132+
(** [merge m1 m2 f] computes a map whose keys is a subset of keys of [m1]
133+
and of [m2]. The presence of each such binding, and the corresponding
134+
value, is determined with the function [f].
135+
*)
136+
130137
val filter:
131138
('k, 'a, 'id) t ->
132139
('k -> 'a -> bool [@bs]) ->
@@ -144,20 +151,6 @@ val partition:
144151
[s] that do not satisfy [p].
145152
*)
146153

147-
val length: ('k, 'a, 'id) t -> int
148-
149-
150-
val toList: ('k, 'a, 'id) t -> ('k * 'a) list
151-
(** In increasing order*)
152-
val toArray : ('k, 'a, 'id) t -> ('k * 'a) array
153-
val keysToArray : ('k, 'a, 'id) t -> 'k array
154-
val valuesToArray : ('k, 'a, 'id) t -> 'a array
155-
156-
val minKVOpt: ('k, 'a, _) t -> ('k * 'a) option
157-
val minKVNull: ('k, 'a, _) t -> ('k * 'a) Js.null
158-
val maxKVOpt: ('k, 'a, _) t -> ('k * 'a) option
159-
val maxKVNull:('k, 'a, _) t -> ('k * 'a) Js.null
160-
161154
val split:
162155
('k, 'a, 'id) t -> 'k ->
163156
(('k, 'a, 'id) t * ('k, 'a, 'id) t )* 'a option
@@ -170,11 +163,6 @@ val split:
170163
or [Some v] if [m] binds [v] to [x].
171164
*)
172165

173-
val findOpt: ('k, 'a, 'id) t -> 'k -> 'a option
174-
val findNull: ('k, 'a, 'id) t -> 'k -> 'a Js.null
175-
val findWithDefault:
176-
('k, 'a, 'id) t -> 'k -> 'a -> 'a
177-
val findExn: ('k, 'a, 'id) t -> 'k -> 'a
178166
val map: ('k, 'a, 'id) t -> ('a -> 'b [@bs]) -> ('k ,'b,'id ) t
179167
(** [map m f] returns a map with same domain as [m], where the
180168
associated value [a] of all bindings of [m] has been

jscomp/others/bs_MapInt.ml

+13-5
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ type 'a t = (key, 'a) N.t0
1212
let empty = N.empty0
1313
let isEmpty = N.isEmpty0
1414
let singleton = N.singleton0
15-
let minKVOpt = N.minKVOpt0
16-
let minKVNull = N.minKVNull0
17-
let maxKVOpt = N.maxKVOpt0
18-
let maxKVNull = N.maxKVNull0
15+
16+
let minKeyOpt = N.minKeyOpt0
17+
let minKeyNull = N.minKeyNull0
18+
let maxKeyOpt = N.maxKeyOpt0
19+
let maxKeyNull = N.maxKeyNull0
20+
let minKeyValueOpt = N.minKVOpt0
21+
let minKeyValueNull = N.minKVNull0
22+
let maxKeyValueOpt = N.maxKVOpt0
23+
let maxKeyValueNull = N.maxKVNull0
1924
let iter = N.iter0
2025
let map = N.map0
2126
let mapi = N.mapi0
@@ -26,6 +31,9 @@ let filter = N.filterShared0
2631
let partition = N.partitionShared0
2732
let length = N.length0
2833
let toList = N.toList0
34+
let toArray = N.toArray0
35+
let keysToArray = N.keysToArray0
36+
let valuesToArray = N.valuesToArray0
2937
let checkInvariant = N.checkInvariant
3038

3139
let rec update t (newK : key) (newD : _) =
@@ -92,4 +100,4 @@ let findWithDefault = I.findWithDefault
92100
let findExn = I.findExn
93101
let split = I.split
94102
let merge = I.merge
95-
let ofArray = I.ofArray
103+
let ofArray = I.ofArray

jscomp/others/bs_MapInt.mli

+48-49
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,9 @@ type 'a t
55
(** The type of maps from type [key] to type ['a]. *)
66

77
val empty: 'a t
8-
9-
val ofArray: (key * 'a) array -> 'a t
10-
118
val isEmpty: 'a t -> bool
12-
13-
val mem: 'a t -> key -> bool
14-
15-
val update: 'a t -> key -> 'a -> 'a t
16-
(** [add m x y] returns a map containing the same bindings as
17-
[m], plus a binding of [x] to [y]. If [x] was already bound
18-
in [m], its previous binding disappears. *)
19-
val updateWithOpt:
20-
'a t ->
21-
key ->
22-
(key option -> 'a option [@bs]) ->
23-
'a t
24-
259
val singleton: key -> 'a -> 'a t
26-
27-
val remove: 'a t -> key -> 'a t
28-
(** [remove m x] returns a map containing the same bindings as
29-
[m], except for [x] which is unbound in the returned map. *)
30-
31-
val merge:
32-
'a t -> 'b t ->
33-
(key -> 'a option -> 'b option -> 'c option [@bs]) ->
34-
'c t
35-
(** [merge m1 m2 f] computes a map whose keys is a subset of keys of [m1]
36-
and of [m2]. The presence of each such binding, and the corresponding
37-
value, is determined with the function [f].
38-
*)
39-
10+
val mem: 'a t -> key -> bool
4011
val cmp: 'a t -> 'a t -> ('a -> 'a -> int [@bs]) -> int
4112

4213
val eq: 'a t -> 'a t -> ('a -> 'a -> bool [@bs]) -> bool
@@ -65,6 +36,52 @@ val exists: 'a t -> (key -> 'a -> bool [@bs]) -> bool
6536
(** [exists m p] checks if at least one binding of the map
6637
satisfy the predicate [p].
6738
*)
39+
val length: 'a t -> int
40+
val toList: 'a t -> (key * 'a) list
41+
(** In increasing order with respect *)
42+
val toArray: 'a t -> (key * 'a) array
43+
val ofArray: (key * 'a) array -> 'a t
44+
val keysToArray: 'a t -> key array
45+
val valuesToArray: 'a t -> 'a array
46+
val minKeyOpt: _ t -> key option
47+
val minKeyNull: _ t -> key Js.null
48+
val maxKeyOpt: _ t -> key option
49+
val maxKeyNull: _ t -> key Js.null
50+
val minKeyValueOpt: 'a t -> (key * 'a) option
51+
val minKeyValueNull: 'a t -> (key * 'a) Js.null
52+
val maxKeyValueOpt: 'a t -> (key * 'a) option
53+
val maxKeyValueNull: 'a t -> (key * 'a) Js.null
54+
val findOpt: 'a t -> key -> 'a option
55+
val findNull: 'a t -> key -> 'a Js.null
56+
val findWithDefault: 'a t -> key -> 'a -> 'a
57+
val findExn: 'a t -> key -> 'a
58+
59+
(****************************************************************************)
60+
61+
val update: 'a t -> key -> 'a -> 'a t
62+
(** [add m x y] returns a map containing the same bindings as
63+
[m], plus a binding of [x] to [y]. If [x] was already bound
64+
in [m], its previous binding disappears. *)
65+
val updateWithOpt:
66+
'a t ->
67+
key ->
68+
(key option -> 'a option [@bs]) ->
69+
'a t
70+
71+
72+
val remove: 'a t -> key -> 'a t
73+
(** [remove m x] returns a map containing the same bindings as
74+
[m], except for [x] which is unbound in the returned map. *)
75+
76+
77+
val merge:
78+
'a t -> 'b t ->
79+
(key -> 'a option -> 'b option -> 'c option [@bs]) ->
80+
'c t
81+
(** [merge m1 m2 f] computes a map whose keys is a subset of keys of [m1]
82+
and of [m2]. The presence of each such binding, and the corresponding
83+
value, is determined with the function [f].
84+
*)
6885

6986
val filter:
7087
'a t ->
@@ -84,20 +101,6 @@ val partition:
84101
[s] that do not satisfy [p].
85102
*)
86103

87-
val length: 'a t -> int
88-
89-
90-
val toList: 'a t -> (key * 'a) list
91-
(** Return the list of all bindings of the given map.
92-
The returned list is sorted in increasing order with respect
93-
to the ordering [Ord.compare], where [Ord] is the argument
94-
given to {!Map.Make}.
95-
*)
96-
97-
val minKVOpt: 'a t -> (key * 'a) option
98-
val minKVNull: 'a t -> (key * 'a) Js.null
99-
val maxKVOpt: 'a t -> (key * 'a) option
100-
val maxKVNull: 'a t -> (key * 'a) Js.null
101104

102105

103106

@@ -112,10 +115,6 @@ val split: key -> 'a t -> 'a t * 'a option * 'a t
112115
or [Some v] if [m] binds [v] to [x].
113116
*)
114117

115-
val findOpt: 'a t -> key -> 'a option
116-
val findNull: 'a t -> key -> 'a Js.null
117-
val findWithDefault: 'a t -> key -> 'a -> 'a
118-
val findExn: 'a t -> key -> 'a
119118

120119
val map: 'a t -> ('a -> 'b [@bs]) -> 'b t
121120
(** [map m f] returns a map with same domain as [m], where the
@@ -127,4 +126,4 @@ val map: 'a t -> ('a -> 'b [@bs]) -> 'b t
127126
val mapi: 'a t -> (key -> 'a -> 'b [@bs]) -> 'b t
128127

129128

130-
val checkInvariant : _ t -> bool
129+
val checkInvariant : _ t -> bool

0 commit comments

Comments
 (0)