Skip to content

Commit 46692a2

Browse files
committed
clean up argument order
1 parent 75a9248 commit 46692a2

21 files changed

+402
-409
lines changed

jscomp/others/bs_Map.ml

+31-31
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let partition0 = N.partition0
3838
let length0 = N.length0
3939
let toList0 = N.toList0
4040

41-
let rec add0 ~cmp x data (t : _ t0) =
41+
let rec add0 (t : _ t0) x data ~cmp =
4242
match N.toOpt t with (* TODO: test case with the same key *)
4343
None ->
4444
N.(return @@ node ~left:empty ~key:x ~value:data ~right:empty ~h:1)
@@ -48,41 +48,41 @@ let rec add0 ~cmp x data (t : _ t0) =
4848
if c = 0 then
4949
N.(return @@ node ~left:l ~key:x ~value:data ~right:r ~h:(h n))
5050
else if c < 0 then
51-
N.(bal (add0 ~cmp x data l) k v r)
51+
N.(bal (add0 ~cmp l x data ) k v r)
5252
else
53-
N.(bal l k v (add0 ~cmp x data r))
53+
N.(bal l k v (add0 ~cmp r x data ))
5454

55-
let rec findOpt0 ~cmp x n =
55+
let rec findOpt0 n x ~cmp =
5656
match N.toOpt n with
5757
None -> None
5858
| Some n (* Node(l, v, d, r, _) *) ->
5959
let v = N.key n in
6060
let c = (Bs_Cmp.getCmp cmp) x v [@bs] in
6161
if c = 0 then Some (N.value n)
62-
else findOpt0 ~cmp x (if c < 0 then N.left n else N.right n)
62+
else findOpt0 ~cmp (if c < 0 then N.left n else N.right n) x
6363

64-
let rec findAssert0 ~cmp x n =
64+
let rec findAssert0 n x ~cmp =
6565
match N.toOpt n with
6666
| None ->
6767
[%assert "Not_found"]
6868
| Some n (* Node(l, v, d, r, _)*) ->
6969
let v = N.key n in
7070
let c = (Bs_Cmp.getCmp cmp) x v [@bs] in
7171
if c = 0 then N.value n
72-
else findAssert0 ~cmp x (if c < 0 then N.left n else N.right n)
72+
else findAssert0 ~cmp (if c < 0 then N.left n else N.right n) x
7373

74-
let rec findWithDefault0 ~cmp ~def x n =
74+
let rec findWithDefault0 n x def ~cmp =
7575
match N.toOpt n with
7676
None ->
7777
def
7878
| Some n (* Node(l, v, d, r, _)*) ->
7979
let v = N.key n in
8080
let c = (Bs_Cmp.getCmp cmp) x v [@bs] in
8181
if c = 0 then N.value n
82-
else findWithDefault0 ~cmp ~def x (if c < 0 then N.left n else N.right n)
82+
else findWithDefault0 ~cmp (if c < 0 then N.left n else N.right n) x def
8383

8484

85-
let rec mem0 ~cmp x n =
85+
let rec mem0 x n ~cmp =
8686
match N.toOpt n with
8787
None ->
8888
false
@@ -92,7 +92,7 @@ let rec mem0 ~cmp x n =
9292
c = 0 || mem0 ~cmp x (if c < 0 then N.left n else N.right n)
9393

9494

95-
let rec remove0 ~cmp x n =
95+
let rec remove0 n x ~cmp =
9696
match N.toOpt n with
9797
None ->
9898
n
@@ -108,9 +108,9 @@ let rec remove0 ~cmp x n =
108108
let r = N.removeMinAuxWithRef rn kr vr in
109109
N.bal l !kr !vr r
110110
else if c < 0 then
111-
N.(bal (remove0 ~cmp x l) v (value n) r)
111+
N.(bal (remove0 ~cmp l x ) v (value n) r)
112112
else
113-
N.(bal l v (value n) (remove0 ~cmp x r))
113+
N.(bal l v (value n) (remove0 ~cmp r x ))
114114

115115
let rec splitAux ~cmp x (n : _ N.node) : _ t0 * _ option * _ t0 =
116116
let l,v,d,r = N.(left n , key n, value n, right n) in
@@ -138,17 +138,17 @@ let split0 ~cmp x n =
138138
| Some n (* Node(l, v, d, r, _) *) ->
139139
splitAux ~cmp x n
140140

141-
let rec merge0 ~cmp f s1 s2 =
141+
let rec merge0 s1 s2 f ~cmp =
142142
match N.(toOpt s1, toOpt s2) with
143143
(None, None) -> N.empty
144144
| Some n (* (Node (l1, v1, d1, r1, h1), _) *), _ when N.h n >= N.height s2 ->
145145
let l1, v1, d1, r1 = N.(left n, key n, value n, right n) in
146146
let (l2, d2, r2) = split0 ~cmp v1 s2 in
147-
N.concatOrJoin (merge0 ~cmp f l1 l2) v1 (f v1 (Some d1) d2 [@bs]) (merge0 ~cmp f r1 r2)
147+
N.concatOrJoin (merge0 ~cmp l1 l2 f) v1 (f v1 (Some d1) d2 [@bs]) (merge0 ~cmp r1 r2 f)
148148
| _, Some n (* Node (l2, v2, d2, r2, h2)*) ->
149149
let l2,v2,d2,r2 = N.(left n, key n, value n, right n) in
150150
let (l1, d1, r1) = split0 ~cmp v2 s1 in
151-
N.concatOrJoin (merge0 ~cmp f l1 l2) v2 (f v2 d1 (Some d2) [@bs]) (merge0 ~cmp f r1 r2)
151+
N.concatOrJoin (merge0 ~cmp l1 l2 f) v2 (f v2 d1 (Some d2) [@bs]) (merge0 ~cmp r1 r2 f)
152152
| _ ->
153153
assert false
154154

@@ -194,7 +194,7 @@ let ofArray0 ~cmp (xs : _ array) : _ t0 =
194194
let result = ref N.empty in
195195
for i = 0 to Array.length xs - 1 do
196196
let k, v = (Bs_Array.unsafe_get xs i) in
197-
result := add0 ~cmp k v !result
197+
result := add0 ~cmp !result k v
198198
done ;
199199
!result
200200

@@ -253,10 +253,10 @@ let mapi map f =
253253

254254

255255

256-
let add (type k) (type v) (type id) key data (map : (k,v,id) t) =
256+
let add (type k) (type v) (type id) (map : (k,v,id) t) key data =
257257
let dict,map = B.(dict map, data map) in
258258
let module X = (val dict) in
259-
B.bag ~dict ~data:(add0 ~cmp:X.cmp key data map)
259+
B.bag ~dict ~data:(add0 ~cmp:X.cmp map key data )
260260

261261

262262
let ofArray (type k) (type v) (type id) (dict : (k,id) Bs_Cmp.t) data =
@@ -267,31 +267,31 @@ let ofArray (type k) (type v) (type id) (dict : (k,id) Bs_Cmp.t) data =
267267

268268

269269

270-
let findOpt (type k) (type v) (type id) x (map : (k,v,id) t) =
270+
let findOpt (type k) (type v) (type id) (map : (k,v,id) t) x =
271271
let dict,map = B.(dict map, data map) in
272272
let module X = (val dict) in
273-
findOpt0 ~cmp:X.cmp x map
273+
findOpt0 ~cmp:X.cmp map x
274274

275-
let findAssert (type k) (type v) (type id) x (map : (k,v,id) t) =
275+
let findAssert (type k) (type v) (type id) (map : (k,v,id) t) x =
276276
let dict,map = B.(dict map, data map) in
277277
let module X = (val dict) in
278-
findAssert0 ~cmp:X.cmp x map
278+
findAssert0 ~cmp:X.cmp map x
279279

280-
let findWithDefault (type k) (type v) (type id) ~def x (map : (k,v,id) t) =
280+
let findWithDefault (type k) (type v) (type id) (map : (k,v,id) t) x def =
281281
let dict,map = B.(dict map, data map) in
282282
let module X = (val dict) in
283-
findWithDefault0 ~cmp:X.cmp ~def x map
283+
findWithDefault0 ~cmp:X.cmp map x def
284284

285285

286-
let mem (type k) (type v) (type id) x (map : (k,v,id) t) =
286+
let mem (type k) (type v) (type id) (map : (k,v,id) t) x =
287287
let dict,map = B.(dict map, data map) in
288288
let module X = (val dict) in
289289
mem0 ~cmp:X.cmp x map
290290

291-
let remove (type k) (type v) (type id) x (map : (k,v,id) t) =
291+
let remove (type k) (type v) (type id) (map : (k,v,id) t) x =
292292
let dict,map = B.(dict map, data map) in
293293
let module X = (val dict) in
294-
B.bag ~dict ~data:(remove0 ~cmp:X.cmp x map)
294+
B.bag ~dict ~data:(remove0 ~cmp:X.cmp map x )
295295

296296
let split (type k) (type v) (type id) x (map : (k,v,id) t) =
297297
let dict,map = B.(dict map, data map) in
@@ -306,11 +306,11 @@ let split (type k) (type v) (type id) x (map : (k,v,id) t) =
306306
~data:r
307307

308308

309-
let merge (type k) (type v) (type id) f (s1 : (k,v,id) t)
310-
(s2 : (k,_,id) t) =
309+
let merge (type k) (type v) (type id) (s1 : (k,v,id) t)
310+
(s2 : (k,_,id) t) f =
311311
let dict, s1_data, s2_data = B.(dict s1, data s1, data s2) in
312312
let module X = (val dict) in
313-
B.bag ~data:(merge0 ~cmp:X.cmp f s1_data s2_data )
313+
B.bag ~data:(merge0 ~cmp:X.cmp s1_data s2_data f)
314314
~dict
315315

316316

0 commit comments

Comments
 (0)