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

The following examples show how to use org.roaringbitmap.RoaringBitmap#deserialize() . 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: TestMemoryMapping.java    From RoaringBitmap with Apache License 2.0 6 votes vote down vote up
@Test
public void oneFormat() throws IOException {
  System.out.println("[TestMemoryMapping] testing format compatibility");
  final int ms = mappedbitmaps.size();
  for (int k = 0; k < ms; ++k) {
    System.out.println("[TestMemoryMapping] testing compat. bitmap " + k + " out of " + ms);
    ImmutableRoaringBitmap rr = mappedbitmaps.get(k);
    ByteArrayOutputStream bos = new ByteArrayOutputStream(rr.serializedSizeInBytes());
    DataOutputStream dos = new DataOutputStream(bos);
    rr.serialize(dos);
    dos.close();
    byte[] arr = bos.toByteArray();
    bos = null;
    ByteArrayInputStream bis = new ByteArrayInputStream(arr);
    RoaringBitmap newr = new RoaringBitmap();
    newr.deserialize(new DataInputStream(bis));
    arr = null;
    RoaringBitmap rrasroaring = rr.toRoaringBitmap();
    assertEquals(newr, rrasroaring);
    System.out
        .println("[TestMemoryMapping] testing compat. bitmap " + k + " out of " + ms + ". ok.");
  }
  System.out.println("[TestMemoryMapping] Format compatibility ok");

}
 
Example 3
Source File: RoaringBitMapUtils.java    From yuvi with Apache License 2.0 5 votes vote down vote up
public static RoaringBitmap toRoaringBitmap(ByteBuffer bb) {
  RoaringBitmap rb = new RoaringBitmap();
  try {
    rb.deserialize(new DataInputStream(new ByteBufferBackedInputStream(bb)));
  } catch (IOException e) {
    e.printStackTrace();
  }
  return rb;
}
 
Example 4
Source File: SerdeUtils.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static RoaringBitmap deserializeRoaring(@CheckForNull final byte[] b) {
    final RoaringBitmap bitmap = new RoaringBitmap();
    try {
        bitmap.deserialize(
            new DataInputStream(new FastByteArrayInputStream(Objects.requireNonNull(b))));
    } catch (IOException e) {
        throw new IllegalStateException("Failed to deserialize RoaringBitmap", e);
    }
    return bitmap;
}
 
Example 5
Source File: TestMemoryMapping.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
public static RoaringBitmap toRoaringBitmap(ByteBuffer bb) {
  RoaringBitmap rb = new RoaringBitmap();
  try {
    rb.deserialize(new DataInputStream(new ByteBufferBackedInputStream(bb)));
  } catch (IOException e) {
    e.printStackTrace();
  }
  return rb;
}
 
Example 6
Source File: RealDataSerializationBenchmark.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void bufferBackedDataInput(BenchmarkState state, Blackhole bh) throws IOException {
    byte[][] buffers = state.buffers;
    for (int i = 0; i < buffers.length; ++i) {
        RoaringBitmap bitmap = new RoaringBitmap();
        bitmap.deserialize(new BufferDataInput(ByteBuffer.wrap(state.buffers[i])));
        bh.consume(bitmap);
    }
}
 
Example 7
Source File: RealDataSerializationBenchmark.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void streamBackedDataInputWithBuffer(BenchmarkState state, Blackhole bh) throws IOException {
  byte[][] buffers = state.buffers;
  for (int i = 0; i < buffers.length; ++i) {
    RoaringBitmap bitmap = new RoaringBitmap();
    ByteArrayInputStream bis = new ByteArrayInputStream(state.buffers[i]);
    bitmap.deserialize(new DataInputStream(bis), null);
    bh.consume(bitmap);
  }
}
 
Example 8
Source File: RealDataSerializationBenchmark.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void streamBackedDataInput(BenchmarkState state, Blackhole bh) throws IOException {
  byte[][] buffers = state.buffers;
  for (int i = 0; i < buffers.length; ++i) {
    RoaringBitmap bitmap = new RoaringBitmap();
    ByteArrayInputStream bis = new ByteArrayInputStream(state.buffers[i]);
    bitmap.deserialize(new DataInputStream(bis));
    bh.consume(bitmap);
  }
}
 
Example 9
Source File: RealDataSerializationBenchmark.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Benchmark
public void directToBuffer(BenchmarkState state, Blackhole bh) throws IOException {
  byte[][] buffers = state.buffers;
  for (int i = 0; i < buffers.length; ++i) {
    RoaringBitmap bitmap = new RoaringBitmap();
    bitmap.deserialize(ByteBuffer.wrap(state.buffers[i]));
    bh.consume(bitmap);
  }
}