Java Code Examples for org.roaringbitmap.RoaringBitmap#bitmapOf()

The following examples show how to use org.roaringbitmap.RoaringBitmap#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: SerializeToByteArrayExample.java    From RoaringBitmap with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  RoaringBitmap mrb = RoaringBitmap.bitmapOf(1, 2, 3, 1000);
  System.out.println("starting with  bitmap " + mrb);
  mrb.runOptimize(); // to improve compression
  byte[] array = new byte[mrb.serializedSizeInBytes()];
  mrb.serialize(ByteBuffer.wrap(array));
  RoaringBitmap ret = new RoaringBitmap();
  try {
    ret.deserialize(ByteBuffer.wrap(array));
  } catch(IOException ioe) {
    ioe.printStackTrace(); // should not happen
  }
  if (!ret.equals(mrb))
    throw new RuntimeException("bug");
  System.out.println("decoded from byte array : " + ret);

}
 
Example 2
Source File: Basic.java    From RoaringBitmap with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
      RoaringBitmap rr = RoaringBitmap.bitmapOf(1,2,3,1000);
      RoaringBitmap rr2 = new RoaringBitmap();
      rr2.add(4000L,4255L);

      RoaringBitmap rror = RoaringBitmap.or(rr, rr2);// new bitmap
      rr.or(rr2); //in-place computation
      boolean equals = rror.equals(rr);// true
      if(!equals) throw new RuntimeException("bug");
      // number of values stored?
      long cardinality = rr.getLongCardinality();
      System.out.println(cardinality);
      // a "forEach" is faster than this loop, but a loop is possible:
      for(int i : rr) {
        System.out.println(i);
      }
}
 
Example 3
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 4
Source File: LSH.java    From ache with Apache License 2.0 5 votes vote down vote up
@Override
public void insertToBand(int band, int[] hashes, int id) {
    String hexkey = toHex(band, hashes);
    RoaringBitmap idsBitmap = maps.get(hexkey);
    if (idsBitmap == null) {
        idsBitmap = RoaringBitmap.bitmapOf(id);
        maps.put(hexkey, idsBitmap);
    } else {
        idsBitmap.add(id);
    }
}
 
Example 5
Source File: IntervalCheck.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
      // some bitmap
      RoaringBitmap rr = RoaringBitmap.bitmapOf(1,2,3,1000);

      // we want to check if it intersects a given range [10,1000]
      int low = 10;
      int high = 1000;
      RoaringBitmap range = new RoaringBitmap();
      range.add((long)low, (long)high + 1);
      //
      //

      System.out.println(RoaringBitmap.intersects(rr,range)); // prints true if they intersect
}
 
Example 6
Source File: SlowORaggregate1.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()) {
    RoaringBitmap basic = RoaringBitmap.bitmapOf(data);
    basic.runOptimize();
    rc.add(basic);
  }
  System.out.println("loaded " + rc.size() + " bitmaps");
}
 
Example 7
Source File: SlowORaggregate3.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()) {
    RoaringBitmap basic = RoaringBitmap.bitmapOf(data);
    basic.runOptimize();
    rc.add(basic);
  }
  System.out.println("loaded " + rc.size() + " bitmaps");
}
 
Example 8
Source File: SlowORaggregate2.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()) {
    RoaringBitmap basic = RoaringBitmap.bitmapOf(data);
    basic.runOptimize();
    rc.add(basic);
  }
  System.out.println("loaded " + rc.size() + " bitmaps");
}
 
Example 9
Source File: RunContainerRealDataBenchmarkRunOptimize.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()) {
    RoaringBitmap basic = RoaringBitmap.bitmapOf(data);
    ac.add(basic);
    RoaringBitmap opti = basic.clone();
    opti.runOptimize();
    rc.add(opti);
  }
}
 
Example 10
Source File: BitmapFactory.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
private static Bitmap newRoaringBitmap(int[] data, boolean optimize) {
  RoaringBitmap roaring = RoaringBitmap.bitmapOf(data);
  if (optimize) {
    roaring.runOptimize();
  }
  return new RoaringBitmapWrapper(roaring);
}
 
Example 11
Source File: WriteUnordered.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
@Benchmark
public RoaringBitmap sortThenBitmapOf() {
  int[] copy = Arrays.copyOf(data, data.length);
  Arrays.sort(copy);
  return RoaringBitmap.bitmapOf(copy);
}
 
Example 12
Source File: WriteUnordered.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
@Benchmark
public RoaringBitmap bitmapOf() {
  int[] copy = Arrays.copyOf(data, data.length);
  return RoaringBitmap.bitmapOf(copy);
}
 
Example 13
Source File: WriteUnordered.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
@Benchmark
public RoaringBitmap partialSortThenBitmapOf() {
  int[] copy = Arrays.copyOf(data, data.length);
  Util.partialRadixSort(copy);
  return RoaringBitmap.bitmapOf(copy);
}