@Override public BitmapCounter newBitmap(ByteBuffer in) throws IOException { RoaringBitmapCounter counter = new RoaringBitmapCounter(); counter.readFields(in); return counter; } }
@Override public String toString() { return "RoaringBitmapCounter[" + getCount() + "]"; } }
@Override public void orWith(BitmapCounter another) { if (another instanceof RoaringBitmapCounter) { RoaringBitmapCounter input = (RoaringBitmapCounter) another; getMutableBitmap().or(input.bitmap); return; } throw new IllegalArgumentException("Unsupported type: " + another.getClass().getCanonicalName()); }
@Override public BitmapCounter newBitmap() { return new RoaringBitmapCounter(); }
@Override public void readFields(ByteBuffer in) throws IOException { int size = peekLength(in); // make a copy of the content to be safe byte[] dst = new byte[size]; in.get(dst); // ImmutableRoaringBitmap only maps the buffer, thus faster than constructing a MutableRoaringBitmap. // we'll convert to MutableRoaringBitmap later when mutate is needed bitmap = new ImmutableRoaringBitmap(ByteBuffer.wrap(dst)); }
@Override public BitmapCounter newBitmap(long counter) { return new RoaringBitmapCounter(counter); }
@Override public void readFields(ByteBuffer in) throws IOException { int size = peekLength(in); // make a copy of the content to be safe byte[] dst = new byte[size]; in.get(dst); // ImmutableRoaringBitmap only maps the buffer, thus faster than constructing a MutableRoaringBitmap. // we'll convert to MutableRoaringBitmap later when mutate is needed bitmap = new ImmutableRoaringBitmap(ByteBuffer.wrap(dst)); }
@Override public void andWith(BitmapCounter another) { if (another instanceof RoaringBitmapCounter) { RoaringBitmapCounter input = (RoaringBitmapCounter) another; getMutableBitmap().and(input.bitmap); return; } throw new IllegalArgumentException("Unsupported type: " + another.getClass().getCanonicalName()); }
@Override public BitmapCounter newBitmap(ByteBuffer in) throws IOException { RoaringBitmapCounter counter = new RoaringBitmapCounter(); counter.readFields(in); return counter; } }
@Override public BitmapCounter newBitmap(int... values) { return new RoaringBitmapCounter(MutableRoaringBitmap.bitmapOf(values)); }
@Override public String toString() { return "RoaringBitmapCounter[" + getCount() + "]"; } }
@Override public void add(int value) { getMutableBitmap().add(value); }
@Override public BitmapCounter newBitmap() { return new RoaringBitmapCounter(); }
@Override public void write(ByteBuffer out) throws IOException { if (bitmap instanceof MutableRoaringBitmap) { getMutableBitmap().runOptimize(); } if (out.remaining() < bitmap.serializedSizeInBytes()) { throw new BufferOverflowException(); } try (DataOutputStream dos = new DataOutputStream(new ByteBufferOutputStream(out))) { bitmap.serialize(dos); } }
@Override public BitmapCounter newBitmap(long counter) { return new RoaringBitmapCounter(counter); }
@Override public void orWith(BitmapCounter another) { if (another instanceof RoaringBitmapCounter) { RoaringBitmapCounter input = (RoaringBitmapCounter) another; getMutableBitmap().or(input.bitmap); return; } throw new IllegalArgumentException("Unsupported type: " + another.getClass().getCanonicalName()); }
@Override public BitmapCounter newBitmap(int... values) { return new RoaringBitmapCounter(MutableRoaringBitmap.bitmapOf(values)); }
@Override public void andWith(BitmapCounter another) { if (another instanceof RoaringBitmapCounter) { RoaringBitmapCounter input = (RoaringBitmapCounter) another; getMutableBitmap().and(input.bitmap); return; } throw new IllegalArgumentException("Unsupported type: " + another.getClass().getCanonicalName()); }
@Override public void add(int value) { getMutableBitmap().add(value); }
@Override public void write(ByteBuffer out) throws IOException { if (bitmap instanceof MutableRoaringBitmap) { getMutableBitmap().runOptimize(); } if (out.remaining() < bitmap.serializedSizeInBytes()) { throw new BufferOverflowException(); } try (DataOutputStream dos = new DataOutputStream(new ByteBufferOutputStream(out))) { bitmap.serialize(dos); } }