public static Bitmap newImmutableEwah32Bitmap(int[] data) throws Exception { ByteBuffer bb = toByteBuffer(newEwah32Bitmap(data)); EWAHCompressedBitmap32 ewah = new EWAHCompressedBitmap32(bb); return new Ewah32BitmapWrapper(ewah); }
@Override public Bitmap aggregate(Iterable<Bitmap> bitmaps) { final Iterator<Bitmap> i = bitmaps.iterator(); EWAHCompressedBitmap32 bitmap = ((Ewah32BitmapWrapper) i.next()).bitmap; while (i.hasNext()) { bitmap = bitmap.and(((Ewah32BitmapWrapper) i.next()).bitmap); } return new Ewah32BitmapWrapper(bitmap); } };
@Benchmark public int horizontalOr_EWAH32(BenchmarkState benchmarkState) { EWAHCompressedBitmap32[] a = new EWAHCompressedBitmap32[benchmarkState.ewah32.size()]; EWAHCompressedBitmap32 bitmapor = EWAHCompressedBitmap32.or(benchmarkState.ewah32.toArray(a)); int answer = bitmapor.cardinality(); return answer; }
@Override public Bitmap flip(int rangeStart, int rangeEnd) { // synthesized with 2-upper-bounded NOTs int savedSize = bitmap.sizeInBits(); EWAHCompressedBitmap32 temp = null; try { temp = (EWAHCompressedBitmap32) 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 Ewah32BitmapWrapper(temp); }
return bitmaps[0]; if (bitmaps.length == 2) return bitmaps[0].and(bitmaps[1]); int initialSize = calculateInitialSize(bitmaps); EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(initialSize); EWAHCompressedBitmap32 tmp = new EWAHCompressedBitmap32(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();
@Override public EWAHIterator32 next() { this.buffer.clear(); IteratorAggregation32.andToContainer(this.buffer, this.bufferSize * this.ll.size(), this.ll.get(0), this.ll.get(1)); if (this.ll.size() > 2) { Iterator<IteratingRLW32> i = this.ll.iterator(); i.next(); i.next(); EWAHCompressedBitmap32 tmpbuffer = new EWAHCompressedBitmap32(); while (i.hasNext() && this.buffer.sizeInBytes() > 0) { IteratorAggregation32 .andToContainer(tmpbuffer, this.buffer.getIteratingRLW(), i.next()); this.buffer.swap(tmpbuffer); tmpbuffer.clear(); } } for (IteratingRLW32 aLl : this.ll) { if (aLl.size() == 0) { this.ll.clear(); break; } } return this.buffer.getEWAHIterator(); }
/** * Simple algorithm that computes the OR aggregate. * * @param bitmaps input bitmaps * @return new bitmap containing the aggregate */ public static EWAHCompressedBitmap32 or(final Iterator<EWAHCompressedBitmap32> bitmaps) { PriorityQueue<EWAHCompressedBitmap32> pq = new PriorityQueue<EWAHCompressedBitmap32>(32, new Comparator<EWAHCompressedBitmap32>() { @Override public int compare(EWAHCompressedBitmap32 a, EWAHCompressedBitmap32 b) { return a.sizeInBytes() - b.sizeInBytes(); } } ); while(bitmaps.hasNext()) pq.add(bitmaps.next()); if(pq.isEmpty()) return new EWAHCompressedBitmap32(); while (pq.size() > 1) { EWAHCompressedBitmap32 x1 = pq.poll(); EWAHCompressedBitmap32 x2 = pq.poll(); pq.add(x1.or(x2)); } return pq.poll(); }
/** * Simple algorithm that computes the XOR aggregate. * * @param bitmaps input bitmaps * @return new bitmap containing the aggregate */ public static EWAHCompressedBitmap32 xor(final EWAHCompressedBitmap32... bitmaps) { PriorityQueue<EWAHCompressedBitmap32> pq = new PriorityQueue<EWAHCompressedBitmap32>(bitmaps.length, new Comparator<EWAHCompressedBitmap32>() { @Override public int compare(EWAHCompressedBitmap32 a, EWAHCompressedBitmap32 b) { return a.sizeInBytes() - b.sizeInBytes(); } } ); Collections.addAll(pq, bitmaps); if(pq.isEmpty()) return new EWAHCompressedBitmap32(); while (pq.size() > 1) { EWAHCompressedBitmap32 x1 = pq.poll(); EWAHCompressedBitmap32 x2 = pq.poll(); pq.add(x1.xor(x2)); } return pq.poll(); }
EWAHCompressedBitmap32 set = new EWAHCompressedBitmap32(); set.set(0); set.set(1000000);
final BitmapStorage32 container) { container.clear(); final EWAHIterator32 i = a.getEWAHIterator(); final EWAHIterator32 j = getEWAHIterator(); final IteratingBufferedRunningLengthWord32 rlwi = new IteratingBufferedRunningLengthWord32( i); : rlwj; remaining.discharge(container); container.setSizeInBitsWithinLastWord(Math.max(sizeInBits(), a.sizeInBits()));
EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(newsz); IteratingRLW32 i = this.getIteratingRLW(); int fullwords = b / WORD_IN_BITS; int shift = b % WORD_IN_BITS; answer.addStreamOfEmptyWords(false, fullwords); if (shift == 0) { answer.buffer.push_back(this.buffer, 0, sz); if (i.getRunningBit()) { int sw = w | (-1 << shift); answer.addWord(sw); w = -1 >>> (WORD_IN_BITS - shift); } else { answer.addWord(w); w = 0; answer.addStreamOfEmptyWords(i.getRunningBit(), rl - 1); int neww = i.getLiteralWordAt(k); int sw = w | (neww << shift); answer.addWord(sw); w = neww >>> (WORD_IN_BITS - shift); if(shiftextension) answer.addWord(w); break;
/** * Compute a Boolean threshold function: bits are true where at least T * bitmaps have a true bit. * * @param t the threshold * @param bitmaps input data * @return the aggregated bitmap * @since 0.8.2 */ public static EWAHCompressedBitmap32 threshold(final int t, final EWAHCompressedBitmap32... bitmaps) { final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(); thresholdWithContainer(container, t, bitmaps); return container; }
/** * Returns a new compressed bitmap containing the bitwise AND values of * the current bitmap with some other bitmap. The current bitmap * is not modified. * * The running time is proportional to the sum of the compressed sizes * (as reported by sizeInBytes()). * * If you are not planning on adding to the resulting bitmap, you may * call the trim() method to reduce memory usage. * * @param a the other bitmap (it will not be modified) * @return the EWAH compressed bitmap */ @Override public EWAHCompressedBitmap32 and(final EWAHCompressedBitmap32 a) { int size = this.buffer.sizeInWords() > a.buffer.sizeInWords() ? this.buffer.sizeInWords() : a.buffer.sizeInWords(); final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(size); andToContainer(a, container); return container; }
/** * Returns a new compressed bitmap containing the bitwise XOR values of * the current bitmap with some other bitmap. * * The running time is proportional to the sum of the compressed sizes * (as reported by sizeInBytes()). * * If you are not planning on adding to the resulting bitmap, you may * call the trim() method to reduce memory usage. * * The current bitmap is not modified. * * @param a the other bitmap (it will not be modified) * @return the EWAH compressed bitmap */ @Override public EWAHCompressedBitmap32 xor(final EWAHCompressedBitmap32 a) { int size = this.buffer.sizeInWords() + a.buffer.sizeInWords(); final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(size); xorToContainer(a, container); return container; }
/** * Returns a new compressed bitmap containing the bitwise AND NOT values * of the current bitmap with some other bitmap. The current bitmap * is not modified. * * The running time is proportional to the sum of the compressed sizes * (as reported by sizeInBytes()). * * If you are not planning on adding to the resulting bitmap, you may * call the trim() method to reduce memory usage. * * @param a the other bitmap (it will not be modified) * @return the EWAH compressed bitmap */ @Override public EWAHCompressedBitmap32 andNot(final EWAHCompressedBitmap32 a) { int size = this.buffer.sizeInWords() > a.buffer.sizeInWords() ? this.buffer.sizeInWords() : a.buffer.sizeInWords(); final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(size); andNotToContainer(a, container); return container; }
/** * Returns a new compressed bitmap containing the bitwise OR values of * the current bitmap with some other bitmap. * * The running time is proportional to the sum of the compressed sizes * (as reported by sizeInBytes()). * * If you are not planning on adding to the resulting bitmap, you may * call the trim() method to reduce memory usage. * * The current bitmap is not modified. * * @param a the other bitmap (it will not be modified) * @return the EWAH compressed bitmap */ @Override public EWAHCompressedBitmap32 or(final EWAHCompressedBitmap32 a) { int size = this.buffer.sizeInWords() + a.buffer.sizeInWords(); final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(size); orToContainer(a, container); return container; }
/** * Returns a new compressed bitmap containing the composition of * the current bitmap with some other bitmap. * * The composition A.compose(B) is defined as follows: we retain * the ith set bit of A only if the ith bit of B is set. For example, * if you have the following bitmap A = { 0, 1, 0, 1, 1, 0 } and want * to keep only the second and third ones, you can call A.compose(B) * with B = { 0, 1, 1 } and you will get C = { 0, 0, 0, 1, 1, 0 }. * * * If you are not planning on adding to the resulting bitmap, you may * call the trim() method to reduce memory usage. * * The current bitmap is not modified. * * @param a the other bitmap (it will not be modified) * @return the EWAH compressed bitmap */ @Override public EWAHCompressedBitmap32 compose(EWAHCompressedBitmap32 a) { int size = this.buffer.sizeInWords(); final EWAHCompressedBitmap32 container = new EWAHCompressedBitmap32(size); composeToContainer(a, container); return container; }
container.clear(); final ChunkIterator iterator = chunkIterator(); final ChunkIterator aIterator = a.chunkIterator(); int index = 0; while(iterator.hasNext() && aIterator.hasNext()) { int length = iterator.nextLength(); index += length; container.setSizeInBits(index, false); iterator.move(length); } else { int length = Math.min(iterator.nextLength(), aIterator.nextLength()); index += length; container.setSizeInBits(index, aIterator.nextBit()); iterator.move(length); aIterator.move(length); container.setSizeInBits(sizeInBits, false);
@Override public Bitmap clone() { try { return new Ewah32BitmapWrapper(bitmap.clone()); } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } }
static int maxSizeInBits(final EWAHCompressedBitmap32... bitmaps) { int maxSizeInBits = 0; for(EWAHCompressedBitmap32 bitmap : bitmaps) { maxSizeInBits = Math.max(maxSizeInBits, bitmap.sizeInBits()); } return maxSizeInBits; }