use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class BitmapOffset method getReverseBitmapOffsetIterator.
static IntIterator getReverseBitmapOffsetIterator(ImmutableBitmap bitmapIndex) {
ImmutableBitmap roaringBitmap = bitmapIndex;
if (!(bitmapIndex instanceof WrappedImmutableRoaringBitmap)) {
final MutableBitmap bitmap = ROARING_BITMAP_FACTORY.makeEmptyMutableBitmap();
final IntIterator iterator = bitmapIndex.iterator();
while (iterator.hasNext()) {
bitmap.add(iterator.next());
}
roaringBitmap = ROARING_BITMAP_FACTORY.makeImmutableBitmap(bitmap);
}
return ((WrappedImmutableRoaringBitmap) roaringBitmap).getBitmap().getReverseIntIterator();
}
use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class BitmapCreationBenchmark method testLinearAddition.
@BenchmarkOptions(warmupRounds = 10, benchmarkRounds = 1000)
@Test
public void testLinearAddition() {
MutableBitmap mutableBitmap = factory.makeEmptyMutableBitmap();
for (int i = 0; i < NUM_BITS; ++i) {
mutableBitmap.add(i);
}
Assert.assertEquals(NUM_BITS, mutableBitmap.size());
}
use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class Point method makeBitmap.
private static MutableBitmap makeBitmap(int entry, BitmapFactory bitmapFactory) {
MutableBitmap retVal = bitmapFactory.makeEmptyMutableBitmap();
retVal.add(entry);
return retVal;
}
use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class BitmapBenchmarkWithVaryingOrder method setup.
@Setup(Level.Trial)
public void setup() throws IOException {
switch(type) {
case "concise":
bitmapFactory = new ConciseBitmapFactory();
break;
case "roaring":
bitmapFactory = new RoaringBitmapFactory();
break;
default:
throw new IAE("Unknown bitmap type[%s]", type);
}
bitmaps = new ArrayList<>(numBitmaps);
// Bitmaps usually have a short circuit to early return an empty bitmap if it finds no intersection
// during an AND operation. We want to let them iterate all bitmaps instead, so add some bits that
// will be set for all bitmaps we create.
final int[] knownTrue = new int[minIntersect];
for (int i = 0; i < knownTrue.length; ++i) {
knownTrue[i] = RANDOM.nextInt(bitmapLength);
}
for (int i = 0; i < numBitmaps; ++i) {
// the later the bitmap is created, the higher its density is.
final int bitCount = (int) (i * 0.1);
IntSet ints = new IntOpenHashSet(bitCount);
for (int j = 0; j < bitCount; j++) {
int offset;
do {
offset = RANDOM.nextInt(bitmapLength);
} while (ints.contains(offset));
ints.add(offset);
}
final MutableBitmap mutableBitmap = bitmapFactory.makeEmptyMutableBitmap();
ints.iterator().forEachRemaining((IntConsumer) mutableBitmap::add);
for (int k : knownTrue) {
mutableBitmap.add(k);
}
bitmaps.add(BitmapBenchmarkUtils.toOffheap(bitmapFactory.makeImmutableBitmap(mutableBitmap)));
}
reverseBitmaps = Lists.reverse(bitmaps);
}
use of org.apache.druid.collections.bitmap.MutableBitmap in project druid by druid-io.
the class UniformBitmapBenchmark method setup.
@Setup(Level.Trial)
public void setup() throws IOException {
final int[] knownTrue = new int[minIntersect];
for (int i = 0; i < knownTrue.length; ++i) {
knownTrue[i] = RANDOM.nextInt(bitmapLength);
}
switch(type) {
case "concise":
bitmapFactory = new ConciseBitmapFactory();
break;
case "roaring":
bitmapFactory = new RoaringBitmapFactory();
break;
default:
throw new IAE("Unknown bitmap type[%s]", type);
}
bitmaps = new ArrayList<>(numBitmaps);
for (int i = 0; i < numBitmaps; ++i) {
final MutableBitmap mutableBitmap = bitmapFactory.makeEmptyMutableBitmap();
for (int k = 0; k < bitmapLength; ++k) {
if (RANDOM.nextDouble() < density) {
mutableBitmap.add(k);
}
}
for (int k : knownTrue) {
mutableBitmap.add(k);
}
bitmaps.add(BitmapBenchmarkUtils.toOffheap(bitmapFactory.makeImmutableBitmap(mutableBitmap)));
}
final long totalSizeBytes = bitmaps.stream().mapToLong(bitmap -> bitmap.toBytes().length).sum();
BitmapBenchmarkUtils.printSizeStats(type, density, bitmaps.size(), totalSizeBytes);
}
Aggregations