diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2022-04-28 21:41:58 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2022-04-28 21:41:58 +0900 |
| commit | eddac153a064648bee2aef6fb733ab6820bb96c3 (patch) | |
| tree | c12f212dc501e6053ec034d1a9f4734b8b94b4d2 /comparison/Inpla/src/msort-800000.in | |
| parent | 1c9344fa14cc018558ec9ebfbf1215a772960b6e (diff) | |
| download | inpla-eddac153a064648bee2aef6fb733ab6820bb96c3.tar.gz inpla-eddac153a064648bee2aef6fb733ab6820bb96c3.zip | |
v0.8.2
Diffstat (limited to 'comparison/Inpla/src/msort-800000.in')
| -rw-r--r-- | comparison/Inpla/src/msort-800000.in | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/comparison/Inpla/src/msort-800000.in b/comparison/Inpla/src/msort-800000.in index b77f353..3c43aa6 100644 --- a/comparison/Inpla/src/msort-800000.in +++ b/comparison/Inpla/src/msort-800000.in @@ -1,34 +1,51 @@ // Merge sort -MS(ret) >< [] => ret~[]; -MS(ret) >< x:xs => MS_tail(ret, x)~xs; +msort(ret) >< [] => ret~[]; +msort(ret) >< x:xs => msort_tail(ret, x)~xs; -MS_tail(ret, int n) >< [] => ret~[n]; -MS_tail(ret, int n) >< x:xs => - Split(left,right) ~ (n:x:xs), - MS(a)~left, MS(b)~right, Merge(ret,b)~a; +msort_tail(ret, int n) >< [] => ret~[n]; +msort_tail(ret, int n) >< x:xs => + split(left,right) ~ (n:x:xs), + msort(a)~left, msort(b)~right, merge(ret,b)~a; -Merge(ret, snd) >< [] => ret~snd; -Merge(ret, snd) >< x:xs => MergeCC(ret, x, xs)~snd; +merge(ret, snd) >< [] => ret~snd; +merge(ret, snd) >< x:xs => mergeCC(ret, x, xs)~snd; -MergeCC(ret, int y, ys) >< [] => ret~(y:ys); -MergeCC(ret, int y, ys) >< (int x):xs -| x <= y => ret~(x:cnt), MergeCC(cnt, y, ys) ~ xs -| _ => ret~(y:cnt), MergeCC(cnt, x, xs) ~ ys; +mergeCC(ret, int y, ys) >< [] => ret~(y:ys); +mergeCC(ret, int y, ys) >< (int x):xs +| x <= y => ret~(x:cnt), mergeCC(cnt, y, ys) ~ xs +| _ => ret~(y:cnt), mergeCC(cnt, x, xs) ~ ys; -Split(right,left) >< [] => right~[], left~[]; -Split(right,left) >< x:xs => - right~(x:cntl), left~cntr, Split(cntr,cntl)~xs; +split(right,left) >< [] => right~[], left~[]; +split(right,left) >< x:xs => + right~(x:cntl), left~cntr, split(cntr,cntl)~xs; +// creates a random list +make_RandList(ret) >< (int n) +| n>0 => ret~(rd:cnt), make_RandList(cnt)~(n-1) + where rd=rand(10000) +| _ => ret~[]; + + +// validation checks +valid(ret) >< [] => ret~False; +valid(ret) >< x:xs => valid_Cons(ret,x)~xs; + +valid_Cons(ret, int x) >< [] => ret~True; +valid_Cons(ret, int x) >< (int y):ys +| x<=y => valid_Cons(ret,y)~ys +| _ => ret~False, Eraser~ys; +// The `Eraser' is a built-in agent defined for any agents as follows: +//Eraser >< Alpha(a1, ..., a5) => Eraser~a1, ..., Eraser~a5; + + +// Main const LIST_ELEM=800000; -MkRandList(ret) >< (int n) -| n>0 => ret~(rd:cnt), MkRandList(cnt)~(n-1) - where rd=rand(10000) -| _ => ret~[]; +make_RandList(rndlist)~(LIST_ELEM), +msort(sorted)~rndlist, +valid(ret)~sorted; -MkRandList(cnt)~(LIST_ELEM), -MS(ret)~cnt; ret; |
