@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 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); } };
static final EWAHCompressedBitmap ones(int sizeInBits) { EWAHCompressedBitmap mask = new EWAHCompressedBitmap(); mask.addStreamOfEmptyWords( true, sizeInBits / EWAHCompressedBitmap.WORD_IN_BITS); int remaining = sizeInBits % EWAHCompressedBitmap.WORD_IN_BITS; if (remaining > 0) mask.addWord((1L << remaining) - 1, remaining); return mask; } }
@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); }
return bitmaps[0]; if (bitmaps.length == 2) return bitmaps[0].and(bitmaps[1]); int initialSize = calculateInitialSize(bitmaps); EWAHCompressedBitmap answer = new EWAHCompressedBitmap(initialSize); EWAHCompressedBitmap tmp = new EWAHCompressedBitmap(initialSize); bitmaps[0].andToContainer(bitmaps[1], answer); for (int k = 2; k < bitmaps.length; ++k) { answer.andToContainer(bitmaps[k], tmp); tmp.swap(answer); tmp.clear();
/** * Set the bit at the given index. Throws an exception if bits are not set in strictly ascending order. * For performance reasons, bits must be set in ascending order. * * @param bitToSet The index of the bit to set. */ public void set(final int bitToSet) { // Check that we are setting bits in ascending order (equality with the last value is OK). if (this.bitmap.cardinality() > 0 && bitToSet < this.bitmap.toArray()[this.bitmap.cardinality() - 1]) { throw new IllegalArgumentException("Must set bits in strictly ascending order."); } this.bitmap.set(bitToSet); }
@Override public Bitmap aggregate(Iterable<Bitmap> bitmaps) { final Iterator<Bitmap> i = bitmaps.iterator(); EWAHCompressedBitmap bitmap = ((EwahBitmapWrapper) i.next()).bitmap; while (i.hasNext()) { bitmap = bitmap.or(((EwahBitmapWrapper) i.next()).bitmap); } return new EwahBitmapWrapper(bitmap); } };
final InflatingBitSet or(EWAHCompressedBitmap other) { if (other.sizeInBits() == 0) return this; return new InflatingBitSet(bitmap.or(other), inflated); }
@Override public int cardinality() { return bitmap.cardinality(); }
/** * For speed, this method sets bits at the given index, without checking that the bits * are set in strictly ascending order. If the bits are not in ascending order, performance could be adversely affected. * * @param bitToSet index of the bit to set */ public void setWithoutAscendingCheck(final int bitToSet) { this.bitmap.set(bitToSet); }
/** * Return a bitmap with the bit set to true at the given positions. The * positions should be given in sorted order. * * (This is a convenience method.) * * @param setBits list of set bit positions * @return the bitmap * @since 0.4.5 */ public static EWAHCompressedBitmap bitmapOf(int... setBits) { EWAHCompressedBitmap a = new EWAHCompressedBitmap(); for (int k : setBits) a.set(k); return a; }
@Override public Iterator<BitmapObject> iterator() { final IntIterator dynamic = bitmap.andNot(ones(bitmapIndex.indexObjectCount)) .intIterator(); final IntIterator commits = ofObjectType(Constants.OBJ_COMMIT); final IntIterator trees = ofObjectType(Constants.OBJ_TREE);
@Override public Bitmap andNot(Bitmap other) { return new EwahBitmapWrapper(bitmap.andNot(((EwahBitmapWrapper) other).bitmap)); }
commits = new EWAHCompressedBitmap(sizeInWords); trees = new EWAHCompressedBitmap(sizeInWords); blobs = new EWAHCompressedBitmap(sizeInWords); tags = new EWAHCompressedBitmap(sizeInWords); for (int i = 0; i < objects.size(); i++) { int type = objects.get(i).getType(); switch (type) { case Constants.OBJ_COMMIT: commits.set(i); break; case Constants.OBJ_TREE: trees.set(i); break; case Constants.OBJ_BLOB: blobs.set(i); break; case Constants.OBJ_TAG: tags.set(i); break; default: commits.trim(); trees.trim(); blobs.trim(); tags.trim();
@Override public boolean removeAllOrNone(PackBitmapIndex index) { if (!bitmapIndex.packIndex.equals(index)) return false; EWAHCompressedBitmap curr = bitset.combine() .xor(ones(bitmapIndex.indexObjectCount)); IntIterator ii = curr.intIterator(); if (ii.hasNext() && ii.next() < bitmapIndex.indexObjectCount) return false; bitset = new ComboBitset(curr); return true; }
final InflatingBitSet xor(EWAHCompressedBitmap other) { if (isEmpty()) { if (other.sizeInBits() == 0) return this; return new InflatingBitSet(other); } return new InflatingBitSet(bitmap.xor(other)); }
private static EWAHCompressedBitmap readBitmap(DataInput dataInput) throws IOException { EWAHCompressedBitmap bitmap = new EWAHCompressedBitmap(); bitmap.deserialize(dataInput); return bitmap; } }
/** * Gets the highest bit that is set in the bitmap. * * @return The highest bit. */ public int getHighestBit() { return this.bitmap.cardinality() > 0 ? this.bitmap.toArray()[this.bitmap.cardinality() - 1] : 0; }
@Override public BitmapIterator iterator() { return new EwahIteratorWrapper(bitmap.intIterator()); }
@Override public void serialize(DataOutputStream dos) throws IOException { bitmap.serialize(dos); }