use of org.roaringbitmap.buffer.MutableRoaringBitmap in project druid by druid-io.
the class WrappedRoaringBitmap method and.
@Override
public void and(MutableBitmap mutableBitmap) {
WrappedRoaringBitmap other = (WrappedRoaringBitmap) mutableBitmap;
MutableRoaringBitmap unwrappedOtherBitmap = other.bitmap;
bitmap.and(unwrappedOtherBitmap);
}
use of org.roaringbitmap.buffer.MutableRoaringBitmap in project druid by druid-io.
the class WrappedRoaringBitmap method andNot.
@Override
public void andNot(MutableBitmap mutableBitmap) {
WrappedRoaringBitmap other = (WrappedRoaringBitmap) mutableBitmap;
MutableRoaringBitmap unwrappedOtherBitmap = other.bitmap;
bitmap.andNot(unwrappedOtherBitmap);
}
use of org.roaringbitmap.buffer.MutableRoaringBitmap in project pinot by linkedin.
the class BitmapDocIdSetTest method testSimple.
@Test
public void testSimple() throws IOException {
int numBitMaps = 5;
final int numDocs = 1000;
List<ImmutableRoaringBitmap> list = new ArrayList<ImmutableRoaringBitmap>();
Random r = new Random();
TreeSet<Integer> originalSet = new TreeSet<Integer>();
for (int i = 0; i < numBitMaps; i++) {
MutableRoaringBitmap mutableRoaringBitmap = new MutableRoaringBitmap();
int length = r.nextInt(numDocs);
for (int j = 0; j < length; j++) {
int docId = r.nextInt(numDocs);
originalSet.add(docId);
mutableRoaringBitmap.add(docId);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
// could call "rr1.runOptimize()" and "rr2.runOptimize" if there
// there were runs to compress
mutableRoaringBitmap.serialize(dos);
dos.close();
ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray());
ImmutableRoaringBitmap immutableRoaringBitmap = new ImmutableRoaringBitmap(bb);
list.add(immutableRoaringBitmap);
}
ImmutableRoaringBitmap[] bitmaps = new ImmutableRoaringBitmap[list.size()];
list.toArray(bitmaps);
BlockMetadata blockMetadata = new BlockMetadata() {
@Override
public boolean isSparse() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isSorted() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isSingleValue() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean hasInvertedIndex() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean hasDictionary() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getStartDocId() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getMaxNumberOfMultiValues() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getLength() {
return numDocs;
}
@Override
public int getEndDocId() {
return numDocs - 1;
}
@Override
public Dictionary getDictionary() {
// TODO Auto-generated method stub
return null;
}
@Override
public DataType getDataType() {
// TODO Auto-generated method stub
return null;
}
};
BitmapDocIdSet bitmapDocIdSet = new BitmapDocIdSet("testColumn", blockMetadata, 0, numDocs - 1, bitmaps);
BlockDocIdIterator iterator = bitmapDocIdSet.iterator();
int docId;
TreeSet<Integer> result = new TreeSet<Integer>();
while ((docId = iterator.next()) != Constants.EOF) {
result.add(docId);
}
Assert.assertEquals(originalSet.size(), result.size());
Assert.assertEquals(originalSet, result);
}
use of org.roaringbitmap.buffer.MutableRoaringBitmap in project pinot by linkedin.
the class BitmapPerformanceBenchmark method and.
private static ImmutableRoaringBitmap and(List<ImmutableRoaringBitmap> bitMaps) {
if (bitMaps.size() == 1) {
return bitMaps.get(0);
}
MutableRoaringBitmap answer = ImmutableRoaringBitmap.and(bitMaps.get(0), bitMaps.get(1));
long start = System.currentTimeMillis();
for (int i = 2; i < bitMaps.size(); i++) {
answer.and(bitMaps.get(i));
}
long end = System.currentTimeMillis();
int[] cardinality = new int[bitMaps.size()];
int[] sizes = new int[bitMaps.size()];
for (int i = 0; i < bitMaps.size(); i++) {
ImmutableRoaringBitmap immutableRoaringBitmap = bitMaps.get(i);
cardinality[i] = immutableRoaringBitmap.getCardinality();
sizes[i] = immutableRoaringBitmap.getSizeInBytes();
}
bitMaps.get(0).getCardinality();
System.out.println("AND operation Took " + (end - start));
System.out.println("\toutput cardinality:" + answer.getCardinality());
System.out.println("\toutout sizes:" + answer.getSizeInBytes());
return answer;
}
use of org.roaringbitmap.buffer.MutableRoaringBitmap in project pinot by linkedin.
the class HeapBitmapInvertedIndexCreator method seal.
@Override
public void seal() throws IOException {
final DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(invertedIndexFile)));
// First, write out offsets of bitmaps. The information can be used to access a certain bitmap directly.
// Totally (invertedIndex.length+1) offsets will be written out; the last offset is used to calculate the length of
// the last bitmap, which might be needed when accessing bitmaps randomly.
// If a bitmap's offset is k, then k bytes need to be skipped to reach the bitmap.
// The first bitmap's offset
int offset = 4 * (invertedIndex.length + 1);
out.writeInt(offset);
for (final MutableRoaringBitmap element : invertedIndex) {
// the other bitmap's offset
offset += element.serializedSizeInBytes();
out.writeInt(offset);
}
// write out bitmaps one by one
for (final MutableRoaringBitmap element : invertedIndex) {
element.serialize(out);
}
out.close();
LOGGER.debug("persisted bitmap inverted index for column : " + spec.getName() + " in " + invertedIndexFile.getAbsolutePath());
}
Aggregations