Skip to content

Commit 45ec437

Browse files
author
Cristiano Calcagno
committed
[Belt] More consistency in mli for Maps and Sets.
More consistency in the generated .mli for specialized Set and String, and the corresponding Dict, for maps and sets. Removed leftover mergeArray which should be mergeMany.
1 parent 1597f50 commit 45ec437

15 files changed

+574
-506
lines changed

jscomp/others/belt_MapDict.mli

Lines changed: 87 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
type ('key, 'value, 'id) t
25+
type ('key, 'value, 'id) t
2626

2727
type ('key, 'id) cmp = ('key, 'id) Belt_Id.cmp
2828

@@ -31,119 +31,140 @@ val empty: ('k, 'v, 'id) t
3131
val isEmpty: ('k, 'v, 'id) t -> bool
3232

3333
val has:
34-
('k, 'a, 'id) t -> 'k ->
35-
cmp:('k, 'id) cmp ->
36-
bool
34+
('k, 'a, 'id) t -> 'k ->
35+
cmp:('k, 'id) cmp ->
36+
bool
3737

38-
val cmpU:
39-
('k, 'v, 'id) t ->
38+
val cmpU:
39+
('k, 'v, 'id) t ->
4040
('k, 'v, 'id) t ->
4141
kcmp:('k, 'id) cmp ->
4242
vcmp:('v -> 'v -> int [@bs]) ->
4343
int
4444
val cmp:
45-
('k, 'v, 'id) t ->
45+
('k, 'v, 'id) t ->
4646
('k, 'v, 'id) t ->
4747
kcmp:('k, 'id) cmp ->
48-
vcmp:('v -> 'v -> int) ->
48+
vcmp:('v -> 'v -> int) ->
4949
int
5050

51-
val eqU:
52-
('k, 'a, 'id) t ->
51+
val eqU:
52+
('k, 'a, 'id) t ->
5353
('k, 'a, 'id) t ->
5454
kcmp:('k, 'id) cmp ->
55-
veq:('a -> 'a -> bool [@bs]) ->
55+
veq:('a -> 'a -> bool [@bs]) ->
5656
bool
57-
val eq:
58-
('k, 'a, 'id) t ->
57+
val eq:
58+
('k, 'a, 'id) t ->
5959
('k, 'a, 'id) t ->
6060
kcmp:('k, 'id) cmp ->
61-
veq:('a -> 'a -> bool) ->
61+
veq:('a -> 'a -> bool) ->
6262
bool
6363
(** [eq m1 m2 cmp] tests whether the maps [m1] and [m2] are
6464
equal, that is, contain equal keys and associate them with
6565
equal data. [cmp] is the equality predicate used to compare
6666
the data associated with the keys. *)
67-
68-
val forEachU: ('k, 'a, 'id) t -> ('k -> 'a -> unit [@bs]) -> unit
69-
val forEach: ('k, 'a, 'id) t -> ('k -> 'a -> unit) -> unit
67+
68+
val forEachU: ('k, 'a, 'id) t -> ('k -> 'a -> unit [@bs]) -> unit
69+
val forEach: ('k, 'a, 'id) t -> ('k -> 'a -> unit) -> unit
7070
(** [forEach m f] applies [f] to all bindings in map [m].
71-
[f] receives the 'k as first argument, and the associated value
72-
as second argument. The bindings are passed to [f] in increasing
71+
[f] receives the key as first argument, and the associated value
72+
as second argument. The bindings are passed to [f] in increasing
7373
order with respect to the ordering over the type of the keys. *)
74-
75-
val reduceU: ('k, 'a, 'id) t -> 'b -> ('b -> 'k -> 'a -> 'b [@bs]) -> 'b
76-
val reduce: ('k, 'a, 'id) t -> 'b -> ('b -> 'k -> 'a -> 'b) -> 'b
74+
75+
val reduceU: ('k, 'a, 'id) t -> 'b -> ('b -> 'k -> 'a -> 'b [@bs]) -> 'b
76+
val reduce: ('k, 'a, 'id) t -> 'b -> ('b -> 'k -> 'a -> 'b) -> 'b
7777
(** [reduce m a f] computes [(f kN dN ... (f k1 d1 a)...)],
7878
where [k1 ... kN] are the keys of all bindings in [m]
7979
(in increasing order), and [d1 ... dN] are the associated data. *)
8080

81-
val everyU: ('k, 'a, 'id) t -> ('k -> 'a -> bool [@bs]) -> bool
82-
val every: ('k, 'a, 'id) t -> ('k -> 'a -> bool) -> bool
81+
val everyU: ('k, 'a, 'id) t -> ('k -> 'a -> bool [@bs]) -> bool
82+
val every: ('k, 'a, 'id) t -> ('k -> 'a -> bool) -> bool
8383
(** [every m p] checks if all the bindings of the map
8484
satisfy the predicate [p]. Order unspecified *)
85-
86-
val someU: ('k, 'a, 'id) t -> ('k -> 'a -> bool [@bs]) -> bool
87-
val some: ('k, 'a, 'id) t -> ('k -> 'a -> bool) -> bool
85+
86+
val someU: ('k, 'a, 'id) t -> ('k -> 'a -> bool [@bs]) -> bool
87+
val some: ('k, 'a, 'id) t -> ('k -> 'a -> bool) -> bool
8888
(** [some m p] checks if at least one binding of the map
8989
satisfy the predicate [p]. Order unspecified *)
9090

9191
val size: ('k, 'a, 'id) t -> int
92+
9293
val toList: ('k, 'a, 'id) t -> ('k * 'a) list
93-
(** In increasing order*)
94+
(** In increasing order. *)
95+
9496
val toArray: ('k, 'a, 'id) t -> ('k * 'a) array
97+
9598
val ofArray: ('k * 'a) array -> cmp:('k,'id) cmp -> ('k,'a,'id) t
9699
[@@ocaml.deprecated "Use fromArray instead"]
100+
97101
val fromArray: ('k * 'a) array -> cmp:('k,'id) cmp -> ('k,'a,'id) t
98-
val keysToArray: ('k, 'a, 'id) t -> 'k array
99-
val valuesToArray: ('k, 'a, 'id) t -> 'a array
102+
103+
val keysToArray: ('k, 'a, 'id) t -> 'k array
104+
105+
val valuesToArray: ('k, 'a, 'id) t -> 'a array
106+
100107
val minKey: ('k, _, _) t -> 'k option
108+
101109
val minKeyUndefined: ('k, _, _) t -> 'k Js.undefined
110+
102111
val maxKey: ('k, _, _) t -> 'k option
112+
103113
val maxKeyUndefined: ('k, _, _) t -> 'k Js.undefined
104-
val minimum: ('k, 'a, _) t -> ('k * 'a) option
114+
115+
val minimum: ('k, 'a, _) t -> ('k * 'a) option
116+
105117
val minUndefined: ('k, 'a, _) t -> ('k * 'a) Js.undefined
118+
106119
val maximum: ('k, 'a, _) t -> ('k * 'a) option
120+
107121
val maxUndefined:('k, 'a, _) t -> ('k * 'a) Js.undefined
122+
108123
val get:
109124
('k, 'a, 'id) t -> 'k ->
110-
cmp:('k, 'id) cmp ->
125+
cmp:('k, 'id) cmp ->
111126
'a option
127+
112128
val getUndefined:
113129
('k, 'a, 'id) t -> 'k ->
114130
cmp:('k, 'id) cmp ->
115131
'a Js.undefined
116-
132+
117133
val getWithDefault:
118-
('k, 'a, 'id) t -> 'k -> 'a ->
134+
('k, 'a, 'id) t -> 'k -> 'a ->
119135
cmp:('k, 'id) cmp ->
120-
'a
136+
'a
137+
121138
val getExn:
122139
('k, 'a, 'id) t -> 'k ->
123140
cmp:('k, 'id) cmp ->
124141
'a
125-
142+
126143
val checkInvariantInternal: _ t -> unit
127144
(**
128145
{b raise} when invariant is not held
129-
*)
146+
*)
130147

131148
val remove:
132149
('a, 'b, 'id) t -> 'a ->
133150
cmp:('a, 'id) cmp ->
134151
('a, 'b, 'id) t
135-
152+
(** [remove m x] returns a map containing the same bindings as
153+
[m], except for [x] which is unbound in the returned map. *)
136154

137155
val removeMany:
138156
('a, 'b, 'id) t ->
139157
'a array ->
140158
cmp:('a, 'id) cmp ->
141159
('a, 'b, 'id) t
142-
160+
143161
val set:
144162
('a, 'b, 'id) t -> 'a -> 'b ->
145163
cmp:('a, 'id) cmp ->
146164
('a, 'b, 'id) t
165+
(** [add m x y] returns a map containing the same bindings as
166+
[m], plus a binding of [x] to [y]. If [x] was already bound
167+
in [m], its previous binding disappears. *)
147168

148169
val updateU:
149170
('a, 'b, 'id) t ->
@@ -160,37 +181,41 @@ val update:
160181

161182
val mergeU:
162183
('a, 'b, 'id) t ->
163-
('a, 'c, 'id) t ->
184+
('a, 'c, 'id) t ->
164185
('a -> 'b option -> 'c option -> 'd option [@bs]) ->
165186
cmp:('a, 'id) cmp -> ('a, 'd, 'id) t
166187
val merge:
167188
('a, 'b, 'id) t ->
168-
('a, 'c, 'id) t ->
189+
('a, 'c, 'id) t ->
169190
('a -> 'b option -> 'c option -> 'd option) ->
170191
cmp:('a, 'id) cmp -> ('a, 'd, 'id) t
192+
(** [merge m1 m2 f] computes a map whose keys is a subset of keys of [m1]
193+
and of [m2]. The presence of each such binding, and the corresponding
194+
value, is determined with the function [f].
195+
*)
171196

172197
val mergeMany:
173198
('a, 'b, 'id) t ->
174199
('a * 'b) array ->
175200
cmp:('a, 'id) cmp ->
176201
('a, 'b, 'id) t
177202

178-
val keepU:
179-
('k, 'a, 'id) t ->
180-
('k -> 'a -> bool [@bs]) ->
203+
val keepU:
204+
('k, 'a, 'id) t ->
205+
('k -> 'a -> bool [@bs]) ->
181206
('k, 'a, 'id) t
182-
val keep:
183-
('k, 'a, 'id) t ->
184-
('k -> 'a -> bool) ->
207+
val keep:
208+
('k, 'a, 'id) t ->
209+
('k -> 'a -> bool) ->
185210
('k, 'a, 'id) t
186211
(** [keep m p] returns the map with all the bindings in [m]
187212
that satisfy predicate [p]. *)
188-
189-
val partitionU:
213+
214+
val partitionU:
190215
('k, 'a, 'id) t ->
191-
('k -> 'a -> bool [@bs]) ->
216+
('k -> 'a -> bool [@bs]) ->
192217
('k, 'a, 'id) t * ('k, 'a, 'id) t
193-
val partition:
218+
val partition:
194219
('k, 'a, 'id) t ->
195220
('k -> 'a -> bool) ->
196221
('k, 'a, 'id) t * ('k, 'a, 'id) t
@@ -205,10 +230,17 @@ val split:
205230
'a ->
206231
cmp:('a, 'id) cmp ->
207232
(('a,'b,'id) t * ('a, 'b, 'id) t) * 'b option
208-
209-
210-
val mapU: ('k, 'a, 'id) t -> ('a -> 'b [@bs]) -> ('k ,'b,'id ) t
211-
val map: ('k, 'a, 'id) t -> ('a -> 'b) -> ('k ,'b,'id ) t
233+
(** [split x m] returns a triple [(l, data, r)], where
234+
[l] is the map with all the bindings of [m] whose key
235+
is strictly less than [x];
236+
[r] is the map with all the bindings of [m] whose key
237+
is strictly greater than [x];
238+
[data] is [None] if [m] contains no binding for [x],
239+
or [Some v] if [m] binds [v] to [x].
240+
*)
241+
242+
val mapU: ('k, 'a, 'id) t -> ('a -> 'b [@bs]) -> ('k ,'b,'id) t
243+
val map: ('k, 'a, 'id) t -> ('a -> 'b) -> ('k ,'b,'id) t
212244
(** [map m f] returns a map with same domain as [m], where the
213245
associated value [a] of all bindings of [m] has been
214246
replaced by the result of the application of [f] to [a].

jscomp/others/belt_MapInt.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
type key = int
33
module I = Belt_internalMapInt
44

5-
# 11 "map.cppo.ml"
5+
# 11
66
module N = Belt_internalAVLtree
77
module A = Belt_Array
88

@@ -140,7 +140,7 @@ let removeMany t keys =
140140
| None -> N.empty
141141
| Some t -> removeMany0 t keys 0 len
142142

143-
let mergeArray h arr =
143+
let mergeMany h arr =
144144
let len = A.length arr in
145145
let v = ref h in
146146
for i = 0 to len - 1 do

0 commit comments

Comments
 (0)