Permalink
Browse files

Simplified API

  • Loading branch information...
1 parent f478b61 commit b109ac3888e462a4fa3478297d62f6b2adc82d8b @lemire committed May 28, 2012
View
@@ -1,3 +1,7 @@
+version 0.5.1 (May 28, 2012)
+- Fixed minor performance regression.
+
+
version 0.5.0 (May 23, 2012)
- Added a 32-bit version of the compression scheme.
@@ -21,12 +21,11 @@
*
* @param newdata
* the word
- * @return the number of words added to the buffer
*/
// @Override : causes problems with Java 1.5
- public int add(final long newdata) {
+ public void add(final long newdata) {
this.oneBits += Long.bitCount(newdata);
- return 0;
+ return;
}
/**
@@ -39,11 +38,11 @@ public int add(final long newdata) {
* @return the number of words added to the buffer
*/
// @Override : causes problems with Java 1.5
- public int addStreamOfEmptyWords(boolean v, long number) {
+ public void addStreamOfEmptyWords(boolean v, long number) {
if (v) {
this.oneBits += number * EWAHCompressedBitmap.wordinbits;
}
- return 0;
+ return;
}
/**
@@ -55,14 +54,13 @@ public int addStreamOfEmptyWords(boolean v, long number) {
* the starting point in the array
* @param number
* the number of dirty words to add
- * @return how many (compressed) words were added to the bitmap
*/
// @Override : causes problems with Java 1.5
- public int addStreamOfDirtyWords(long[] data, int start, int number) {
+ public void addStreamOfDirtyWords(long[] data, int start, int number) {
for (int i = start; i < start + number; i++) {
add(data[i]);
}
- return 0;
+ return;
}
/**
@@ -74,14 +72,13 @@ public int addStreamOfDirtyWords(long[] data, int start, int number) {
* the starting point in the array
* @param number
* the number of dirty words to add
- * @return how many (compressed) words were added to the bitmap
*/
// @Override : causes problems with Java 1.5
- public int addStreamOfNegatedDirtyWords(long[] data, int start, int number) {
+ public void addStreamOfNegatedDirtyWords(long[] data, int start, int number) {
for (int i = start; i < start + number; i++) {
add(~data[i]);
}
- return 0;
+ return;
}
/**
@@ -21,9 +21,8 @@
*
* @param newdata
* the word
- * @return the number of words added to the buffer
*/
- public int add(final long newdata);
+ public void add(final long newdata);
/**
* For experts: You want to add many zeroes or ones? This is the method you
@@ -33,9 +32,8 @@
* zeros or ones
* @param number
* how many to words add
- * @return the number of words added to the buffer
*/
- public int addStreamOfEmptyWords(final boolean v, final long number);
+ public void addStreamOfEmptyWords(final boolean v, final long number);
/**
* if you have several dirty words to copy over, this might be faster.
@@ -46,9 +44,8 @@
* the starting point in the array
* @param number
* the number of dirty words to add
- * @return how many (compressed) words were added to the bitmap
*/
- public int addStreamOfDirtyWords(final long[] data, final int start,
+ public void addStreamOfDirtyWords(final long[] data, final int start,
final int number);
/**
@@ -60,9 +57,8 @@ public int addStreamOfDirtyWords(final long[] data, final int start,
* the starting point in the array
* @param number
* the number of dirty words to add
- * @return how many (compressed) words were added to the bitmap
*/
- public int addStreamOfNegatedDirtyWords(long[] data, final int start,
+ public void addStreamOfNegatedDirtyWords(long[] data, final int start,
final int number);
/**
@@ -1153,10 +1153,9 @@ public boolean set(final int i) {
*
* @param newdata
* the word
- * @return the number of words added to the buffer
*/
- public int add(final long newdata) {
- return add(newdata, wordinbits);
+ public void add(final long newdata) {
+ add(newdata, wordinbits);
}
/**
@@ -1167,19 +1166,16 @@ public int add(final long newdata) {
* the boolean value
* @param number
* the number
- * @return the number of words added to the buffer
*/
- public int addStreamOfEmptyWords(final boolean v, long number) {
+ public void addStreamOfEmptyWords(final boolean v, long number) {
if (number == 0)
- return 0;
+ return;
this.sizeinbits += number * wordinbits;
- int wordsadded = 0;
if ((this.rlw.getRunningBit() != v) && (this.rlw.size() == 0)) {
this.rlw.setRunningBit(v);
} else if ((this.rlw.getNumberOfLiteralWords() != 0)
|| (this.rlw.getRunningBit() != v)) {
push_back(0);
- ++wordsadded;
this.rlw.position = this.actualsizeinwords - 1;
if (v)
this.rlw.setRunningBit(v);
@@ -1191,7 +1187,6 @@ public int addStreamOfEmptyWords(final boolean v, long number) {
number -= whatwecanadd;
while (number >= RunningLengthWord.largestrunninglengthcount) {
push_back(0);
- ++wordsadded;
this.rlw.position = this.actualsizeinwords - 1;
if (v)
this.rlw.setRunningBit(v);
@@ -1200,13 +1195,11 @@ public int addStreamOfEmptyWords(final boolean v, long number) {
}
if (number > 0) {
push_back(0);
- ++wordsadded;
this.rlw.position = this.actualsizeinwords - 1;
if (v)
this.rlw.setRunningBit(v);
this.rlw.setRunningLength(number);
}
- return wordsadded;
}
/**
@@ -1265,12 +1258,11 @@ private void fastaddStreamOfEmptyWords(final boolean v, long number) {
* the starting point in the array
* @param number
* the number of dirty words to add
- * @return how many (compressed) words were added to the bitmap
*/
- public int addStreamOfNegatedDirtyWords(final long[] data, final int start,
+ public void addStreamOfNegatedDirtyWords(final long[] data, final int start,
final int number) {
if (number == 0)
- return 0;
+ return;
final int NumberOfLiteralWords = this.rlw.getNumberOfLiteralWords();
final int whatwecanadd = number < RunningLengthWord.largestliteralcount
- NumberOfLiteralWords ? number : RunningLengthWord.largestliteralcount
@@ -1279,15 +1271,13 @@ public int addStreamOfNegatedDirtyWords(final long[] data, final int start,
final int leftovernumber = number - whatwecanadd;
negative_push_back(data, start, whatwecanadd);
this.sizeinbits += whatwecanadd * wordinbits;
- int wordsadded = whatwecanadd;
if (leftovernumber > 0) {
push_back(0);
this.rlw.position = this.actualsizeinwords - 1;
- ++wordsadded;
- wordsadded += addStreamOfDirtyWords(data, start + whatwecanadd,
+ addStreamOfDirtyWords(data, start + whatwecanadd,
leftovernumber);
}
- return wordsadded;
+ return;
}
/**
@@ -1300,12 +1290,11 @@ public int addStreamOfNegatedDirtyWords(final long[] data, final int start,
* the starting point in the array
* @param number
* the number of dirty words to add
- * @return how many (compressed) words were added to the bitmap
*/
- public int addStreamOfDirtyWords(final long[] data, final int start,
+ public void addStreamOfDirtyWords(final long[] data, final int start,
final int number) {
if (number == 0)
- return 0;
+ return;
final int NumberOfLiteralWords = this.rlw.getNumberOfLiteralWords();
final int whatwecanadd = number < RunningLengthWord.largestliteralcount
- NumberOfLiteralWords ? number : RunningLengthWord.largestliteralcount
@@ -1314,15 +1303,13 @@ public int addStreamOfDirtyWords(final long[] data, final int start,
final int leftovernumber = number - whatwecanadd;
push_back(data, start, whatwecanadd);
this.sizeinbits += whatwecanadd * wordinbits;
- int wordsadded = whatwecanadd;
if (leftovernumber > 0) {
push_back(0);
this.rlw.position = this.actualsizeinwords - 1;
- ++wordsadded;
- wordsadded += addStreamOfDirtyWords(data, start + whatwecanadd,
+ addStreamOfDirtyWords(data, start + whatwecanadd,
leftovernumber);
}
- return wordsadded;
+ return;
}
/**
@@ -1332,16 +1319,15 @@ public int addStreamOfDirtyWords(final long[] data, final int start,
* the word
* @param bitsthatmatter
* the number of significant bits (by default it should be 64)
- * @return the number of words added to the buffer
*/
- public int add(final long newdata, final int bitsthatmatter) {
+ public void add(final long newdata, final int bitsthatmatter) {
this.sizeinbits += bitsthatmatter;
if (newdata == 0) {
- return addEmptyWord(false);
+ addEmptyWord(false);
} else if (newdata == ~0l) {
- return addEmptyWord(true);
+ addEmptyWord(true);
} else {
- return addLiteralWord(newdata);
+ addLiteralWord(newdata);
}
}
@@ -1513,9 +1499,8 @@ private void negative_push_back(final long[] data, final int start,
*
* @param v
* the boolean value
- * @return the storage cost of the addition
*/
- private int addEmptyWord(final boolean v) {
+ private void addEmptyWord(final boolean v) {
final boolean noliteralword = (this.rlw.getNumberOfLiteralWords() == 0);
final long runlen = this.rlw.getRunningLength();
if ((noliteralword) && (runlen == 0)) {
@@ -1524,34 +1509,31 @@ private int addEmptyWord(final boolean v) {
if ((noliteralword) && (this.rlw.getRunningBit() == v)
&& (runlen < RunningLengthWord.largestrunninglengthcount)) {
this.rlw.setRunningLength(runlen + 1);
- return 0;
+ return;
}
push_back(0);
this.rlw.position = this.actualsizeinwords - 1;
this.rlw.setRunningBit(v);
this.rlw.setRunningLength(1);
- return 1;
+ return;
}
/**
* For internal use.
*
* @param newdata
* the dirty word
- * @return the storage cost of the addition
*/
- private int addLiteralWord(final long newdata) {
+ private void addLiteralWord(final long newdata) {
final int numbersofar = this.rlw.getNumberOfLiteralWords();
if (numbersofar >= RunningLengthWord.largestliteralcount) {
push_back(0);
this.rlw.position = this.actualsizeinwords - 1;
this.rlw.setNumberOfLiteralWords(1);
push_back(newdata);
- return 2;
}
this.rlw.setNumberOfLiteralWords(numbersofar + 1);
push_back(newdata);
- return 1;
}
/**
@@ -24,10 +24,10 @@
*
* @see javaewah.BitmapStorage#add(long)
*/
- public int add(long newdata) {
+ public void add(long newdata) {
if (newdata != 0)
throw new NonEmptyException();
- return 0;
+ return;
}
/**
@@ -36,18 +36,18 @@ public int add(long newdata) {
*
* @see javaewah.BitmapStorage#addStreamOfEmptyWords(boolean, long)
*/
- public int addStreamOfEmptyWords(boolean v, long number) {
+ public void addStreamOfEmptyWords(boolean v, long number) {
if (v)
throw new NonEmptyException();
- return 0;
+ return;
}
/**
* throws a NonEmptyException exception
*
* @see javaewah.BitmapStorage#addStreamOfDirtyWords(long[], long, long)
*/
- public int addStreamOfDirtyWords(long[] data, int start, int number) {
+ public void addStreamOfDirtyWords(long[] data, int start, int number) {
throw new NonEmptyException();
}
@@ -57,7 +57,7 @@ public int addStreamOfDirtyWords(long[] data, int start, int number) {
* @see javaewah.BitmapStorage#addStreamOfNegatedDirtyWords(long[], long,
* long)
*/
- public int addStreamOfNegatedDirtyWords(long[] data, int start, int number) {
+ public void addStreamOfNegatedDirtyWords(long[] data, int start, int number) {
throw new NonEmptyException();
}
Oops, something went wrong.

0 comments on commit b109ac3

Please sign in to comment.