Skip to content

Commit

Permalink
Add some methods to RoaringBitmap32.
Browse files Browse the repository at this point in the history
  • Loading branch information
guanshi committed Jul 16, 2024
1 parent fcde4c1 commit 1c0cc80
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.DataOutput;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.Objects;

/** A compressed bitmap for 32-bit integer. */
Expand Down Expand Up @@ -103,6 +104,19 @@ public void deserialize(byte[] rbmBytes) throws IOException {
roaringBitmap.deserialize(ByteBuffer.wrap(rbmBytes));
}

public void flip(final long rangeStart, final long rangeEnd) {
roaringBitmap.flip(rangeStart, rangeEnd);
}

public Iterator<Integer> iterator() {
return roaringBitmap.iterator();
}

@Override
public String toString() {
return roaringBitmap.toString();
}

@VisibleForTesting
public static RoaringBitmap32 bitmapOf(int... dat) {
RoaringBitmap32 roaringBitmap32 = new RoaringBitmap32();
Expand All @@ -119,4 +133,20 @@ public static RoaringBitmap32 and(final RoaringBitmap32 x1, final RoaringBitmap3
public static RoaringBitmap32 or(final RoaringBitmap32 x1, final RoaringBitmap32 x2) {
return new RoaringBitmap32(RoaringBitmap.or(x1.roaringBitmap, x2.roaringBitmap));
}

public static RoaringBitmap32 or(Iterator<RoaringBitmap32> iterator) {
return new RoaringBitmap32(
RoaringBitmap.or(
new Iterator<RoaringBitmap>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}

@Override
public RoaringBitmap next() {
return iterator.next().roaringBitmap;
}
}));
}
}

0 comments on commit 1c0cc80

Please sign in to comment.