Skip to content

Commit

Permalink
Sort members
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jun 23, 2024
1 parent e68c2ce commit 152a57a
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,48 @@ public ArrayCountingBloomFilter copy() {
return new ArrayCountingBloomFilter(this);
}

@Override
public int getMaxCell() {
return Integer.MAX_VALUE;
}

@Override
public int getMaxInsert(final CellExtractor cellExtractor) {
final int[] max = {Integer.MAX_VALUE};
cellExtractor.processCells( (x, y) -> {
final int count = cells[x] / y;
if (count < max[0]) {
max[0] = count;
}
return max[0] > 0;
});
return max[0];
}

@Override
public Shape getShape() {
return shape;
}

/**
* {@inheritDoc}
*
* <p><em>Implementation note</em>
*
* <p>The state transition to invalid is permanent.</p>
*
* <p>This implementation does not correct negative cells to zero or integer
* overflow cells to {@link Integer#MAX_VALUE}. Thus the operation that
* 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 #processCells(CellPredicate)}.</p>
*/
@Override
public boolean isValid() {
return state >= 0;
}

@Override
public boolean processBitMaps(final LongPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
Expand Down Expand Up @@ -215,48 +257,6 @@ public boolean processIndices(final IntPredicate consumer) {
return true;
}

@Override
public int getMaxCell() {
return Integer.MAX_VALUE;
}

@Override
public int getMaxInsert(final CellExtractor cellExtractor) {
final int[] max = {Integer.MAX_VALUE};
cellExtractor.processCells( (x, y) -> {
final int count = cells[x] / y;
if (count < max[0]) {
max[0] = count;
}
return max[0] > 0;
});
return max[0];
}

@Override
public Shape getShape() {
return shape;
}

/**
* {@inheritDoc}
*
* <p><em>Implementation note</em>
*
* <p>The state transition to invalid is permanent.</p>
*
* <p>This implementation does not correct negative cells to zero or integer
* overflow cells to {@link Integer#MAX_VALUE}. Thus the operation that
* 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 #processCells(CellPredicate)}.</p>
*/
@Override
public boolean isValid() {
return state >= 0;
}

@Override
public boolean subtract(final CellExtractor other) {
Objects.requireNonNull(other, "other");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public long[] asBitMapArray() {
return Arrays.copyOf(bitMaps, bitMaps.length);
}

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

@Override
public boolean processBitMaps(final LongPredicate predicate) {
for (final long word : bitMaps) {
Expand All @@ -59,12 +65,6 @@ public boolean processBitMaps(final LongPredicate predicate) {
}
return true;
}

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

Expand Down Expand Up @@ -120,21 +120,6 @@ long[] toArray() {
return bits.toArray();
}

/**
* Each bit map is passed to the predicate in order. The predicate is applied to each
* 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 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 processBitMaps(LongPredicate predicate);

/**
* Applies the {@code func} to each bit map pair in order. Will apply all of the bit maps from the other
* BitMapExtractor to this extractor. If this extractor does not have as many bit maps it will provide 0 (zero)
Expand All @@ -151,4 +136,19 @@ default boolean processBitMapPairs(final BitMapExtractor other, final LongBiPred
final CountingLongPredicate p = new CountingLongPredicate(asBitMapArray(), func);
return other.processBitMaps(p) && p.processRemaining();
}

/**
* Each bit map is passed to the predicate in order. The predicate is applied to each
* 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 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 processBitMaps(LongPredicate predicate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ public BloomFilter[] asBloomFilterArray() {
return filters.clone();
}

@Override
public boolean processBloomFilters(final Predicate<BloomFilter> predicate) {
for (final BloomFilter filter : filters) {
if (!predicate.test(filter)) {
return false;
}
}
return true;
}

/**
* This implementation uses references to the original filters. Any modifications to the
* filters are reflected in the originals.
Expand All @@ -76,6 +66,16 @@ public boolean processBloomFilterPair(final BloomFilterExtractor other,
final CountingPredicate<BloomFilter> p = new CountingPredicate<>(filters, func);
return other.processBloomFilters(p) && p.processRemaining();
}

@Override
public boolean processBloomFilters(final Predicate<BloomFilter> predicate) {
for (final BloomFilter filter : filters) {
if (!predicate.test(filter)) {
return false;
}
}
return true;
}
};
}

Expand Down Expand Up @@ -110,16 +110,6 @@ default BloomFilter flatten() {
return bf[0];
}

/**
* Executes a Bloom filter Predicate on each Bloom filter in the collection. The
* ordering of the Bloom filters is not specified by this interface.
*
* @param bloomFilterPredicate the predicate to evaluate each Bloom filter with.
* @return {@code false} when the first filter fails the predicate test. Returns
* {@code true} if all filters pass the test.
*/
boolean processBloomFilters(Predicate<BloomFilter> bloomFilterPredicate);

/**
* Applies the {@code func} to each Bloom filter pair in order. Will apply all
* of the Bloom filters from the other BloomFilterExtractor to this extractor. If
Expand All @@ -141,4 +131,14 @@ default boolean processBloomFilterPair(final BloomFilterExtractor other,
final CountingPredicate<BloomFilter> p = new CountingPredicate<>(asBloomFilterArray(), func);
return other.processBloomFilters(p) && p.processRemaining();
}

/**
* Executes a Bloom filter Predicate on each Bloom filter in the collection. The
* ordering of the Bloom filters is not specified by this interface.
*
* @param bloomFilterPredicate the predicate to evaluate each Bloom filter with.
* @return {@code false} when the first filter fails the predicate test. Returns
* {@code true} if all filters pass the test.
*/
boolean processBloomFilters(Predicate<BloomFilter> bloomFilterPredicate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@ public int[] asIndexArray() {
return counterCells.keySet().stream().mapToInt(c -> c.idx).toArray();
}

@Override
public boolean processCells(final CellPredicate consumer) {
populate();
for (final CounterCell cell : counterCells.values()) {
if (!consumer.test(cell.idx, cell.count)) {
return false;
}
}
return true;
}

private void populate() {
if (counterCells.isEmpty()) {
indexExtractor.processIndices(idx -> {
Expand All @@ -136,6 +125,17 @@ private void populate() {
});
}
}

@Override
public boolean processCells(final CellPredicate consumer) {
populate();
for (final CounterCell cell : counterCells.values()) {
if (!consumer.test(cell.idx, cell.count)) {
return false;
}
}
return true;
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,24 +364,6 @@ public final T first() {
return filters.getFirst();
}

/**
* Executes a Bloom filter Predicate on each Bloom filter in the manager in
* depth order. Oldest filter first.
*
* @param bloomFilterPredicate the predicate to evaluate each Bloom filter with.
* @return {@code false} when the a filter fails the predicate test. Returns
* {@code true} if all filters pass the test.
*/
@Override
public boolean processBloomFilters(final Predicate<BloomFilter> bloomFilterPredicate) {
for (final BloomFilter bf : filters) {
if (!bloomFilterPredicate.test(bf)) {
return false;
}
}
return true;
}

/**
* Gets the Bloom filter at the specified depth. The filter at depth 0 is the
* oldest filter.
Expand Down Expand Up @@ -446,4 +428,22 @@ void next() {
this.filterCleanup.accept(filters);
addFilter();
}

/**
* Executes a Bloom filter Predicate on each Bloom filter in the manager in
* depth order. Oldest filter first.
*
* @param bloomFilterPredicate the predicate to evaluate each Bloom filter with.
* @return {@code false} when the a filter fails the predicate test. Returns
* {@code true} if all filters pass the test.
*/
@Override
public boolean processBloomFilters(final Predicate<BloomFilter> bloomFilterPredicate) {
for (final BloomFilter bf : filters) {
if (!bloomFilterPredicate.test(bf)) {
return false;
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,30 +295,6 @@ public BloomFilter flatten() {
return bf;
}

@Override
public boolean processBitMaps(final LongPredicate predicate) {
return flatten().processBitMaps(predicate);
}

/**
* Processes the Bloom filters in depth order with the most recent filters
* first. Each filter is passed to the predicate in turn. The function exits on
* the first {@code false} returned by the predicate.
*
* @param bloomFilterPredicate the predicate to execute.
* @return {@code true} if all filters passed the predicate, {@code false}
* otherwise.
*/
@Override
public final boolean processBloomFilters(final Predicate<BloomFilter> bloomFilterPredicate) {
return layerManager.processBloomFilters(bloomFilterPredicate);
}

@Override
public boolean processIndices(final IntPredicate predicate) {
return processBloomFilters(bf -> bf.processIndices(predicate));
}

/**
* Gets the Bloom filter at the specified depth
*
Expand Down Expand Up @@ -377,4 +353,28 @@ public void next() {
layerManager.next();
}

@Override
public boolean processBitMaps(final LongPredicate predicate) {
return flatten().processBitMaps(predicate);
}

/**
* Processes the Bloom filters in depth order with the most recent filters
* first. Each filter is passed to the predicate in turn. The function exits on
* the first {@code false} returned by the predicate.
*
* @param bloomFilterPredicate the predicate to execute.
* @return {@code true} if all filters passed the predicate, {@code false}
* otherwise.
*/
@Override
public final boolean processBloomFilters(final Predicate<BloomFilter> bloomFilterPredicate) {
return layerManager.processBloomFilters(bloomFilterPredicate);
}

@Override
public boolean processIndices(final IntPredicate predicate) {
return processBloomFilters(bf -> bf.processIndices(predicate));
}

}
Loading

0 comments on commit 152a57a

Please sign in to comment.