From 018677a159a6a529dd74c1d0bd443fe2b230877a Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 21 Oct 2009 01:01:01 +0000 Subject: [PATCH] working genome on byte strings --- .../Benchmarks/SingleTM/Genome/Bitmap.java | 26 +++++------ .../SingleTM/Genome/ByteString.java | 45 +++++++++++-------- .../Benchmarks/SingleTM/Genome/Hashtable.java | 21 ++------- .../src/Benchmarks/SingleTM/Genome/List.java | 14 ++---- .../Benchmarks/SingleTM/Genome/Sequencer.java | 10 ++--- 5 files changed, 48 insertions(+), 68 deletions(-) diff --git a/Robust/src/Benchmarks/SingleTM/Genome/Bitmap.java b/Robust/src/Benchmarks/SingleTM/Genome/Bitmap.java index f9115244..cfd6a8f7 100644 --- a/Robust/src/Benchmarks/SingleTM/Genome/Bitmap.java +++ b/Robust/src/Benchmarks/SingleTM/Genome/Bitmap.java @@ -53,7 +53,7 @@ public class Bitmap { return false; } - bits[((int)i)/NUM_BIT_PER_WORD] |= (1 << (i % NUM_BIT_PER_WORD)); + bits[i/NUM_BIT_PER_WORD] |= (1 << (i % NUM_BIT_PER_WORD)); return true; } @@ -70,7 +70,7 @@ public class Bitmap { return false; } - bits[((int)i)/NUM_BIT_PER_WORD] &= ~(1 << (i % NUM_BIT_PER_WORD)); + bits[i/NUM_BIT_PER_WORD] &= ~(1 << (i % NUM_BIT_PER_WORD)); return true; } @@ -95,11 +95,11 @@ public class Bitmap { * ============================================================================= */ boolean isSet (int i) { - int tempB = (int)bits[((int)i)/NUM_BIT_PER_WORD]; - int tempC = (1 << (((int)i) % NUM_BIT_PER_WORD)); + int tempB = bits[i/NUM_BIT_PER_WORD]; + int tempC = (1 << (i % NUM_BIT_PER_WORD)); boolean tempbool = ((tempB & tempC) > 0) ? true:false; //tempB /*bits[((int)i)/NUM_BIT_PER_WORD]*/ & tempC /*(1 << (i % NUM_BIT_PER_WORD))*/ - if ((i >= 0) && (i < (int)numBit) && tempbool) { + if ((i >= 0) && (i < numBit) && tempbool) { return true; } @@ -116,8 +116,8 @@ public class Bitmap { */ int findClear (int startIndex) { int i; - boolean tempbool = ((bits[((int)i)/NUM_BIT_PER_WORD] & (1 << (i % NUM_BIT_PER_WORD))) > 0) ? true:false; - for (i = MAX(startIndex, 0); i < numBit; i++) { + boolean tempbool = ((bits[i/NUM_BIT_PER_WORD] & (1 << (i % NUM_BIT_PER_WORD))) > 0) ? true:false; + for (i = (startIndex>0?startIndex:0);i < numBit; i++) { if (!tempbool) { return i; } @@ -136,8 +136,8 @@ public class Bitmap { int findSet (int startIndex) { int i; - for (i = MAX(startIndex, 0); i < numBit; i++) { - boolean tempbool = ((int)bits[((int)i)/NUM_BIT_PER_WORD] & (1 << ((int)i % NUM_BIT_PER_WORD)) > 0) ? true:false; + for (i = (startIndex>0? startIndex: 0); i < numBit; i++) { + boolean tempbool = (bits[i/NUM_BIT_PER_WORD] & (1 << (i % NUM_BIT_PER_WORD)) > 0) ? true:false; if (tempbool) { return i; } @@ -164,7 +164,7 @@ public class Bitmap { int i; int count = 0; for (i = 0; i < numBit; i++) { - boolean tempbool = ((int)bits[((int)i)/NUM_BIT_PER_WORD] & (1 << ((int)i % NUM_BIT_PER_WORD)) > 0) ? true:false; + boolean tempbool = (bits[i/NUM_BIT_PER_WORD] & (1 << (i % NUM_BIT_PER_WORD)) > 0) ? true:false; if (tempbool) { count++; } @@ -184,11 +184,7 @@ public class Bitmap { } } - int DIVIDE_AND_ROUND_UP(int a, int b) { + static int DIVIDE_AND_ROUND_UP(int a, int b) { return (a/b) + (((a % b) > 0) ? (1) : (0)); } - - int MAX(int a, int b) { - return (a > b) ? a : b; - } } diff --git a/Robust/src/Benchmarks/SingleTM/Genome/ByteString.java b/Robust/src/Benchmarks/SingleTM/Genome/ByteString.java index a3c3dd7c..7f956af2 100644 --- a/Robust/src/Benchmarks/SingleTM/Genome/ByteString.java +++ b/Robust/src/Benchmarks/SingleTM/Genome/ByteString.java @@ -13,10 +13,23 @@ public class ByteString { this.offset=0; } - public boolean endsWith(String suffix) { - return regionMatches(count - suffix.count, suffix, 0, suffix.count); + public int compareTo(ByteString s) { + int smallerlength=count0; i--) - if (this.byteAt(i)==ch) + if (this.value[i+offset]==ch) return i; return -1; } @@ -80,8 +88,9 @@ public class ByteString { } public int indexOf(int ch, int fromIndex) { + int off=offset; for(int i=fromIndex; i= 0) { + if (nodePtr.dataPtr.firstPtr.compareTo(dataPtr.firstPtr) >= 0) { return prevPtr; } prevPtr = nodePtr; @@ -45,7 +45,7 @@ public class List { prevPtr = findPrevious(dataPtr); currPtr = prevPtr.nextPtr; - if ((currPtr != null) && (compareSegment((Pair)currPtr.dataPtr, (Pair)dataPtr) == 0)) { + if ((currPtr != null) && (currPtr.dataPtr.firstPtr.compareTo(dataPtr.firstPtr)==0)) { return false; } @@ -57,10 +57,4 @@ public class List { return true; } - - int compareSegment (Pair a, Pair b) { - ByteString aString = a.firstPtr; - ByteString bString = b.firstPtr; - return aString.compareTo(bString); - } } diff --git a/Robust/src/Benchmarks/SingleTM/Genome/Sequencer.java b/Robust/src/Benchmarks/SingleTM/Genome/Sequencer.java index 741467cc..1e0af4b3 100644 --- a/Robust/src/Benchmarks/SingleTM/Genome/Sequencer.java +++ b/Robust/src/Benchmarks/SingleTM/Genome/Sequencer.java @@ -196,18 +196,16 @@ public class Sequencer { startHash = 0; for (newj = 1; newj < segmentLength; newj++) { - startHash = segment.charAt((int)newj-1) + (startHash << 6) + (startHash << 16) - startHash; + startHash = segment.byteAt(newj-1) + (startHash << 6) + (startHash << 16) - startHash; atomic { boolean check = startHashToConstructEntryTables[newj].table_insert(startHash, constructEntryPtr); } - } - /* * For looking up construct entries quickly */ - startHash = segment.charAt((int)newj-1) + (startHash << 6) + (startHash << 16) - startHash; + startHash = segment.byteAt(newj-1) + (startHash << 6) + (startHash << 16) - startHash; atomic { hashToConstructEntryTable.table_insert(startHash, constructEntryPtr); } @@ -377,9 +375,9 @@ public class Sequencer { static void trans2(ByteString startSegment, ByteString endSegment, constructEntry startConstructEntryPtr, constructEntry endConstructEntryPtr, int segmentLength, int substringLength, endInfoEntry endInfoEntries[], int entryIndex) { if(startConstructEntryPtr.isStart && (endConstructEntryPtr.startPtr != startConstructEntryPtr) && - (startSegment.substring(0, substringLength.compareTo(endSegment.substring(segmentLength-substringLength))) == 0)) { + (startSegment.substring(0, substringLength).compareTo(endSegment.substring(segmentLength-substringLength)) == 0)) { startConstructEntryPtr.isStart = false; - + /* Update endInfo (appended something so no inter end) */ endInfoEntries[entryIndex].isEnd = false; /* Update segment chain construct info */ -- 2.34.1