use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class Roaring64NavigableMap method or.
/**
* In-place bitwise OR (union) operation. The current bitmap is modified.
*
* @param x2 other bitmap
*/
public void or(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).or((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).or((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;
}
}
}
use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class Roaring64NavigableMap method and.
/**
* In-place bitwise AND (intersection) operation. The current bitmap is modified.
*
* @param x2 other bitmap
*/
public void and(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) {
// None of given high values are present in x2
thisIterator.remove();
} else {
BitmapDataProvider lowBitmap1 = e1.getValue();
if (lowBitmap2 instanceof RoaringBitmap && lowBitmap1 instanceof RoaringBitmap) {
((RoaringBitmap) lowBitmap1).and((RoaringBitmap) lowBitmap2);
} else if (lowBitmap2 instanceof MutableRoaringBitmap && lowBitmap1 instanceof MutableRoaringBitmap) {
((MutableRoaringBitmap) lowBitmap1).and((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 deserialize.
/**
* Deserialize (retrieve) this bitmap.
*
* Unlike RoaringBitmap, there is no specification for now: it may change from one java version to
* another, and from one RoaringBitmap version to another.
*
* The current bitmap is overwritten.
*
* @param in the DataInput stream
* @throws IOException Signals that an I/O exception has occurred.
*/
public void deserialize(DataInput in) throws IOException {
this.clear();
signedLongs = in.readBoolean();
int nbHighs = in.readInt();
// Other NavigableMap may accept a target capacity
highToBitmap = new TreeMap<>();
for (int i = 0; i < nbHighs; i++) {
int high = in.readInt();
RoaringBitmap provider = new RoaringBitmap();
provider.deserialize(in);
highToBitmap.put(high, provider);
}
resetPerfHelpers();
}
use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class MapBenchmark method testMap.
@BenchmarkMode(Mode.AverageTime)
@Benchmark
public RoaringBitmap testMap(BenchmarkState benchmarkState) {
final RoaringBitmap answer = new RoaringBitmap();
benchmarkState.bitmap.forEach(new IntConsumer() {
@Override
public void accept(int value) {
answer.add(inttointmap(value));
}
});
return answer;
}
use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class RoaringBitmapBenchmark method inplace_and.
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public RoaringBitmap inplace_and() {
RoaringBitmap b1 = bitmap1.clone();
b1.and(bitmap2);
return b1;
}
Aggregations