aboutsummaryrefslogtreecommitdiff
path: root/comparison/Inpla/src/msort-800000-reuse.in
blob: 5f57484a3b21a14cc46781b453608fcac49c4c1d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Merge sort
MS(ret) >< [] => ret~[];
MS(ret) >< x:xs => (*L)MS_tail(ret, x)~xs;

MS_tail(ret, int n) >< [] => ret~[n];
MS_tail(ret, int n) >< x:xs => 
	Split(left,right) ~ (*R)(n:x:xs),
	MS(a)~left, MS(b)~right, (*L)Merge(ret,b)~a;

Merge(ret, snd) >< [] => ret~snd;
Merge(ret, snd) >< x:xs => (*L)MergeCC(ret, x, xs)~snd;

MergeCC(ret, int y, ys) >< [] => ret~(*R)(y:ys);
MergeCC(ret, int y, ys) >< (int x):xs
| x <= y => ret~(x:cnt), (*L)MergeCC(cnt, y, ys) ~ xs
| _      => ret~(y:cnt), (*L)MergeCC(cnt, x, xs) ~ ys;


Split(right,left) >< [] => right~[], left~[];
Split(right,left) >< x:xs =>
	right~(*R)(x:cntl), left~cntr, (*L)Split(cntr,cntl)~xs;



const LIST_ELEM=800000;

MkRandList(ret) >< (int n)
| n>0 => ret~(rd:cnt), (*L)MkRandList(cnt)~(n-1) 
  where rd=rand(10000)
| _ => ret~[];

MkRandList(cnt)~(LIST_ELEM),
MS(ret)~cnt;
ret;