/** * Return true if the two EWAHCompressedBitmap have both at least one * true bit in the same position. Equivalently, you could call "and" and * check whether there is a set bit, but intersects will run faster if * you don't need the result of the "and" operation. * * The current bitmap is not modified. * * @param a the other bitmap (it will not be modified) * @return whether they intersect */ public boolean intersects(final EWAHCompressedBitmap32 a) { NonEmptyVirtualStorage32 nevs = new NonEmptyVirtualStorage32(); try { this.andToContainer(a, nevs); } catch (NonEmptyVirtualStorage32.NonEmptyException nee) { return true; } return false; }
/** * Return true if the two EWAHCompressedBitmap have both at least one * true bit in the same position. Equivalently, you could call "and" and * check whether there is a set bit, but intersects will run faster if * you don't need the result of the "and" operation. * * The current bitmap is not modified. * * @param a the other bitmap (it will not be modified) * @return whether they intersect */ public boolean intersects(final EWAHCompressedBitmap32 a) { NonEmptyVirtualStorage32 nevs = new NonEmptyVirtualStorage32(); try { this.andToContainer(a, nevs); } catch (NonEmptyVirtualStorage32.NonEmptyException nee) { return true; } return false; }
/** * For internal use. Computes the bitwise and of the provided bitmaps * and stores the result in the container. * * The content of the container is overwritten. * * @param container where the result is stored * @param bitmaps bitmaps to AND */ public static void andWithContainer(final BitmapStorage32 container, final EWAHCompressedBitmap32... bitmaps) { if (bitmaps.length == 1) throw new IllegalArgumentException( "Need at least one bitmap"); if (bitmaps.length == 2) { bitmaps[0].andToContainer(bitmaps[1], container); return; } 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 - 1; ++k) { answer.andToContainer(bitmaps[k], tmp); tmp.swap(answer); tmp.clear(); } answer.andToContainer(bitmaps[bitmaps.length - 1], container); }
/** * Returns the cardinality of the result of a bitwise AND of the values * of the current bitmap with some other bitmap. Avoids * allocating an intermediate bitmap to hold the result of the OR. * The current bitmap is not modified. * * @param a the other bitmap (it will not be modified) * @return the cardinality */ public int andCardinality(final EWAHCompressedBitmap32 a) { final BitCounter32 counter = new BitCounter32(); andToContainer(a, counter); return counter.getCount(); }
/** * For internal use. Computes the bitwise and of the provided bitmaps * and stores the result in the container. * * The content of the container is overwritten. * * @param container where the result is stored * @param bitmaps bitmaps to AND */ public static void andWithContainer(final BitmapStorage32 container, final EWAHCompressedBitmap32... bitmaps) { if (bitmaps.length == 1) throw new IllegalArgumentException( "Need at least one bitmap"); if (bitmaps.length == 2) { bitmaps[0].andToContainer(bitmaps[1], container); return; } 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 - 1; ++k) { answer.andToContainer(bitmaps[k], tmp); tmp.swap(answer); tmp.clear(); } answer.andToContainer(bitmaps[bitmaps.length - 1], container); }
/** * Returns the cardinality of the result of a bitwise AND of the values * of the current bitmap with some other bitmap. Avoids * allocating an intermediate bitmap to hold the result of the OR. * The current bitmap is not modified. * * @param a the other bitmap (it will not be modified) * @return the cardinality */ public int andCardinality(final EWAHCompressedBitmap32 a) { final BitCounter32 counter = new BitCounter32(); andToContainer(a, counter); return counter.getCount(); }
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();
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();
/** * 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; }