Skip to content

Commit

Permalink
optimise OrderedWriter code
Browse files Browse the repository at this point in the history
  • Loading branch information
richardstartin committed Dec 18, 2017
1 parent 0d4a981 commit 83b49de
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions roaringbitmap/src/main/java/org/roaringbitmap/OrderedWriter.java
Expand Up @@ -23,10 +23,10 @@ public OrderedWriter(RoaringBitmap underlying) {
public void add(int value) {
short key = Util.highbits(value);
short low = Util.lowbits(value);
if (Util.compareUnsigned(key, currentKey) < 0) {
throw new IllegalStateException("Must write in ascending key order");
}
if (key != currentKey) {
if (Util.compareUnsigned(key, currentKey) < 0) {
throw new IllegalStateException("Must write in ascending key order");
}
flush();
}
int ulow = low & 0xFFFF;
Expand Down Expand Up @@ -72,11 +72,11 @@ private ArrayContainer createArrayContainer(int cardinality) {
int arrIndex = 0;
for (int i = 0; i < bitmap.length; ++i) {
long word = bitmap[i];
for (int j = Long.numberOfTrailingZeros(word); j < 64; j = Long.numberOfTrailingZeros(word)) {
if ((word & (1L << j)) != 0) {
word ^= (1L << j);
array[arrIndex++] = (short) ((i << 6) + j);
}
int j = Long.numberOfTrailingZeros(word);
while (j < 64) {
word ^= (1L << j);
array[arrIndex++] = (short) ((i << 6) + j);
j = Long.numberOfTrailingZeros(word);
}
}
return new ArrayContainer(cardinality, array);
Expand Down

0 comments on commit 83b49de

Please sign in to comment.