bugfix in CCList.split

This commit is contained in:
Simon Cruanes 2017-07-04 16:24:54 +02:00
parent debf586db5
commit 609d51c89e

View file

@ -389,44 +389,32 @@ let combine_gen l1 l2 =
let split l =
let rec direct i l = match l with
| [] -> ([],[])
| [] -> [], []
| [x1, y1] -> [x1], [y1]
| [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; x4, y4] -> [x1;x2;x3;x4], [y1;y2;y3;y4]
| _ when i=0 -> split_slow ([], []) l
| (x1, y1) ::
(x2, y2) ::
(x3, y3) ::
(x4, y4) ::
(x5, y5) :: l' ->
| _ when i=0 -> split_slow [] [] l
| (x1, y1) :: (x2, y2) :: (x3, y3) :: (x4, y4) :: (x5, y5) :: l' ->
let rx, ry = direct (i-1) l' in
x1 :: x2 :: x3 :: x4 :: x5 :: rx,
y1 :: y2 :: y3 :: y4 :: y5 :: ry
and split_slow acc l = match l with
| [] -> acc
| (x1, y1) :: l' ->
let acc = x1 :: fst acc, y1 :: snd acc in
split_slow acc l'
and split_slow acc1 acc2 l = match l with
| [] -> List.rev acc1, List.rev acc2
| (x1, x2) :: tail ->
let acc1 = x1 :: acc1
and acc2 = x2 :: acc2 in
split_slow acc1 acc2 tail
in
direct direct_depth_default_ l
(*$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 \
List.length l1 = List.length l \
&& List.length l2 = List.length l)
(Q.(list (pair string 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 -> \
Q.(list_of_size Gen.(0--10_000) (pair small_int small_int)) (fun l -> \
split l = List.split l)
*)