use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class RunContainerRealDataBenchmarkRunOptimize method clone.
@Benchmark
public int clone(BenchmarkState benchmarkState) {
int total = 0;
for (int i = 0; i < benchmarkState.ac.size(); i++) {
RoaringBitmap bitmap = benchmarkState.ac.get(i).clone();
total += bitmap.getCardinality();
}
return total;
}
use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class RunContainerRealDataBenchmarkRunOptimize method serializeToBAOSNoClone.
@Benchmark
public int serializeToBAOSNoClone(BenchmarkState benchmarkState) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
for (int i = 0; i < benchmarkState.ac.size(); i++) {
RoaringBitmap bitmap = benchmarkState.ac.get(i);
bitmap.serialize(dos);
}
dos.flush();
return bos.size();
}
use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class TestRoaringBitmap method conversionTest.
@Test
public void conversionTest() {
RoaringBitmap rb = new RoaringBitmap();
for (int i = 0; i < 100; i++) {
rb.add(i);
}
for (int i = 0; i < 100; i++) {
rb.add(i * 2 + (1 << 16));
}
for (int i = 0; i < (1 << 16); i++) {
rb.add(i * 2 + 2 * (1 << 16));
}
rb.runOptimize();
MutableRoaringBitmap mrb = rb.toMutableRoaringBitmap();
RoaringBitmap rb2 = mrb.toRoaringBitmap();
Assert.assertEquals(rb, rb2);
ImmutableRoaringBitmap irb = toMapped(mrb);
Assert.assertEquals(irb.toRoaringBitmap(), rb2);
}
use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class Roaring64NavigableMap method andNot.
/**
* In-place bitwise ANDNOT (difference) operation. The current bitmap is modified.
*
* @param x2 other bitmap
*/
public void andNot(final Roaring64NavigableMap x2) {
boolean firstBucket = true;
Iterator<Entry<Integer, BitmapDataProvider>> thisIterator = highToBitmap.entrySet().iterator();
while (thisIterator.hasNext()) {
Entry<Integer, BitmapDataProvider> e1 = thisIterator.next();
// Keep object to prevent auto-boxing
Integer high = e1.getKey();
BitmapDataProvider lowBitmap2 = x2.highToBitmap.get(high);
if (lowBitmap2 != null) {
BitmapDataProvider lowBitmap1 = e1.getValue();
if (lowBitmap2 instanceof RoaringBitmap && lowBitmap1 instanceof RoaringBitmap) {
((RoaringBitmap) lowBitmap1).andNot((RoaringBitmap) lowBitmap2);
} else if (lowBitmap2 instanceof MutableRoaringBitmap && lowBitmap1 instanceof MutableRoaringBitmap) {
((MutableRoaringBitmap) lowBitmap1).andNot((MutableRoaringBitmap) lowBitmap2);
} else {
throw new UnsupportedOperationException(".and is not between " + this.getClass() + " and " + lowBitmap1.getClass());
}
}
if (firstBucket) {
firstBucket = false;
// Invalidate the lowest high as lowest not valid
firstHighNotValid = Math.min(firstHighNotValid, high);
allValid = false;
}
}
}
use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class Roaring64NavigableMap method xor.
/**
* In-place bitwise XOR (symmetric difference) operation. The current bitmap is modified.
*
* @param x2 other bitmap
*/
public void xor(final Roaring64NavigableMap x2) {
boolean firstBucket = true;
for (Entry<Integer, BitmapDataProvider> e2 : x2.highToBitmap.entrySet()) {
// Keep object to prevent auto-boxing
Integer high = e2.getKey();
BitmapDataProvider lowBitmap1 = this.highToBitmap.get(high);
BitmapDataProvider lowBitmap2 = e2.getValue();
// not on buffer
if ((lowBitmap1 == null || lowBitmap1 instanceof RoaringBitmap) && lowBitmap2 instanceof RoaringBitmap) {
if (lowBitmap1 == null) {
// Clone to prevent future modification of this modifying the input Bitmap
RoaringBitmap lowBitmap2Clone = ((RoaringBitmap) lowBitmap2).clone();
pushBitmapForHigh(high, lowBitmap2Clone);
} else {
((RoaringBitmap) lowBitmap1).xor((RoaringBitmap) lowBitmap2);
}
} else if ((lowBitmap1 == null || lowBitmap1 instanceof MutableRoaringBitmap) && lowBitmap2 instanceof MutableRoaringBitmap) {
if (lowBitmap1 == null) {
// Clone to prevent future modification of this modifying the input Bitmap
BitmapDataProvider lowBitmap2Clone = ((MutableRoaringBitmap) lowBitmap2).clone();
pushBitmapForHigh(high, lowBitmap2Clone);
} else {
((MutableRoaringBitmap) lowBitmap1).xor((MutableRoaringBitmap) lowBitmap2);
}
} else {
throw new UnsupportedOperationException(".or is not between " + this.getClass() + " and " + lowBitmap2.getClass());
}
if (firstBucket) {
firstBucket = false;
// Invalidate the lowest high as lowest not valid
firstHighNotValid = Math.min(firstHighNotValid, high);
allValid = false;
}
}
}
Aggregations