@Override public int last() { return bitmap.reverseIntIterator().next(); }
@Override public boolean contains(int i) { return bitmap.get(i); }
@Override public int cardinality() { return bitmap.cardinality(); }
@Benchmark public int horizontalOr_EWAH(BenchmarkState benchmarkState) { EWAHCompressedBitmap[] a = new EWAHCompressedBitmap[benchmarkState.ewah.size()]; EWAHCompressedBitmap bitmapor = EWAHCompressedBitmap.or(benchmarkState.ewah.toArray(a)); int answer = bitmapor.cardinality(); return answer; }
@Override public Bitmap flip(int rangeStart, int rangeEnd) { // synthesized with 2-upper-bounded NOTs // unfortunately, cannot be used with an immutable bitmap. // for that case, could synthesize from XOR and a mask for the range int savedSize = bitmap.sizeInBits(); EWAHCompressedBitmap temp = null; try { temp = (EWAHCompressedBitmap) bitmap.clone(); } catch (CloneNotSupportedException e) { } ; temp.setSizeInBits(rangeEnd, false); temp.not(); if (rangeStart != 0) { temp.setSizeInBits(rangeStart - 1, false); temp.not(); } temp.setSizeInBits(savedSize, false); return new EwahBitmapWrapper(temp); }
@Override public Bitmap and(Bitmap other) { return new EwahBitmapWrapper(bitmap.and(((EwahBitmapWrapper) other).bitmap)); }
@Override public Bitmap or(Bitmap other) { return new EwahBitmapWrapper(bitmap.or(((EwahBitmapWrapper) other).bitmap)); }
@Override public int last() { return bitmap.reverseIntIterator().next(); }
@Override public Bitmap andNot(Bitmap other) { return new EwahBitmapWrapper(bitmap.andNot(((EwahBitmapWrapper) other).bitmap)); }
@Override public void serialize(DataOutputStream dos) throws IOException { bitmap.serialize(dos); }
@Override public boolean hasNext() { return iterator.hasNext(); }
@Override public int next() { return iterator.next(); }
public static Bitmap newImmutableEwahBitmap(int[] data) throws Exception { ByteBuffer bb = toByteBuffer(newEwahBitmap(data)); EWAHCompressedBitmap ewah = new EWAHCompressedBitmap(bb); return new EwahBitmapWrapper(ewah); }
@Override public BitmapIterator iterator() { return new EwahIteratorWrapper(bitmap.intIterator()); }
@Override public Bitmap xor(Bitmap other) { return new EwahBitmapWrapper(bitmap.xor(((EwahBitmapWrapper) other).bitmap)); }
public static Bitmap newEwahBitmap(int[] data) { EWAHCompressedBitmap ewah = EWAHCompressedBitmap.bitmapOf(data); return new EwahBitmapWrapper(ewah); }
@Override public Bitmap clone() { try { return new EwahBitmapWrapper(bitmap.clone()); } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } }
@Override public BitmapIterator reverseIterator() { return new EwahIteratorWrapper(bitmap.reverseIntIterator()); }
@Override public Bitmap aggregate(final Iterable<Bitmap> bitmaps) { Iterator<EWAHCompressedBitmap> iterator = new Iterator<EWAHCompressedBitmap>() { final Iterator<Bitmap> i = bitmaps.iterator(); @Override public boolean hasNext() { return i.hasNext(); } @Override public EWAHCompressedBitmap next() { return ((EwahBitmapWrapper) i.next()).bitmap; } @Override public void remove() { throw new UnsupportedOperationException(); } }; return new EwahBitmapWrapper(FastAggregation.or(iterator)); } };
@Override public Bitmap aggregate(Iterable<Bitmap> bitmaps) { final Iterator<Bitmap> i = bitmaps.iterator(); EWAHCompressedBitmap bitmap = ((EwahBitmapWrapper) i.next()).bitmap; while (i.hasNext()) { bitmap = bitmap.and(((EwahBitmapWrapper) i.next()).bitmap); } return new EwahBitmapWrapper(bitmap); } };