changeset 234:2cc9f1e0cb43

refactor and add comment
author sugi
date Fri, 29 Mar 2013 18:53:55 +0900
parents bc451bb72d5a
children 4dc2f09a8f7a
files src/alice/test/codesegment/local/bitonicsort/OddPhase.java src/alice/test/codesegment/local/bitonicsort/SetInfo.java src/alice/test/codesegment/local/bitonicsort/SetTask.java src/alice/test/codesegment/local/bitonicsort/SortPhase.java
diffstat 4 files changed, 66 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/src/alice/test/codesegment/local/bitonicsort/OddPhase.java	Fri Mar 29 18:33:11 2013 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-package alice.test.codesegment.local.bitonicsort;
-
-import alice.codesegment.CodeSegment;
-import alice.datasegment.CommandType;
-import alice.datasegment.Receiver;
-
-public class OddPhase extends CodeSegment{
-	private Receiver info0 = ids.create(CommandType.PEEK); // range
-	private Receiver info1; 							   // Array1
-	private Receiver info2; 							   // Array2
-	private Receiver info3 = ids.create(CommandType.PEEK); // block_num
-	//private Receiver info4 = ids.create(CommandType.PEEK); // last_block_num
-	private Receiver info5 = ids.create(CommandType.PEEK); // sort_count
-	private Receiver info6 = ids.create(CommandType.TAKE); // count
-	
-	
-	public OddPhase(String key0,String key1,String key2,int index,String key6){
-		info0.setKey(key0);
-		info1 = ids.create(CommandType.TAKE);
-		info1.setKey(key1,index);
-		info2 = ids.create(CommandType.TAKE);
-		info2.setKey(key2,index);
-		info3.setKey("block_num");
-		info5.setKey("sort_count");
-		info6.setKey(key6);
-	}
-	
-	@Override
-	public void run() {
-		RangeInfo info = info0.asClass(RangeInfo.class);
-		DataList list1 = info1.asClass(DataList.class);
-		DataList list2 = info2.asClass(DataList.class);
-		int sort_count = info5.asInteger();
-		int count = info6.asInteger();
-		
-		int i = info.range;
-		//System.out.println("CS"+i+" "+info1.key+" "+info2.key+" dataIndex "+info1.index +" count "+count);
-		Sort.quickSort(list1);
-		Sort.quickSort(list2);
-		DataList.merge(list1,list2);
-		
-		if (count%2==0&&i==0){
-			ods.flip(info1);
-		} else if (count%2==0&&info.lastFlag){
-			ods.flip(info2);
-		}
-		
-		ods.flip(info1);
-		ods.flip(info2);
-		
-		if (count+1>=sort_count/2){
-			
-		} else if (count%2==0&&info.lastFlag&&count+2<sort_count/2){
-			new OddPhase(info0.key, info1.key, info2.key,count+2,info6.key);
-			ods.update(info6.key, count+2);
-		} else {
-			String f = (count%2==1) ? SetInfo.array[2*i] : SetInfo.array[2*i+1];
-			String b = (count%2==1) ? SetInfo.array[2*i+1] : SetInfo.array[2*i+2];
-			
-			new OddPhase(info0.key, f, b, count+1, info6.key);
-			ods.update(info6.key, count+1);
-		}
-		
-		
-	}
-	
-}
--- a/src/alice/test/codesegment/local/bitonicsort/SetInfo.java	Fri Mar 29 18:33:11 2013 +0900
+++ b/src/alice/test/codesegment/local/bitonicsort/SetInfo.java	Fri Mar 29 18:53:55 2013 +0900
@@ -8,7 +8,6 @@
 	public static String[] range;
 	public static String[] array;
 	public static String[] count;
-	public static String[] result;
 	
 	public SetInfo(SortConfig conf) {
 		this.conf = conf;
@@ -29,13 +28,11 @@
 		range = new String[conf.length];
 		array = new String[conf.length];
 		count = new String[conf.length];
-		result = new String[conf.length];
 		
 		for(int i = 0 ; i < conf.length ; i++) {
 			range[i] = "range" + i;
 			array[i] = "array" + i;
 			count[i] = "count" + i;
-			result[i] = "result" + i;
 		}
 		
 	}
--- a/src/alice/test/codesegment/local/bitonicsort/SetTask.java	Fri Mar 29 18:33:11 2013 +0900
+++ b/src/alice/test/codesegment/local/bitonicsort/SetTask.java	Fri Mar 29 18:53:55 2013 +0900
@@ -35,7 +35,7 @@
 				ods.update(SetInfo.array[i*2], list.createDataList(i*2*block_num, block_num));
 				ods.update(SetInfo.array[i*2+1], list.createDataList((i*2+1)*block_num, block_num));
 				ods.update(SetInfo.count[i], 0);
-				new OddPhase(SetInfo.range[i],SetInfo.array[i*2],SetInfo.array[i*2+1],0,SetInfo.count[i]);
+				new SortPhase(SetInfo.range[i],SetInfo.array[i*2],SetInfo.array[i*2+1],0,SetInfo.count[i]);
 				
 			}
 			new ShowData(i*2, sort_count);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/codesegment/local/bitonicsort/SortPhase.java	Fri Mar 29 18:53:55 2013 +0900
@@ -0,0 +1,65 @@
+package alice.test.codesegment.local.bitonicsort;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class SortPhase extends CodeSegment{
+	private Receiver info0 = ids.create(CommandType.PEEK); // range
+	private Receiver info1; 							   // Array1
+	private Receiver info2; 							   // Array2
+	private Receiver info3 = ids.create(CommandType.PEEK); // sort_count
+	private Receiver info4 = ids.create(CommandType.TAKE); // count
+	
+	
+	public SortPhase(String key0, String key1, String key2, int index, String key4){
+		// this setKey doesn't have to use. 
+		info0.setKey(key0);
+		info1 = ids.create(CommandType.TAKE);
+		info1.setKey(key1,index);
+		info2 = ids.create(CommandType.TAKE);
+		info2.setKey(key2,index);
+		info3.setKey("sort_count");
+		info4.setKey(key4);
+	}
+	
+	@Override
+	public void run() {
+		RangeInfo info = info0.asClass(RangeInfo.class);
+		DataList list1 = info1.asClass(DataList.class);
+		DataList list2 = info2.asClass(DataList.class);
+		int sort_count = info3.asInteger();
+		int count = info4.asInteger();
+		
+		int i = info.range;
+		//System.out.println("CS"+i+" "+info1.key+" "+info2.key+" dataIndex "+info1.index +" count "+count);
+		Sort.quickSort(list1);
+		Sort.quickSort(list2);
+		DataList.merge(list1,list2);
+		
+		if (count%2==0&&i==0){
+			ods.flip(info1); // first block index is less than others. So put data twice.
+		} else if (count%2==0&&info.lastFlag){
+			ods.flip(info2); // Same reason 
+		}
+		
+		ods.flip(info1);
+		ods.flip(info2);
+		
+		if (count+1>=sort_count/2){
+			
+		} else if (count%2==0&&info.lastFlag&&count+2<sort_count/2){
+			new SortPhase(info0.key, info1.key, info2.key,count+2,info4.key);
+			ods.update(info4.key, count+2);
+		} else {
+			String f = (count%2==1) ? SetInfo.array[2*i] : SetInfo.array[2*i+1];
+			String b = (count%2==1) ? SetInfo.array[2*i+1] : SetInfo.array[2*i+2];
+			
+			new SortPhase(info0.key, f, b, count+1, info4.key);
+			ods.update(info4.key, count+1);
+		}
+		
+		
+	}
+	
+}