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;
}
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;
}
* =============================================================================
*/
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;
}
*/
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;
}
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;
}
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++;
}
}
}
- 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;
- }
}
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);
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;
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;
}
}
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;
}
}
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;
}
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;
}
Pair insertPtr = new Pair(keyPtr, dataPtr);
/* Add new entry */
- if (buckets[(int)i].insert(insertPtr) == false) {
+ if (buckets[i].insert(insertPtr) == false) {
return false;
}
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;
- }
}
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) {
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;
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;
}
return true;
}
-
- int compareSegment (Pair a, Pair b) {
- ByteString aString = a.firstPtr;
- ByteString bString = b.firstPtr;
- return aString.compareTo(bString);
- }
}
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);
}
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 */