comparison src/main/java/alice/test/codesegment/local/bitonicsort/SortPhase.java @ 345:8f71c3e6f11d

Change directory structure Maven standard
author sugi
date Wed, 16 Apr 2014 18:26:07 +0900
parents
children
comparison
equal deleted inserted replaced
344:9f97ec18f8c5 345:8f71c3e6f11d
1 package alice.test.codesegment.local.bitonicsort;
2
3 import alice.codesegment.CodeSegment;
4 import alice.datasegment.CommandType;
5 import alice.datasegment.Receiver;
6
7 public class SortPhase extends CodeSegment{
8 private Receiver info0 = ids.create(CommandType.PEEK); // range
9 private Receiver info1 = ids.create(CommandType.TAKE); // Array1
10 private Receiver info2 = ids.create(CommandType.TAKE); // Array2
11 private Receiver info3 = ids.create(CommandType.PEEK); // sort_count
12 private Receiver info4 = ids.create(CommandType.TAKE); // count
13
14
15 public SortPhase(String key0, String key1, String key2, int index, String key4){
16 info0.setKey(key0);
17 info1.setKey(key1,index);
18 info2.setKey(key2,index);
19 info3.setKey("sort_count");
20 info4.setKey(key4);
21 }
22
23 @Override
24 public void run() {
25 RangeInfo info = info0.asClass(RangeInfo.class);
26 DataList list1 = info1.asClass(DataList.class);
27 DataList list2 = info2.asClass(DataList.class);
28 int sort_count = info3.asInteger();
29 int count = info4.asInteger();
30
31 int i = info.range;
32 //System.out.println("CS"+i+" "+info1.key+" "+info2.key+" dataIndex "+info1.index +" count "+count);
33 Sort.quickSort(list1);
34 Sort.quickSort(list2);
35 DataList.merge(list1,list2);
36
37 if (count%2==0&&i==0){
38 ods.flip(info1); // first block index is less than others. So put data twice.
39 } else if (count%2==0&&info.lastFlag){
40 ods.flip(info2); // Same reason
41 }
42
43 ods.flip(info1);
44 ods.flip(info2);
45
46 if (count%2==0&&info.lastFlag&&count+2<sort_count/2){
47 new SortPhase(info0.key, info1.key, info2.key,count+2,info4.key);
48 ods.update(info4.key, count+2);
49 } else {
50 String f = (count%2==1) ? SetInfo.array[2*i] : SetInfo.array[2*i+1];
51 String b = (count%2==1) ? SetInfo.array[2*i+1] : SetInfo.array[2*i+2];
52
53 new SortPhase(info0.key, f, b, count+1, info4.key);
54 ods.update(info4.key, count+1);
55 }
56
57
58 }
59
60 }