Mercurial > hg > Database > Alice
view src/alice/test/codesegment/local/bitonicsort/noarrraylist/OddPhase.java @ 206:5016c7e18c76 working
use flip API
author | sugi |
---|---|
date | Tue, 26 Mar 2013 01:45:34 +0900 |
parents | 7f47231ef509 |
children |
line wrap: on
line source
package alice.test.codesegment.local.bitonicsort.noarrraylist; 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 ,int index,String key6){ info0.setKey(key0); info1 = ids.create(CommandType.TAKE); info1.setKey(key1,index); info3.setKey("block_num"); info5.setKey("sort_count"); info6.setKey(key6); } 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); int block_num = info3.asInteger(); int sort_count = info5.asInteger(); int count = info6.asInteger(); //System.out.println("count is " +count); if (info2==null){ DataList list = (DataList)info1.obj; if (count > sort_count){ info1.flip(CommandType.UPDATE, "array"+info.range, list, false); return; } Sort.quickSort(list,0,list.table.length-1); if (!info.lastFlag){ info1.flip(CommandType.PUT, info.range+"f", list.createDataList(0, block_num/2) ,false); info3.flip(CommandType.PUT, info.range+"b", list.createDataList(block_num/2, block_num/2) ,false); if (info.range==0){ //System.out.println("next Even "+info.range+" "+info.range+"f"); new EvenPhase(info0.key,info.range+"f",count,info6.key); } else { //System.out.println("next Even "+info.range+" "+ (info.range-1)+"b"+" "+(info.range)+"f"); new EvenPhase(info0.key,(info.range-1)+"b",info.range+"f",count,info6.key); } } else { info1.flip(CommandType.PUT, info.range+"f",list, false); info3.flip(CommandType.PUT, info.range+"b","dummy"); //System.out.println("next Even "+info.range+" "+ (info.range-1)+"b"+" "+(info.range)+"f"); new EvenPhase(info0.key,(info.range-1)+"b",info.range+"f",count,info6.key); } } else { DataList list1 = (DataList)info1.obj; DataList list2 = (DataList)info2.obj; DataList list3 = new DataList(list1.table.length+list2.table.length); System.arraycopy(list1.table, 0, list3.table, 0, list1.table.length); System.arraycopy(list2.table, 0, list3.table, list1.table.length, list2.table.length); if (count > sort_count){ info1.flip(CommandType.UPDATE, "array"+info.range, list3, false); return; } Sort.quickSort(list3,0,list3.table.length-1); info1.flip(CommandType.PUT, info.range+"f", list3.createDataList(0, block_num/2) ,false); info2.flip(CommandType.PUT, info.range+"b", list3.createDataList(block_num/2, block_num/2) ,false); if (info.range==0){ //System.out.println("next Even2b "+info.range+" "+ info.range+"f"); new EvenPhase(info0.key,info.range+"f",count,info6.key); } else { //System.out.println("next Even2b "+info.range+" "+ (info.range-1)+"b"+" "+info.range+"f"); new EvenPhase(info0.key,(info.range-1)+"b",info.range+"f",count,info6.key); } } info6.flip(CommandType.UPDATE, info6.key, count+1); } }