Java Code Examples for org.roaringbitmap.buffer.MutableRoaringBitmap#bitmapOf()

The following examples show how to use org.roaringbitmap.buffer.MutableRoaringBitmap#bitmapOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SerializationBenchmark.java    From RoaringBitmap with Apache License 2.0 6 votes vote down vote up
public BenchmarkState() {

      final int[] data = takeSortedAndDistinct(new Random(0xcb000a2b9b5bdfb6l), 100000);
      bitmap_a = RoaringBitmap.bitmapOf(data);
      bitmap_ar = MutableRoaringBitmap.bitmapOf(data);
      for (int k = 100000; k < 200000; ++k) {
        bitmap_a.add(2 * k);
        bitmap_ar.add(2 * k);
      }
      outbb = ByteBuffer.allocate(bitmap_a.serializedSizeInBytes());
      presoutbb = ByteBuffer.allocate(bitmap_a.serializedSizeInBytes());
      ByteBufferBackedOutputStream out = new ByteBufferBackedOutputStream(presoutbb);
      try {
        bitmap_a.serialize(new DataOutputStream(out));
      } catch (Exception e) {
        e.printStackTrace();
      }
      presoutbb.flip();
    }
 
Example 2
Source File: InvertedIndexTagStore.java    From yuvi with Apache License 2.0 5 votes vote down vote up
private void addToMetricIndex(final String key, final Integer id) {
  if (metricIndex.containsKey(key)) {
    MutableRoaringBitmap currentMap = lookupMetricIndex(key).toMutableRoaringBitmap();
    currentMap.add(id);
    metricIndex.put(key, RoaringBitMapUtils.toByteBuffer(currentMap));
  } else {
    MutableRoaringBitmap newMap = MutableRoaringBitmap.bitmapOf(id);
    metricIndex.put(key, RoaringBitMapUtils.toByteBuffer(newMap));
  }
}
 
Example 3
Source File: SlowMappedORaggregate1.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Setup
public void setup() throws Exception {
  ZipRealDataRetriever dataRetriever = new ZipRealDataRetriever(dataset);
  System.out.println();
  System.out.println("Loading files from " + dataRetriever.getName());
  ArrayList<MutableRoaringBitmap> tmprc = new ArrayList<MutableRoaringBitmap>();

  for (int[] data : dataRetriever.fetchBitPositions()) {
    MutableRoaringBitmap basic = MutableRoaringBitmap.bitmapOf(data);
    basic.runOptimize();
    tmprc.add(basic);
  }
  rc = convertToImmutableRoaring(tmprc);
}
 
Example 4
Source File: SlowMappedORaggregate2.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Setup
public void setup() throws Exception {
  ZipRealDataRetriever dataRetriever = new ZipRealDataRetriever(dataset);
  System.out.println();
  System.out.println("Loading files from " + dataRetriever.getName());
  ArrayList<MutableRoaringBitmap> tmprc = new ArrayList<MutableRoaringBitmap>();

  for (int[] data : dataRetriever.fetchBitPositions()) {
    MutableRoaringBitmap basic = MutableRoaringBitmap.bitmapOf(data);
    basic.runOptimize();
    tmprc.add(basic);
  }
  rc = convertToImmutableRoaring(tmprc);
}
 
Example 5
Source File: MappedRunContainerRealDataBenchmarkRunOptimize.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Setup
public void setup() throws Exception {
  ZipRealDataRetriever dataRetriever = new ZipRealDataRetriever(dataset);
  System.out.println();
  System.out.println("Loading files from " + dataRetriever.getName());

  for (int[] data : dataRetriever.fetchBitPositions()) {
    MutableRoaringBitmap mbasic = MutableRoaringBitmap.bitmapOf(data);
    mac.add(mbasic);
    MutableRoaringBitmap mopti = mbasic.clone();
    mopti.runOptimize();
    mrc.add(mopti);
  }
}
 
Example 6
Source File: RoaringBitmapCounterFactory.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public BitmapCounter newBitmap(int... values) {
    return new RoaringBitmapCounter(MutableRoaringBitmap.bitmapOf(values));
}
 
Example 7
Source File: RoaringBitmapCounterFactory.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public BitmapCounter newBitmap(int... values) {
    return new RoaringBitmapCounter(MutableRoaringBitmap.bitmapOf(values));
}
 
Example 8
Source File: TestSerialization.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
@BeforeAll
public static void init() throws IOException {
  final int[] data = takeSortedAndDistinct(new Random(0xcb000a2b9b5bdfb6L), 100000);
  bitmap_a = RoaringBitmap.bitmapOf(data);
  bitmap_ar = MutableRoaringBitmap.bitmapOf(data);
  bitmap_a1 = RoaringBitmap.bitmapOf(data);

  for (int k = 100000; k < 200000; ++k) {
    bitmap_a.add(3 * k); // bitmap density and too many little runs
    bitmap_ar.add(3 * k);
    bitmap_a1.add(3 * k);
  }

  for (int k = 700000; k < 800000; ++k) { // runcontainer would be best
    bitmap_a.add(k);
    bitmap_ar.add(k);
    bitmap_a1.add(k);
  }

  bitmap_a.runOptimize(); // mix of all 3 container kinds
  bitmap_ar.runOptimize(); // must stay in sync with bitmap_a
  /*
   * There is potentially some "slop" betweeen the size estimates used for RoaringBitmaps and
   * MutableRoaringBitmaps, so it is risky to assume that they will both *always* agree whether to
   * run encode a container. Nevertheless testMutableSerialize effectively does that, by using the
   * serialized size of one as the output buffer size for the other.
   */
  // do not runoptimize bitmap_a1

  outbb = ByteBuffer
      .allocate(bitmap_a.serializedSizeInBytes() + bitmap_empty.serializedSizeInBytes());
  presoutbb = ByteBuffer
      .allocate(bitmap_a.serializedSizeInBytes() + bitmap_empty.serializedSizeInBytes());
  ByteBufferBackedOutputStream out = new ByteBufferBackedOutputStream(presoutbb);

  DataOutputStream dos = new DataOutputStream(out);
  bitmap_empty.serialize(dos);
  bitmap_a.serialize(dos);
  presoutbb.flip();

}
 
Example 9
Source File: TestSerialization.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
@Test
public void testMutableRunSerializationBasicDeserialization() throws java.io.IOException {
  final int[] data = takeSortedAndDistinct(new Random(07734), 100000);
  RoaringBitmap bitmap_a = RoaringBitmap.bitmapOf(data);
  RoaringBitmap bitmap_ar = RoaringBitmap.bitmapOf(data);

  MutableRoaringBitmap bitmap_am = MutableRoaringBitmap.bitmapOf(data);
  MutableRoaringBitmap bitmap_amr = MutableRoaringBitmap.bitmapOf(data);

  for (int k = 100000; k < 200000; ++k) {
    bitmap_a.add(3 * k); // bitmap density and too many little runs
    bitmap_ar.add(3 * k);
    bitmap_am.add(3 * k);
    bitmap_amr.add(3 * k);
  }

  for (int k = 700000; k < 800000; ++k) { // will choose a runcontainer on this
    bitmap_a.add(k); // bitmap density and too many little runs
    bitmap_ar.add(k);
    bitmap_am.add(k);
    bitmap_amr.add(k);    
  }

  bitmap_ar.runOptimize();
  bitmap_amr.runOptimize();
  assertEquals(bitmap_a, bitmap_ar);
  assertEquals(bitmap_am, bitmap_amr);
  assertEquals(bitmap_am.serializedSizeInBytes(), bitmap_a.serializedSizeInBytes());
  assertEquals(bitmap_amr.serializedSizeInBytes(), bitmap_ar.serializedSizeInBytes());

  ByteBuffer outbuf = ByteBuffer.allocate(2*(bitmap_a.serializedSizeInBytes() + bitmap_ar.serializedSizeInBytes()));
  DataOutputStream out = new DataOutputStream(new ByteBufferBackedOutputStream(outbuf));
  try {
    bitmap_a.serialize(out);
    bitmap_ar.serialize(out);
    bitmap_am.serialize(out);
    bitmap_amr.serialize(out);
  } catch (Exception e) {
    e.printStackTrace();
  }
  outbuf.flip();

  RoaringBitmap bitmap_c1 = new RoaringBitmap();
  RoaringBitmap bitmap_c2 = new RoaringBitmap();
  RoaringBitmap bitmap_c3 = new RoaringBitmap();
  RoaringBitmap bitmap_c4 = new RoaringBitmap();

  DataInputStream in = new DataInputStream(new ByteBufferBackedInputStream(outbuf));
  bitmap_c1.deserialize(in);
  bitmap_c2.deserialize(in);
  bitmap_c3.deserialize(in);
  bitmap_c4.deserialize(in);

  assertEquals(bitmap_a, bitmap_c1);
  assertEquals(bitmap_a, bitmap_c2);
  assertEquals(bitmap_a, bitmap_c3);
  assertEquals(bitmap_a, bitmap_c4);
  assertEquals(bitmap_ar, bitmap_c1);
  assertEquals(bitmap_ar, bitmap_c2);
  assertEquals(bitmap_ar, bitmap_c3);
  assertEquals(bitmap_ar, bitmap_c4);

}