Skip to content

Commit

Permalink
[COLLECTIONS-854] renaming bloomfilter components and methods as per …
Browse files Browse the repository at this point in the history
…ticket (#492)

* Changed BitMap to BitMaps and CellConsumer to CellPredicate

* Renamed IndexProducer to IndexExtractor

* Renamed BitmapProducer to BitMapExtractor

* Renamed BitmapProducer to BitMapExtractor and BloomFilterProducer to BloomFilterExtractor

* change forEachBitMap to processBitMap

* change forEachBloomFilter to processBloomFilters

* change processBitMap to processBitMaps

* change forEachCell to processCells

* change forEachIndex to processIndices

* renaming cleanup

* replaced [Pp]roducer with [Ee]xtractor

* changed forEachX to processXs.  Updated documentation

* Update package-info.java as per review comments

* Updated as per review

* fixed javadoc
  • Loading branch information
Claudenw committed May 28, 2024
1 parent 2e2cd9c commit 4a2aa76
Show file tree
Hide file tree
Showing 65 changed files with 937 additions and 900 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* consumption of approximately 8 GB.
*
* @see Shape
* @see CellProducer
* @see CellExtractor
* @since 4.5
*/
public final class ArrayCountingBloomFilter implements CountingBloomFilter {
Expand Down Expand Up @@ -105,9 +105,9 @@ public ArrayCountingBloomFilter(final Shape shape) {
}

@Override
public boolean add(final CellProducer other) {
public boolean add(final CellExtractor other) {
Objects.requireNonNull(other, "other");
other.forEachCell(this::add);
other.processCells(this::add);
return isValid();
}

Expand Down Expand Up @@ -151,13 +151,13 @@ public void clear() {
}

@Override
public boolean contains(final BitMapProducer bitMapProducer) {
return contains(IndexProducer.fromBitMapProducer(bitMapProducer));
public boolean contains(final BitMapExtractor bitMapExtractor) {
return contains(IndexExtractor.fromBitMapExtractor(bitMapExtractor));
}

@Override
public boolean contains(final IndexProducer indexProducer) {
return indexProducer.forEachIndex(idx -> this.cells[idx] != 0);
public boolean contains(final IndexExtractor indexExtractor) {
return indexExtractor.processIndices(idx -> this.cells[idx] != 0);
}

@Override
Expand All @@ -166,17 +166,17 @@ public ArrayCountingBloomFilter copy() {
}

@Override
public boolean forEachBitMap(final LongPredicate consumer) {
public boolean processBitMaps(final LongPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
final int blocksm1 = BitMap.numberOfBitMaps(cells.length) - 1;
final int blocksm1 = BitMaps.numberOfBitMaps(cells.length) - 1;
int i = 0;
long value;
// must break final block separate as the number of bits may not fall on the long boundary
for (int j = 0; j < blocksm1; j++) {
value = 0;
for (int k = 0; k < Long.SIZE; k++) {
if (cells[i++] != 0) {
value |= BitMap.getLongBit(k);
value |= BitMaps.getLongBit(k);
}
}
if (!consumer.test(value)) {
Expand All @@ -187,14 +187,14 @@ public boolean forEachBitMap(final LongPredicate consumer) {
value = 0;
for (int k = 0; i < cells.length; k++) {
if (cells[i++] != 0) {
value |= BitMap.getLongBit(k);
value |= BitMaps.getLongBit(k);
}
}
return consumer.test(value);
}

@Override
public boolean forEachCell(final CellProducer.CellConsumer consumer) {
public boolean processCells(final CellPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
for (int i = 0; i < cells.length; i++) {
if (cells[i] != 0 && !consumer.test(i, cells[i])) {
Expand All @@ -205,7 +205,7 @@ public boolean forEachCell(final CellProducer.CellConsumer consumer) {
}

@Override
public boolean forEachIndex(final IntPredicate consumer) {
public boolean processIndices(final IntPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
for (int i = 0; i < cells.length; i++) {
if (cells[i] != 0 && !consumer.test(i)) {
Expand All @@ -221,9 +221,9 @@ public int getMaxCell() {
}

@Override
public int getMaxInsert(final CellProducer cellProducer) {
public int getMaxInsert(final CellExtractor cellExtractor) {
final int[] max = {Integer.MAX_VALUE};
cellProducer.forEachCell( (x, y) -> {
cellExtractor.processCells( (x, y) -> {
final int count = cells[x] / y;
if (count < max[0]) {
max[0] = count;
Expand All @@ -250,17 +250,17 @@ public Shape getShape() {
* generated invalid cells can be reversed by using the complement of the
* original operation with the same Bloom filter. This will restore the cells
* to the state prior to the invalid operation. Cells can then be extracted
* using {@link #forEachCell(CellConsumer)}.</p>
* using {@link #processCells(CellPredicate)}.</p>
*/
@Override
public boolean isValid() {
return state >= 0;
}

@Override
public boolean subtract(final CellProducer other) {
public boolean subtract(final CellExtractor other) {
Objects.requireNonNull(other, "other");
other.forEachCell(this::subtract);
other.processCells(this::subtract);
return isValid();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@
* @since 4.5
*/
@FunctionalInterface
public interface BitMapProducer {
public interface BitMapExtractor {

/**
* Creates a BitMapProducer from an array of Long.
* Creates a BitMapExtractor from an array of Long.
* @param bitMaps the bit maps to return.
* @return a BitMapProducer.
* @return a BitMapExtractor.
*/
static BitMapProducer fromBitMapArray(final long... bitMaps) {
return new BitMapProducer() {
static BitMapExtractor fromBitMapArray(final long... bitMaps) {
return new BitMapExtractor() {
@Override
public long[] asBitMapArray() {
return Arrays.copyOf(bitMaps, bitMaps.length);
}

@Override
public boolean forEachBitMap(final LongPredicate predicate) {
public boolean processBitMaps(final LongPredicate predicate) {
for (final long word : bitMaps) {
if (!predicate.test(word)) {
return false;
Expand All @@ -61,41 +61,40 @@ public boolean forEachBitMap(final LongPredicate predicate) {
}

@Override
public boolean forEachBitMapPair(final BitMapProducer other, final LongBiPredicate func) {
public boolean processBitMapPairs(final BitMapExtractor other, final LongBiPredicate func) {
final CountingLongPredicate p = new CountingLongPredicate(bitMaps, func);
return other.forEachBitMap(p) && p.forEachRemaining();
return other.processBitMaps(p) && p.processRemaining();
}
};
}

/**
* Creates a BitMapProducer from an IndexProducer.
* @param producer the IndexProducer that specifies the indexes of the bits to enable.
* Creates a BitMapExtractor from an IndexExtractor.
* @param extractor the IndexExtractor that specifies the indexes of the bits to enable.
* @param numberOfBits the number of bits in the Bloom filter.
* @return A BitMapProducer that produces the bit maps equivalent of the Indices from the producer.
* @return A BitMapExtractor that produces the bit maps equivalent of the Indices from the extractor.
*/
static BitMapProducer fromIndexProducer(final IndexProducer producer, final int numberOfBits) {
Objects.requireNonNull(producer, "producer");
Objects.requireNonNull(numberOfBits, "numberOfBits");
static BitMapExtractor fromIndexExtractor(final IndexExtractor extractor, final int numberOfBits) {
Objects.requireNonNull(extractor, "extractor");

final long[] result = new long[BitMap.numberOfBitMaps(numberOfBits)];
producer.forEachIndex(i -> {
BitMap.set(result, i);
final long[] result = new long[BitMaps.numberOfBitMaps(numberOfBits)];
extractor.processIndices(i -> {
BitMaps.set(result, i);
return true;
});
return fromBitMapArray(result);
}

/**
* Return a copy of the BitMapProducer data as a bit map array.
* Return a copy of the BitMapExtractor data as a bit map array.
* <p>
* The default implementation of this method is slow. It is recommended
* that implementing classes reimplement this method.
* </p>
* @return An array of bit map data.
*/
default long[] asBitMapArray() {
class Bits {
final class Bits {
private long[] data = new long[16];
private int size;

Expand All @@ -117,7 +116,7 @@ long[] toArray() {
}
}
final Bits bits = new Bits();
forEachBitMap(bits::add);
processBitMaps(bits::add);
return bits.toArray();
}

Expand All @@ -126,30 +125,30 @@ long[] toArray() {
* bit map value, if the predicate returns {@code false} the execution is stopped, {@code false}
* is returned, and no further bit maps are processed.
*
* <p>If the producer is empty this method will return true.</p>
* <p>If the extractor is empty this method will return true.</p>
*
* <p>Any exceptions thrown by the action are relayed to the caller.</p>
*
* @param predicate the function to execute
* @return {@code true} if all bit maps returned {@code true}, {@code false} otherwise.
* @throws NullPointerException if the specified consumer is null
*/
boolean forEachBitMap(LongPredicate predicate);
boolean processBitMaps(LongPredicate predicate);

/**
* Applies the {@code func} to each bit map pair in order. Will apply all of the bit maps from the other
* BitMapProducer to this producer. If this producer does not have as many bit maps it will provide 0 (zero)
* BitMapExtractor to this extractor. If this extractor does not have as many bit maps it will provide 0 (zero)
* for all excess calls to the LongBiPredicate.
* <p>
* <em>The default implementation of this method uses {@code asBitMapArray()}. It is recommended that implementations
* of BitMapProducer that have local arrays reimplement this method.</em></p>
* of BitMapExtractor that have local arrays reimplement this method.</em></p>
*
* @param other The other BitMapProducer that provides the y values in the (x,y) pair.
* @param other The other BitMapExtractor that provides the y values in the (x,y) pair.
* @param func The function to apply.
* @return A LongPredicate that tests this BitMapProducers bitmap values in order.
* @return A LongPredicate that tests this BitMapExtractor's bitmap values in order.
*/
default boolean forEachBitMapPair(final BitMapProducer other, final LongBiPredicate func) {
default boolean processBitMapPairs(final BitMapExtractor other, final LongBiPredicate func) {
final CountingLongPredicate p = new CountingLongPredicate(asBitMapArray(), func);
return other.forEachBitMap(p) && p.forEachRemaining();
return other.processBitMaps(p) && p.processRemaining();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
* Contains functions to convert {@code int} indices into Bloom filter bit positions and visa versa.
*
* <p>The functions view an array of longs as a collection of bit maps each containing 64 bits. The bits are arranged
* in memory as a little-endian long value. This matches the requirements of the BitMapProducer interface.</p>
* in memory as a little-endian long value. This matches the requirements of the BitMapExtractor interface.</p>
*
* @since 4.5
*/
public class BitMap {
public class BitMaps {
/** A bit shift to apply to an integer to divided by 64 (2^6). */
private static final int DIVIDE_BY_64 = 6;

Expand Down Expand Up @@ -136,6 +136,6 @@ public static void set(final long[] bitMaps, final int bitIndex) {
}

/** Do not instantiate. */
private BitMap() {
private BitMaps() {
}
}
Loading

0 comments on commit 4a2aa76

Please sign in to comment.