working genome on byte strings
authorbdemsky <bdemsky>
Wed, 21 Oct 2009 01:01:01 +0000 (01:01 +0000)
committerbdemsky <bdemsky>
Wed, 21 Oct 2009 01:01:01 +0000 (01:01 +0000)
Robust/src/Benchmarks/SingleTM/Genome/Bitmap.java
Robust/src/Benchmarks/SingleTM/Genome/ByteString.java
Robust/src/Benchmarks/SingleTM/Genome/Hashtable.java
Robust/src/Benchmarks/SingleTM/Genome/List.java
Robust/src/Benchmarks/SingleTM/Genome/Sequencer.java

index f9115244745a950f537e6819719c9b73c696bf56..cfd6a8f707bc4a9aae16316d7bbef3e9b634d785 100644 (file)
@@ -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; 
-  }  
 }
index a3c3dd7caef88a0793c230c2aac2a3a06c6c2a50..7f956af2bb48ed18edfdd10468d1a41889c7a68d 100644 (file)
@@ -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=count<s.count?count:s.count;
+
+    int off=offset;
+    int soff=s.offset;
+    for( int i = 0; i < smallerlength; i++) {
+      int valDiff = this.value[i+offset] - s.value[i+soff];
+      if( valDiff != 0 ) {
+        return valDiff;
+      }
+    }
+    return count-s.count;
   }
 
+  public boolean endsWith(ByteString suffix) {
+    return regionMatches(count - suffix.count, suffix, 0, suffix.count);
+  }
 
   public ByteString substring(int beginIndex) {
     return substring(beginIndex, this.count);
@@ -46,13 +59,6 @@ public class ByteString {
     return this.lastindexOf(ch, count - 1);
   }
 
-  public static ByteString concat2(ByteString s1, ByteString s2) {
-    if (s1==null)
-      return "null".concat(s2);
-    else
-      return s1.concat(s2);
-  }
-
   public ByteString concat(ByteString str) {
     ByteString newstr=new ByteString();
     newstr.count=this.count+str.count;
@@ -62,15 +68,17 @@ public class ByteString {
     for(int i=0; i<count; i++) {
       charstr[i]=value[i+offset];
     }
+    int stroffset=str.offset;
     for(int i=0; i<str.count; i++) {
-      charstr[i+count]=str.value[i+str.offset];
+      charstr[i+count]=str.value[stroffset];
     }
     return newstr;
   }
 
   public int lastindexOf(int ch, int fromIndex) {
+    int off=offset;
     for(int i=fromIndex; i>0; 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<count; i++)
-      if (this.byteAt(i)==ch)
+      if (this.value[i+off]==ch)
        return i;
     return -1;
   }
@@ -148,17 +157,15 @@ public class ByteString {
   }
 
   public int hashCode() {
-    if (cachedHashCode!=0)
-      return cachedHashCode;
+    if (cachedHashcode!=0)
+      return cachedHashcode;
     int hash=0;
     int off=offset;
-    for(int index = 0; index < str.length(); index++) {
-      byte c = str.value[index+off];
+    for(int index = 0; index < count; index++) {
+      byte c = value[index+off];
       hash = c + (hash << 6) + (hash << 16) - hash;
     }
-    if(hash < 0) hash = -hash;
-    
-    cachedHashCode=hash;
+    cachedHashcode=hash<0?-hash:hash;
     return hash;
   }
 
index 65087e0b8ffddf169f4dc0f19009c0226d5eacec..f2b54ce416860ff3fb045f7f40d188d040ef87cb 100644 (file)
@@ -18,7 +18,7 @@ public class Hashtable {
 
       Pair findPair = new Pair();
       findPair.firstPtr = keyPtr;
-      Pair pairPtr = buckets[(int)i].find(findPair);
+      Pair pairPtr = buckets[i].find(findPair);
       if (pairPtr != null) {
           return false;
       }
@@ -26,7 +26,7 @@ public class Hashtable {
       Pair insertPtr = new Pair(keyPtr, dataPtr);
 
       /* Add new entry  */
-      if (buckets[(int)i].insert(insertPtr) == false) {
+      if (buckets[i].insert(insertPtr) == false) {
           return false;
       }
 
@@ -42,22 +42,7 @@ public class Hashtable {
       
       for (i = 0; i < (numBucket + 1); i++) {
           List chainPtr = new List();
-          buckets[(int)i] = chainPtr;
+          buckets[i] = chainPtr;
       }
     }
-    
-    int hashSegment (ByteString str) {
-      int hash = 0;
-
-      int index = 0;
-      /* Note: Do not change this hashing scheme */
-      for(index = 0; index < str.length(); index++) {
-        char c = str.byteAt(index);
-        hash = c + (hash << 6) + (hash << 16) - hash;
-      }
-  
-      if(hash < 0) hash *= -1;
-
-      return hash;
-    }
 }
index 4412815a613b50ca277ec76eb059072a6758f68f..6ced9fa8492ee9edc4da730fc93889b9b189b5eb 100644 (file)
@@ -15,11 +15,11 @@ public class List {
 
     nodePtr = prevPtr.nextPtr;
 
-    if ((nodePtr == null) || (compareSegment(nodePtr.dataPtr, dataPtr) != 0)) {
+    if ((nodePtr == null) || nodePtr.dataPtr.firstPtr.compareTo(dataPtr.firstPtr) !=0 ) {
       return null;
     }
 
-    return (nodePtr.dataPtr);
+    return nodePtr.dataPtr;
   }
 
   ListNode findPrevious (Pair dataPtr) {
@@ -28,7 +28,7 @@ public class List {
     nodePtr = prevPtr.nextPtr;
 
     for (; nodePtr != null; nodePtr = nodePtr.nextPtr) {
-      if (compareSegment(nodePtr.dataPtr, dataPtr) >= 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);
-  }
 }
index 741467cc9f6b2068dc260629780a0af6c1ef6d3a..1e0af4b350be78571d0e084a7c0789335bc6330c 100644 (file)
@@ -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 */