public static Bitmap newImmutableEwah32Bitmap(int[] data) throws Exception { ByteBuffer bb = toByteBuffer(newEwah32Bitmap(data)); EWAHCompressedBitmap32 ewah = new EWAHCompressedBitmap32(bb); return new Ewah32BitmapWrapper(ewah); }
Set<Integer> foo = ImmutableSet.of(1,2,3,4,8,9); Set<Integer> bar = ImmutableSet.of(1,3,8,5,11); EWAHCompressedBitmap32 fooBitmap = new EWAHCompressedBitmap32(); EWAHCompressedBitmap32 barBitmap = new EWAHCompressedBitmap32(); //fill bitmaps foo.stream().forEach(fooBitmap::set); bar.stream().forEach(barBitmap::set); //fooBitmap.and(barBitmap) returns intersection of sets now. fast! ImmutableSet<Integer> intersection = ImmutableSet.<Integer>builder() .addAll(fooBitmap.and(barBitmap)) .build(); System.out.println(intersection);
EWAHCompressedBitmap32 res = sets.stream().collect(Collectors.reducing( //identity null, //mapper set -> compressedBitmap l -> { EWAHCompressedBitmap32 b = new EWAHCompressedBitmap32(); l.stream().forEach(b::set); return b; }, //and-reducer (l, r) -> l == null ? r : l.and(r) ));
Set<Integer> foo = ImmutableSet.of(1,2,3,4,8,9); Set<Integer> bar = ImmutableSet.of(1,3,8,5,11); List<Set<Integer>> sets = ImmutableList.of(foo,bar); EWAHCompressedBitmap32 res = sets.stream().map(l -> { EWAHCompressedBitmap32 b = new EWAHCompressedBitmap32(); l.stream().forEach(b::set); return b; }).reduce(null, (l, r) -> l == null ? r : l.and(r)); System.out.println(res);
/** * Compute the or aggregate using a temporary uncompressed bitmap. * * @param bitmaps the source bitmaps * @param bufSize buffer size used during the computation in 64-bit * words * @return the or aggregate. */ public static EWAHCompressedBitmap32 bufferedor(final int bufSize, final EWAHCompressedBitmap32... bitmaps) { EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(); bufferedorWithContainer(answer, bufSize, bitmaps); return answer; }
/** * 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; }
/** * Compute the or aggregate using a temporary uncompressed bitmap. * * @param bitmaps the source bitmaps * @param bufSize buffer size used during the computation in 64-bit * words * @return the or aggregate. */ public static EWAHCompressedBitmap32 bufferedor(final int bufSize, final EWAHCompressedBitmap32... bitmaps) { EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(); bufferedorWithContainer(answer, bufSize, bitmaps); return answer; }
/** * Compute the xor aggregate using a temporary uncompressed bitmap. * * @param bitmaps the source bitmaps * @param bufSize buffer size used during the computation in 64-bit * words * @return the xor aggregate. */ public static EWAHCompressedBitmap32 bufferedxor(final int bufSize, final EWAHCompressedBitmap32... bitmaps) { EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(); bufferedxorWithContainer(answer, bufSize, bitmaps); return answer; }
/** * Compute the xor aggregate using a temporary uncompressed bitmap. * * @param bitmaps the source bitmaps * @param bufSize buffer size used during the computation in 64-bit * words * @return the xor aggregate. */ public static EWAHCompressedBitmap32 bufferedxor(final int bufSize, final EWAHCompressedBitmap32... bitmaps) { EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(); bufferedxorWithContainer(answer, bufSize, bitmaps); return answer; }
/** * Compute the and aggregate using a temporary uncompressed bitmap. * * This function does not seek to match the "sizeinbits" attributes * of the input bitmaps. * * @param bitmaps the source bitmaps * @param bufSize buffer size used during the computation in 64-bit * words (per input bitmap) * @return the or aggregate. */ public static EWAHCompressedBitmap32 bufferedand(final int bufSize, final EWAHCompressedBitmap32... bitmaps) { EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(); bufferedandWithContainer(answer, bufSize, bitmaps); return answer; }
/** * 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; }
/** * 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 EWAHCompressedBitmap32 bitmapOf(int... setbits) { EWAHCompressedBitmap32 a = new EWAHCompressedBitmap32(); for (int k : setbits) a.set(k); return a; }
/** * 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 EWAHCompressedBitmap32 bitmapOf(int... setbits) { EWAHCompressedBitmap32 a = new EWAHCompressedBitmap32(); for (int k : setbits) a.set(k); return a; }
/** * Compute the and aggregate using a temporary uncompressed bitmap. * * This function does not seek to match the "sizeinbits" attributes * of the input bitmaps. * * @param bitmaps the source bitmaps * @param bufSize buffer size used during the computation in 64-bit * words (per input bitmap) * @return the or aggregate. */ public static EWAHCompressedBitmap32 bufferedand(final int bufSize, final EWAHCompressedBitmap32... bitmaps) { EWAHCompressedBitmap32 answer = new EWAHCompressedBitmap32(); bufferedandWithContainer(answer, bufSize, bitmaps); return answer; }
@Override public EWAHCompressedBitmap32 clone() throws CloneNotSupportedException { EWAHCompressedBitmap32 clone = new EWAHCompressedBitmap32(this.buffer.clone()); clone.sizeInBits = this.sizeInBits; clone.rlw = new RunningLengthWord32(clone.buffer, this.rlw.position); return clone; }
@Override public EWAHCompressedBitmap32 clone() throws CloneNotSupportedException { EWAHCompressedBitmap32 clone = new EWAHCompressedBitmap32(this.buffer.clone()); clone.sizeInBits = this.sizeInBits; clone.rlw = new RunningLengthWord32(clone.buffer, this.rlw.position); return clone; }
EWAHCompressedBitmap32 set = new EWAHCompressedBitmap32(); set.set(0); set.set(1000000);
/** * 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 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 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; }