mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-01-29 12:24:50 -05:00
bugfix in CCList.split
This commit is contained in:
parent
debf586db5
commit
609d51c89e
1 changed files with 11 additions and 23 deletions
|
|
@ -389,44 +389,32 @@ let combine_gen l1 l2 =
|
||||||
|
|
||||||
let split l =
|
let split l =
|
||||||
let rec direct i l = match l with
|
let rec direct i l = match l with
|
||||||
| [] -> ([],[])
|
| [] -> [], []
|
||||||
| [x1, y1] -> [x1], [y1]
|
| [x1, y1] -> [x1], [y1]
|
||||||
| [x1, y1; x2, y2] -> [x1;x2], [y1;y2]
|
| [x1, y1; x2, y2] -> [x1;x2], [y1;y2]
|
||||||
| [x1, y1; x2, y2; x3, y3] -> [x1;x2;x3], [y1;y2;y3]
|
| [x1, y1; x2, y2; x3, y3] -> [x1;x2;x3], [y1;y2;y3]
|
||||||
| [x1, y1; x2, y2; x3, y3; x4, y4] -> [x1;x2;x3;x4], [y1;y2;y3;y4]
|
| [x1, y1; x2, y2; x3, y3; x4, y4] -> [x1;x2;x3;x4], [y1;y2;y3;y4]
|
||||||
| _ when i=0 -> split_slow ([], []) l
|
| _ when i=0 -> split_slow [] [] l
|
||||||
| (x1, y1) ::
|
| (x1, y1) :: (x2, y2) :: (x3, y3) :: (x4, y4) :: (x5, y5) :: l' ->
|
||||||
(x2, y2) ::
|
|
||||||
(x3, y3) ::
|
|
||||||
(x4, y4) ::
|
|
||||||
(x5, y5) :: l' ->
|
|
||||||
let rx, ry = direct (i-1) l' in
|
let rx, ry = direct (i-1) l' in
|
||||||
x1 :: x2 :: x3 :: x4 :: x5 :: rx,
|
x1 :: x2 :: x3 :: x4 :: x5 :: rx,
|
||||||
y1 :: y2 :: y3 :: y4 :: y5 :: ry
|
y1 :: y2 :: y3 :: y4 :: y5 :: ry
|
||||||
and split_slow acc l = match l with
|
and split_slow acc1 acc2 l = match l with
|
||||||
| [] -> acc
|
| [] -> List.rev acc1, List.rev acc2
|
||||||
| (x1, y1) :: l' ->
|
| (x1, x2) :: tail ->
|
||||||
let acc = x1 :: fst acc, y1 :: snd acc in
|
let acc1 = x1 :: acc1
|
||||||
split_slow acc l'
|
and acc2 = x2 :: acc2 in
|
||||||
|
split_slow acc1 acc2 tail
|
||||||
in
|
in
|
||||||
direct direct_depth_default_ l
|
direct direct_depth_default_ l
|
||||||
|
|
||||||
(*$Q
|
(*$Q
|
||||||
(Q.(list (pair int string))) (fun l -> \
|
(Q.(list_of_size Gen.(0--10_000) (pair small_int small_string))) (fun l -> \
|
||||||
let (l1, l2) = split l in \
|
let (l1, l2) = split l in \
|
||||||
List.length l1 = List.length l \
|
List.length l1 = List.length l \
|
||||||
&& List.length l2 = List.length l)
|
&& List.length l2 = List.length l)
|
||||||
|
|
||||||
(Q.(list (pair string int))) (fun l -> \
|
Q.(list_of_size Gen.(0--10_000) (pair small_int small_int)) (fun l -> \
|
||||||
let l = ("hello", 10) :: l in \
|
|
||||||
let (l1, l2) = split l in \
|
|
||||||
let i = Random.int @@ List.length l in \
|
|
||||||
let l1_x = List.nth l1 i in \
|
|
||||||
let l2_y = List.nth l2 i in \
|
|
||||||
let (x,y) = List.nth l i in \
|
|
||||||
l1_x = x && l2_y = y)
|
|
||||||
|
|
||||||
Q.(list (pair int int)) (fun l -> \
|
|
||||||
split l = List.split l)
|
split l = List.split l)
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue