@@ -75,12 +75,12 @@ let rec _compare cmp a1 i1 j1 a2 i2 j2 =
75
75
if i1 = j1
76
76
then if i2= j2 then 0 else - 1
77
77
else if i2= j2
78
- then 1
79
- else
80
- let c = cmp a1.(i1) a2.(i2) in
81
- if c = 0
82
- then _compare cmp a1 (i1+ 1 ) j1 a2 (i2+ 1 ) j2
83
- else c
78
+ then 1
79
+ else
80
+ let c = cmp a1.(i1) a2.(i2) in
81
+ if c = 0
82
+ then _compare cmp a1 (i1+ 1 ) j1 a2 (i2+ 1 ) j2
83
+ else c
84
84
85
85
let equal eq a b =
86
86
length a = length b && _equal eq a.arr a.i a.j b.arr b.i b.j
@@ -105,8 +105,8 @@ let fold_while f acc a =
105
105
if i < Array. length a.arr && i < a.j then
106
106
let acc, cont = f acc a.arr.(i) in
107
107
match cont with
108
- | `Stop -> acc
109
- | `Continue -> fold_while_i f acc (i+ 1 )
108
+ | `Stop -> acc
109
+ | `Continue -> fold_while_i f acc (i+ 1 )
110
110
else acc
111
111
in fold_while_i f acc a.i
112
112
@@ -157,44 +157,44 @@ let rec _find f a i j =
157
157
let rec _lookup_rec ~cmp k a i j =
158
158
if i> j then raise Not_found
159
159
else if i= j
160
- then if cmp k a.(i) = 0
161
- then i
162
- else raise Not_found
160
+ then if cmp k a.(i) = 0
161
+ then i
162
+ else raise Not_found
163
163
else
164
164
let middle = (j+ i)/ 2 in
165
165
match cmp k a.(middle) with
166
- | 0 -> middle
167
- | n when n< 0 -> _lookup_rec ~cmp k a i (middle-1 )
168
- | _ -> _lookup_rec ~cmp k a (middle+ 1 ) j
166
+ | 0 -> middle
167
+ | n when n< 0 -> _lookup_rec ~cmp k a i (middle-1 )
168
+ | _ -> _lookup_rec ~cmp k a (middle+ 1 ) j
169
169
170
170
let _lookup_exn ~cmp k a i j =
171
171
if i> j then raise Not_found ;
172
172
match cmp k a.(i) with
173
- | 0 -> i
174
- | n when n< 0 -> raise Not_found (* too low *)
175
- | _ when i= j -> raise Not_found (* too high *)
176
- | _ ->
173
+ | 0 -> i
174
+ | n when n< 0 -> raise Not_found (* too low *)
175
+ | _ when i= j -> raise Not_found (* too high *)
176
+ | _ ->
177
177
match cmp k a.(j) with
178
- | 0 -> j
179
- | n when n< 0 -> _lookup_rec ~cmp k a (i+ 1 ) (j-1 )
180
- | _ -> raise Not_found (* too high *)
178
+ | 0 -> j
179
+ | n when n< 0 -> _lookup_rec ~cmp k a (i+ 1 ) (j-1 )
180
+ | _ -> raise Not_found (* too high *)
181
181
182
182
let bsearch_ ~cmp x arr i j =
183
183
let rec aux i j =
184
184
if i > j
185
- then `Just_after j
186
- else
187
- let middle = i + (j - i) / 2 in (* avoid overflow *)
188
- match cmp x arr.(middle) with
185
+ then `Just_after j
186
+ else
187
+ let middle = i + (j - i) / 2 in (* avoid overflow *)
188
+ match cmp x arr.(middle) with
189
189
| 0 -> `At middle
190
190
| n when n< 0 -> aux i (middle - 1 )
191
191
| _ -> aux (middle + 1 ) j
192
192
in
193
193
if i> = j then `Empty
194
194
else match cmp arr.(i) x, cmp arr.(j) x with
195
- | n , _ when n> 0 -> `All_bigger
196
- | _ , n when n< 0 -> `All_lower
197
- | _ -> aux i j
195
+ | n , _ when n> 0 -> `All_bigger
196
+ | _ , n when n< 0 -> `All_lower
197
+ | _ -> aux i j
198
198
199
199
let rec _for_all p a i j =
200
200
i = j || (p a.(i) && _for_all p a (i+ 1 ) j)
@@ -267,7 +267,7 @@ let rec _to_klist a i j () =
267
267
let reverse_in_place a = _reverse_in_place a.arr a.i ~len: (length a)
268
268
269
269
(* $T
270
- let a = 1--6 in let s = make a 2 ~len:3 in \
270
+ let a = 1--6 in let s = make a 2 ~len:3 in \
271
271
reverse_in_place s; a = [| 1; 2; 5; 4; 3; 6 |]
272
272
*)
273
273
@@ -343,7 +343,7 @@ let find_idx p a =
343
343
344
344
(* $=
345
345
(Some (1,"c")) (find_idx ((=) "c") (make [| "a"; "b"; "c" |] 1 2))
346
- *)
346
+ *)
347
347
348
348
let lookup_exn ?(cmp =Pervasives. compare) k a =
349
349
_lookup_exn ~cmp k a.arr a.i (a.j-1 ) - a.i
@@ -354,7 +354,7 @@ let lookup ?(cmp=Pervasives.compare) k a =
354
354
355
355
(* $=
356
356
(Some 1) (lookup "c" (make [| "a"; "b"; "c" |] 1 2))
357
- *)
357
+ *)
358
358
359
359
let bsearch ?(cmp =Pervasives. compare) k a =
360
360
match bsearch_ ~cmp k a.arr a.i (a.j - 1 ) with
@@ -373,7 +373,7 @@ let exists2 p a b =
373
373
_exists2 p a.arr b.arr a.i b.i ~len: (min (length a) (length b))
374
374
375
375
(* $T
376
- exists2 (=) (make [| 1;2;3;4 |] 1 ~len:2) (make [| 0;1;3;4 |] 1 ~len:3)
376
+ exists2 (=) (make [| 1;2;3;4 |] 1 ~len:2) (make [| 0;1;3;4 |] 1 ~len:3)
377
377
*)
378
378
379
379
let _iter2 f a b i j ~len =
0 commit comments