Bloom filter code clean-up
Correct whitespace issues. Javadoc additions and corrections.
This commit is contained in:
parent
a251c18dae
commit
3071aea62d
|
@ -52,7 +52,7 @@ public interface BitCountProducer extends IndexProducer {
|
|||
|
||||
/**
|
||||
* Performs the given action for each {@code <index, count>} pair where the count is non-zero.
|
||||
* Any exceptions thrown by the action are relayed to the caller. The consumer is applied to each
|
||||
* Any exceptions thrown by the action are relayed to the caller. The consumer is applied to each
|
||||
* index-count pair, if the consumer returns {@code false} the execution is stopped, {@code false}
|
||||
* is returned, and no further pairs are processed.
|
||||
*
|
||||
|
@ -74,7 +74,7 @@ public interface BitCountProducer extends IndexProducer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a BitCountProducer from an IndexProducer. The resulting
|
||||
* Creates a BitCountProducer from an IndexProducer. The resulting
|
||||
* producer will return every index from the IndexProducer with a count of 1.
|
||||
*
|
||||
* <p>Note that the BitCountProducer does not remove duplicates. Any use of the
|
||||
|
@ -119,7 +119,7 @@ public interface BitCountProducer extends IndexProducer {
|
|||
*
|
||||
* @param index the bit index.
|
||||
* @param count the count at the specified bit index.
|
||||
* @return {@code true} if processing should continue, {@code false} it processing should stop.
|
||||
* @return {@code true} if processing should continue, {@code false} if processing should stop.
|
||||
*/
|
||||
boolean test(int index, int count);
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.apache.commons.collections4.bloomfilter;
|
|||
/**
|
||||
* 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>
|
||||
* <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>
|
||||
*
|
||||
* @since 4.5
|
||||
*/
|
||||
|
|
|
@ -39,7 +39,7 @@ import java.util.function.LongPredicate;
|
|||
public interface BitMapProducer {
|
||||
|
||||
/**
|
||||
* Each bit map is passed to the predicate in order. The predicate is applied to each
|
||||
* 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.
|
||||
*
|
||||
|
@ -54,11 +54,11 @@ public interface BitMapProducer {
|
|||
boolean forEachBitMap(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)
|
||||
* 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)
|
||||
* for all excess calls to the LongBiPredicate.
|
||||
* <p>
|
||||
* <em>The default implementation of this method uses {@code asBitMapArray()} It is recommended that implementations
|
||||
* <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>
|
||||
*
|
||||
* @param other The other BitMapProducer that provides the y values in the (x,y) pair.
|
||||
|
@ -73,7 +73,7 @@ public interface BitMapProducer {
|
|||
/**
|
||||
* Return a copy of the BitMapProducer data as a bit map array.
|
||||
* <p>
|
||||
* The default implementation of this method is slow. It is recommended
|
||||
* 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.
|
||||
|
|
|
@ -32,8 +32,8 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
|
|||
/**
|
||||
* The sparse characteristic used to determine the best method for matching.
|
||||
* <p>For `sparse` implementations
|
||||
* the {@code forEachIndex(IntConsumer consumer)} method is more efficient. For non `sparse` implementations
|
||||
* the {@code forEachBitMap(LongConsumer consumer)} is more efficient. Implementers should determine if it is easier
|
||||
* the {@code forEachIndex(IntConsumer consumer)} method is more efficient. For non `sparse` implementations
|
||||
* the {@code forEachBitMap(LongConsumer consumer)} is more efficient. Implementers should determine if it is easier
|
||||
* for the implementation to produce indexes of bit map blocks.</p>
|
||||
*/
|
||||
int SPARSE = 0x1;
|
||||
|
@ -136,7 +136,7 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
|
|||
* @return true if the merge was successful
|
||||
*/
|
||||
default boolean merge(BloomFilter other) {
|
||||
return (characteristics() & SPARSE) != 0 ? merge((IndexProducer) other ) : merge((BitMapProducer) other);
|
||||
return (characteristics() & SPARSE) != 0 ? merge((IndexProducer) other) : merge((BitMapProducer) other);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -82,7 +82,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer {
|
|||
/**
|
||||
* Merges the specified Bloom filter into this Bloom filter.
|
||||
*
|
||||
* <p>Specifically: all counts for the indexes identified by the {@code other} filter will be incremented by 1,</p>
|
||||
* <p>Specifically: all counts for the indexes identified by the {@code other} filter will be incremented by 1.</p>
|
||||
*
|
||||
* <p>Note: If the other filter is a counting Bloom filter the index counts are ignored and it is treated as an
|
||||
* IndexProducer.</p>
|
||||
|
@ -102,7 +102,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer {
|
|||
/**
|
||||
* Merges the specified Hasher into this Bloom filter.
|
||||
*
|
||||
* <p>Specifically: all counts for the unique indexes identified by the {@code hasher} will be incremented by 1,</p>
|
||||
* <p>Specifically: all counts for the unique indexes identified by the {@code hasher} will be incremented by 1.</p>
|
||||
*
|
||||
* <p>This method will return {@code true} if the filter is valid after the operation.</p>
|
||||
*
|
||||
|
@ -119,7 +119,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer {
|
|||
/**
|
||||
* Merges the specified index producer into this Bloom filter.
|
||||
*
|
||||
* <p>Specifically: all counts for the indexes identified by the {@code indexProducer} will be incremented by 1,</p>
|
||||
* <p>Specifically: all counts for the indexes identified by the {@code indexProducer} will be incremented by 1.</p>
|
||||
*
|
||||
* <p>This method will return {@code true} if the filter is valid after the operation.</p>
|
||||
*
|
||||
|
@ -143,7 +143,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer {
|
|||
/**
|
||||
* Merges the specified BitMap producer into this Bloom filter.
|
||||
*
|
||||
* <p>Specifically: all counts for the indexes identified by the {@code bitMapProducer} will be incremented by 1,</p>
|
||||
* <p>Specifically: all counts for the indexes identified by the {@code bitMapProducer} will be incremented by 1.</p>
|
||||
*
|
||||
* <p>This method will return {@code true} if the filter is valid after the operation.</p>
|
||||
*
|
||||
|
@ -160,7 +160,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer {
|
|||
/**
|
||||
* Removes the specified Bloom filter from this Bloom filter.
|
||||
*
|
||||
* <p>Specifically: all counts for the indexes identified by the {@code other} filter will be decremented by 1,</p>
|
||||
* <p>Specifically: all counts for the indexes identified by the {@code other} filter will be decremented by 1.</p>
|
||||
*
|
||||
* <p>Note: If the other filter is a counting Bloom filter the index counts are ignored and it is treated as an
|
||||
* IndexProducer.</p>
|
||||
|
|
|
@ -32,7 +32,7 @@ class CountingLongPredicate implements LongPredicate {
|
|||
|
||||
/**
|
||||
* Constructs an instance that will compare the elements in @{code ary} with the elements returned by @{code func}.
|
||||
* function is called as @{code func.test( idxValue, otherValue )}. if there are more @{code otherValue} values than
|
||||
* function is called as @{code func.test( idxValue, otherValue )}. If there are more @{code otherValue} values than
|
||||
* @{code idxValues} then @{code func} is called as @{code func.test( 0, otherValue )}.
|
||||
* @param ary The array of long values to compare.
|
||||
* @param func The function to apply to the pairs of long values.
|
||||
|
|
|
@ -68,7 +68,7 @@ public class EnhancedDoubleHasher implements Hasher {
|
|||
int shift = Long.SIZE;
|
||||
final int end = offset + Math.min(len, Long.BYTES);
|
||||
for (int i = offset; i < end; i++) {
|
||||
shift -= Byte.SIZE;
|
||||
shift -= Byte.SIZE;
|
||||
val |= ((long) (byteArray[i] & 0xFF) << shift);
|
||||
}
|
||||
return val;
|
||||
|
@ -104,7 +104,7 @@ public class EnhancedDoubleHasher implements Hasher {
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructs the EnhancedDoubleHasher from 2 longs. The long values will be interpreted as unsigned values.
|
||||
* Constructs the EnhancedDoubleHasher from 2 longs. The long values will be interpreted as unsigned values.
|
||||
* @param initial The initial value for the hasher.
|
||||
* @param increment The value to increment the hash by on each iteration.
|
||||
*/
|
||||
|
|
|
@ -49,7 +49,7 @@ public interface Hasher {
|
|||
* Creates an IndexProducer of unique indices for this hasher based on the Shape.
|
||||
*
|
||||
* <p>This is like the `indices(Shape)` method except that it adds the guarantee that no
|
||||
* duplicate values will be returned. The indices produced are equivalent to those returned
|
||||
* duplicate values will be returned. The indices produced are equivalent to those returned
|
||||
* from by a Bloom filter created from this hasher.</p>
|
||||
*
|
||||
* @param shape the shape of the desired Bloom filter.
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.Objects;
|
|||
import java.util.function.IntPredicate;
|
||||
|
||||
/**
|
||||
* A collection of Hashers. Useful when the generation of a Bloom filter depends upon
|
||||
* A collection of Hashers. Useful when the generation of a Bloom filter depends upon
|
||||
* multiple items.
|
||||
* <p>
|
||||
* Hashers for each item are added to the HasherCollection and then
|
||||
|
@ -95,7 +95,7 @@ public class HasherCollection implements Hasher {
|
|||
* hashers.
|
||||
*
|
||||
* <p>This method may return duplicates if the collection of unique values from each of the contained
|
||||
* hashers contain duplicates. This is equivalent to creating Bloom filters for each contained hasher
|
||||
* hashers contain duplicates. This is equivalent to creating Bloom filters for each contained hasher
|
||||
* and returning an IndexProducer with the concatenated output indices from each filter.</p>
|
||||
*
|
||||
* <p>A BitCountProducer generated from this IndexProducer is equivalent to a BitCountProducer from a
|
||||
|
|
|
@ -77,7 +77,7 @@ public final class IndexFilter {
|
|||
|
||||
/**
|
||||
* An IndexTracker implementation that uses an array of integers to track whether or not a
|
||||
* number has been seen. Suitable for Shapes that have few hash functions.
|
||||
* number has been seen. Suitable for Shapes that have few hash functions.
|
||||
* @since 4.5
|
||||
*/
|
||||
static class ArrayTracker implements IntPredicate {
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.function.LongPredicate;
|
|||
/**
|
||||
* An object that produces indices of a Bloom filter.
|
||||
* <p><em>
|
||||
* The default implementation of {@code asIndexArray} is slow. Implementers should reimplement the
|
||||
* The default implementation of {@code asIndexArray} is slow. Implementers should reimplement the
|
||||
* method where possible.</em></p>
|
||||
*
|
||||
* @since 4.5
|
||||
|
@ -33,7 +33,7 @@ import java.util.function.LongPredicate;
|
|||
public interface IndexProducer {
|
||||
|
||||
/**
|
||||
* Each index is passed to the predicate. The predicate is applied to each
|
||||
* Each index is passed to the predicate. The predicate is applied to each
|
||||
* index value, if the predicate returns {@code false} the execution is stopped, {@code false}
|
||||
* is returned, and no further indices are processed.
|
||||
*
|
||||
|
@ -112,7 +112,7 @@ public interface IndexProducer {
|
|||
* <p>Indices ordering and uniqueness is not guaranteed.</p>
|
||||
*
|
||||
* <p><em>
|
||||
* The default implementation of this method is slow. It is recommended
|
||||
* The default implementation of this method is slow. It is recommended
|
||||
* that implementing classes reimplement this method.
|
||||
* </em></p>
|
||||
*
|
||||
|
|
|
@ -44,7 +44,7 @@ public final class SetOperations {
|
|||
}
|
||||
|
||||
/**
|
||||
* Calculates the cardinality of a BitMapProducer. By necessity this method will visit each bit map
|
||||
* Calculates the cardinality of a BitMapProducer. By necessity this method will visit each bit map
|
||||
* created by the producer.
|
||||
* @param producer the Producer to calculate the cardinality for.
|
||||
* @return the cardinality of the bit maps produced by the producer.
|
||||
|
|
|
@ -149,7 +149,7 @@ public final class Shape {
|
|||
|
||||
/**
|
||||
* Determines if a cardinality is sparse based on the shape.
|
||||
* <p>This method assumes that bit maps are 64bits and indexes are 32bits. If the memory
|
||||
* <p>This method assumes that bit maps are 64bits and indexes are 32bits. If the memory
|
||||
* necessary to store the cardinality as indexes is less than the estimated memory for bit maps,
|
||||
* the cardinality is determined to be {@code sparse}.</p>
|
||||
* @param cardinality the cardinality to check.
|
||||
|
|
|
@ -29,7 +29,7 @@ import java.util.function.LongPredicate;
|
|||
public final class SimpleBloomFilter implements BloomFilter {
|
||||
|
||||
/**
|
||||
* The array of bit map longs that defines this Bloom filter. Will be null if the filter is empty.
|
||||
* The array of bit map longs that defines this Bloom filter. Will be null if the filter is empty.
|
||||
*/
|
||||
private final long[] bitMap;
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
* <h3>BloomFilter</h3>
|
||||
*
|
||||
* <p>The Bloom filter architecture here is designed for speed of execution, so some methods like {@code merge}, {@code remove},
|
||||
* {@code add}, and {@code subtract} may throw exceptions. Once an exception is thrown the state of the Bloom filter is unknown.
|
||||
* {@code add}, and {@code subtract} may throw exceptions. Once an exception is thrown the state of the Bloom filter is unknown.
|
||||
* The choice to use not use atomic transactions was made to achieve maximum performance under correct usage.</p>
|
||||
*
|
||||
* <p>In addition the architecture is designed so that the implementation of the storage of bits is abstracted.
|
||||
|
|
|
@ -127,7 +127,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
|||
Hasher hasher = new ArrayHasher(expected);
|
||||
f.merge(hasher);
|
||||
// create sorted unique array of expected values
|
||||
assertArrayEquals(DefaultIndexProducerTest.unique(expected), f.asIndexArray( ));
|
||||
assertArrayEquals(DefaultIndexProducerTest.unique(expected), f.asIndexArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
|||
public void testMergeWithBitMapProducer() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
long[] values = new long[2];
|
||||
for (int idx : DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits())) {
|
||||
for (int idx : DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits())) {
|
||||
BitMap.set(values, idx);
|
||||
}
|
||||
BloomFilter f = createFilter(getTestShape(), BitMapProducer.fromBitMapArray(values));
|
||||
|
@ -175,11 +175,11 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
|||
// value to large
|
||||
final BloomFilter f1 = createEmptyFilter(getTestShape());
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> f1.merge(IndexProducer.fromIndexArray(new int[] { getTestShape().getNumberOfBits() })));
|
||||
() -> f1.merge(IndexProducer.fromIndexArray(new int[] {getTestShape().getNumberOfBits()})));
|
||||
// negative value
|
||||
final BloomFilter f2 = createEmptyFilter(getTestShape());
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> f2.merge(IndexProducer.fromIndexArray(new int[] { -1 })));
|
||||
() -> f2.merge(IndexProducer.fromIndexArray(new int[] {-1})));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -391,13 +391,13 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
|||
public void testIndexProducerMerge() {
|
||||
Shape shape = Shape.fromKM(5, 10);
|
||||
|
||||
assertIndexProducerMerge(shape, new int[] { 0, 2, 4, 6, 8 }, new int[] { 0, 2, 4, 6, 8 });
|
||||
assertIndexProducerMerge(shape, new int[] {0, 2, 4, 6, 8}, new int[] {0, 2, 4, 6, 8});
|
||||
// test duplicate values
|
||||
assertIndexProducerMerge(shape, new int[] { 0, 2, 4, 2, 8 }, new int[] { 0, 2, 4, 8 });
|
||||
assertIndexProducerMerge(shape, new int[] {0, 2, 4, 2, 8}, new int[] {0, 2, 4, 8});
|
||||
// test negative values
|
||||
assertFailedIndexProducerConstructor(shape, new int[] { 0, 2, 4, -2, 8 });
|
||||
assertFailedIndexProducerConstructor(shape, new int[] {0, 2, 4, -2, 8});
|
||||
// test index too large
|
||||
assertFailedIndexProducerConstructor(shape, new int[] { 0, 2, 4, 12, 8 });
|
||||
assertFailedIndexProducerConstructor(shape, new int[] {0, 2, 4, 12, 8});
|
||||
// test no indices
|
||||
assertIndexProducerMerge(shape, new int[0], new int[0]);
|
||||
}
|
||||
|
@ -427,7 +427,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
|||
IndexProducer producer;
|
||||
|
||||
BadHasher(int value) {
|
||||
this.producer = IndexProducer.fromIndexArray(new int[] { value });
|
||||
this.producer = IndexProducer.fromIndexArray(new int[] {value});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,11 +31,11 @@ import org.junit.jupiter.api.Test;
|
|||
*/
|
||||
public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFilter>
|
||||
extends AbstractBloomFilterTest<T> {
|
||||
protected int[] from1Counts = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 };
|
||||
protected int[] from11Counts = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
0 };
|
||||
protected int[] bigHashCounts = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 0 };
|
||||
protected int[] from1Counts = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
|
||||
protected int[] from11Counts = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
0};
|
||||
protected int[] bigHashCounts = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 0};
|
||||
|
||||
protected final BitCountProducer maximumValueProducer = new BitCountProducer() {
|
||||
|
||||
|
@ -191,7 +191,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
|
|||
assertFalse(bf3.contains(from1), "Should not contain");
|
||||
assertFalse(bf3.contains(bf4), "Should not contain");
|
||||
|
||||
assertCounts(bf3, new int[] { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 });
|
||||
assertCounts(bf3, new int[] {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -229,7 +229,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
|
|||
assertFalse(bf3.contains(from1), "Should not contain");
|
||||
assertFalse(bf3.contains(simple), "Should not contain");
|
||||
|
||||
assertCounts(bf3, new int[] { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
|
||||
assertCounts(bf3, new int[] {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
|
||||
|
||||
// with IndexProducer
|
||||
IndexProducer ip = from11.indices(getTestShape());
|
||||
|
@ -257,11 +257,11 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
|
|||
// test producer errors
|
||||
IndexProducer ip2 = IndexProducer.fromIndexArray(1, 2, getTestShape().getNumberOfBits());
|
||||
final CountingBloomFilter bf6 = createFilter(getTestShape(), from1);
|
||||
assertThrows( IllegalArgumentException.class, () -> bf6.remove(ip2));
|
||||
assertThrows(IllegalArgumentException.class, () -> bf6.remove(ip2));
|
||||
|
||||
final CountingBloomFilter bf7 = createFilter(getTestShape(), from1);
|
||||
final BitMapProducer bmp2 = BitMapProducer.fromIndexProducer(ip2, getTestShape().getNumberOfBits());
|
||||
assertThrows( IllegalArgumentException.class, () -> bf7.remove(bmp2));
|
||||
assertThrows(IllegalArgumentException.class, () -> bf7.remove(bmp2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -29,7 +29,7 @@ public abstract class AbstractHasherTest extends AbstractIndexProducerTest {
|
|||
protected abstract Hasher createEmptyHasher();
|
||||
|
||||
/**
|
||||
* A method to get the number of items in a hasher. Mostly applies to
|
||||
* A method to get the number of items in a hasher. Mostly applies to
|
||||
* Collections of hashers.
|
||||
* @param hasher the hasher to check.
|
||||
* @return the number of hashers in the hasher
|
||||
|
@ -59,9 +59,14 @@ public abstract class AbstractHasherTest extends AbstractIndexProducerTest {
|
|||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({ "17, 72", "3, 14", "5, 67868", "75, 10"})
|
||||
@CsvSource({
|
||||
"17, 72",
|
||||
"3, 14",
|
||||
"5, 67868",
|
||||
"75, 10"
|
||||
})
|
||||
public void testHashing(int k, int m) {
|
||||
int[] count = { 0 };
|
||||
int[] count = {0};
|
||||
Hasher hasher = createHasher();
|
||||
hasher.indices(Shape.fromKM(k, m)).forEachIndex(i -> {
|
||||
assertTrue(i >= 0 && i < m, () -> "Out of range: " + i + ", m=" + m);
|
||||
|
|
|
@ -33,9 +33,9 @@ public abstract class AbstractIndexProducerTest {
|
|||
private static final IntPredicate TRUE_PREDICATE = i -> true;
|
||||
private static final IntPredicate FALSE_PREDICATE = i -> false;
|
||||
|
||||
/** Flag to indicate the {@link IndexProducer#forEachIndex(IntPredicate)} is ordered. */
|
||||
/** Flag to indicate the indices are ordered, e.g. from {@link IndexProducer#forEachIndex(IntPredicate)}. */
|
||||
protected static final int ORDERED = 0x1;
|
||||
/** Flag to indicate the {@link IndexProducer#forEachIndex(IntPredicate)} is distinct. */
|
||||
/** Flag to indicate the indices are distinct, e.g. from {@link IndexProducer#forEachIndex(IntPredicate)}. */
|
||||
protected static final int DISTINCT = 0x2;
|
||||
|
||||
/**
|
||||
|
@ -84,6 +84,8 @@ public abstract class AbstractIndexProducerTest {
|
|||
/**
|
||||
* Gets the behaviour of the {@link IndexProducer#asIndexArray()} method.
|
||||
* @return the behaviour.
|
||||
* @see #ORDERED
|
||||
* @see #DISTINCT
|
||||
*/
|
||||
protected abstract int getAsIndexArrayBehaviour();
|
||||
|
||||
|
@ -91,6 +93,8 @@ public abstract class AbstractIndexProducerTest {
|
|||
* Gets the behaviour of the {@link IndexProducer#forEachIndex(IntPredicate)} method.
|
||||
* By default returns the value of {@code getAsIndexArrayBehaviour()} method.
|
||||
* @return the behaviour.
|
||||
* @see #ORDERED
|
||||
* @see #DISTINCT
|
||||
*/
|
||||
protected int getForEachIndexBehaviour() {
|
||||
return getAsIndexArrayBehaviour();
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.commons.collections4.bloomfilter;
|
||||
|
||||
|
||||
public class BitCountProducerFromAbsoluteUniqueHasherCollectionTest extends AbstractBitCountProducerTest {
|
||||
|
||||
@Override
|
||||
|
@ -39,6 +38,6 @@ public class BitCountProducerFromAbsoluteUniqueHasherCollectionTest extends Abst
|
|||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
return new int[]{1, 2, 3, 4, 5, 7, 9};
|
||||
return new int[] {1, 2, 3, 4, 5, 7, 9};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,13 +41,13 @@ public class BitCountProducerFromArrayCountingBloomFilterTest extends AbstractBi
|
|||
|
||||
@Override
|
||||
protected int[][] getExpectedBitCount() {
|
||||
return new int[][]{{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 2}, {6, 2}, {7, 2},
|
||||
return new int[][] {{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 2}, {6, 2}, {7, 2},
|
||||
{8, 2}, {9, 2}, {10, 2}, {11, 2}, {12, 2}, {13, 2}, {14, 2}, {15, 2}, {16, 2},
|
||||
{17, 1}, {18, 1}, {19, 1}, {20, 1}, {21, 1}};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
return new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
|
||||
return new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,13 +38,13 @@ public class BitCountProducerFromHasherCollectionTest extends AbstractBitCountPr
|
|||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
return new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
return new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
2, 9, 16, 23, 30, 37, 44, 51, 58, 65, 0, 7, 14, 21, 28, 35, 42};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[][] getExpectedBitCount() {
|
||||
return new int[][]{{0, 2}, {1, 1}, {2, 2}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 2}, {8, 1},
|
||||
return new int[][] {{0, 2}, {1, 1}, {2, 2}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 2}, {8, 1},
|
||||
{9, 2}, {10, 1}, {11, 1}, {12, 1}, {13, 1}, {14, 2}, {15, 1}, {16, 2}, {21, 1}, {23, 1},
|
||||
{28, 1}, {30, 1}, {35, 1}, {37, 1}, {42, 1}, {44, 1}, {51, 1}, {58, 1}, {65, 1} };
|
||||
}
|
||||
|
|
|
@ -37,11 +37,11 @@ public class BitCountProducerFromHasherTest extends AbstractBitCountProducerTest
|
|||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
return new int[]{4, 12, 20, 28, 36, 44, 52, 60, 68, 4, 12, 20, 28, 36, 44, 52, 60};
|
||||
return new int[] {4, 12, 20, 28, 36, 44, 52, 60, 68, 4, 12, 20, 28, 36, 44, 52, 60};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[][] getExpectedBitCount() {
|
||||
return new int[][]{{4, 2}, {12, 2}, {20, 2}, {28, 2}, {36, 2}, {44, 2}, {52, 2}, {60, 2}, {68, 1}};
|
||||
return new int[][] {{4, 2}, {12, 2}, {20, 2}, {28, 2}, {36, 2}, {44, 2}, {52, 2}, {60, 2}, {68, 1}};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,6 @@ public class BitCountProducerFromSimpleBloomFilterTest extends AbstractBitCountP
|
|||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
return new int[]{3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35};
|
||||
return new int[] {3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,6 @@ public class BitCountProducerFromSparseBloomFilterTest extends AbstractBitCountP
|
|||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
return new int[]{2, 4, 9, 11, 16, 18, 23, 25, 30, 32, 37, 39, 44, 46, 53, 60, 67};
|
||||
return new int[] {2, 4, 9, 11, 16, 18, 23, 25, 30, 32, 37, 39, 44, 46, 53, 60, 67};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,11 +39,11 @@ public class BitCountProducerFromUniqueHasherCollectionTest extends AbstractBitC
|
|||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
return new int[]{1, 2, 3, 4, 5, 7, 9, 1, 3, 5};
|
||||
return new int[] {1, 2, 3, 4, 5, 7, 9, 1, 3, 5};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[][] getExpectedBitCount() {
|
||||
return new int[][]{{1, 2}, {2, 1}, {3, 2}, {4, 1}, {5, 2}, {7, 1}, {9, 1}};
|
||||
return new int[][] {{1, 2}, {2, 1}, {3, 2}, {4, 1}, {5, 2}, {7, 1}, {9, 1}};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,6 @@ public class BitCountProducerFromUniqueHasherTest extends AbstractBitCountProduc
|
|||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
return new int[]{4, 12, 20, 28, 36, 44, 52, 60, 68};
|
||||
return new int[] {4, 12, 20, 28, 36, 44, 52, 60, 68};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class BitMapProducerFromLongArrayTest extends AbstractBitMapProducerTest
|
|||
|
||||
@Override
|
||||
protected BitMapProducer createProducer() {
|
||||
long[] ary = new long[] { 1L, 2L, 3L, 4L, 5L };
|
||||
long[] ary = new long[] {1L, 2L, 3L, 4L, 5L};
|
||||
return BitMapProducer.fromBitMapArray(ary);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,13 +59,13 @@ public class DefaultBitCountProducerTest extends AbstractBitCountProducerTest {
|
|||
|
||||
@Override
|
||||
protected int getForEachIndexBehaviour() {
|
||||
// the default method has the same behaviour as the forEachCount() method.
|
||||
// The default method has the same behaviour as the forEachCount() method.
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getForEachCountBehaviour() {
|
||||
// the implemented mehtod returns unordered duplicates.
|
||||
// The implemented method returns unordered duplicates.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
public class DefaultBitMapProducerTest extends AbstractBitMapProducerTest {
|
||||
|
||||
long[] values = generateLongArray( 5 );
|
||||
long[] values = generateLongArray(5);
|
||||
|
||||
@Override
|
||||
protected BitMapProducer createProducer() {
|
||||
|
@ -76,15 +76,15 @@ public class DefaultBitMapProducerTest extends AbstractBitMapProducerTest {
|
|||
IndexProducer ip = IndexProducer.fromIndexArray(expected);
|
||||
long[] ary = BitMapProducer.fromIndexProducer(ip, 256).asBitMapArray();
|
||||
for (int idx : expected) {
|
||||
assertTrue( BitMap.contains(ary, idx));
|
||||
assertTrue(BitMap.contains(ary, idx));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromBitMapArray() {
|
||||
int nOfBitMaps = BitMap.numberOfBitMaps(256);
|
||||
long[] expected = generateLongArray( nOfBitMaps );
|
||||
long[] expected = generateLongArray(nOfBitMaps);
|
||||
long[] ary = BitMapProducer.fromBitMapArray(expected).asBitMapArray();
|
||||
assertArrayEquals( expected, ary );
|
||||
assertArrayEquals(expected, ary);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
|||
assertEquals(3, filter.cardinality());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDefaultBloomFilterSparseSpecificMerge() {
|
||||
Shape shape = Shape.fromKM(3, 150);
|
||||
|
@ -115,12 +114,13 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
|||
private void checkIndicesRange() {
|
||||
if (!indices.isEmpty()) {
|
||||
if (indices.last() >= shape.getNumberOfBits()) {
|
||||
throw new IllegalArgumentException(String.format("Value in list %s is greater than maximum value (%s)",
|
||||
indices.last(), shape.getNumberOfBits()));
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Value in list %s is greater than maximum value (%s)", indices.last(),
|
||||
shape.getNumberOfBits()));
|
||||
}
|
||||
if (indices.first() < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Value in list %s is less than 0", indices.first()));
|
||||
String.format("Value in list %s is less than 0", indices.first()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(BitMapProducer bitMapProducer){
|
||||
public boolean merge(BitMapProducer bitMapProducer) {
|
||||
return merge(IndexProducer.fromBitMapProducer(bitMapProducer));
|
||||
}
|
||||
|
||||
|
|
|
@ -95,9 +95,9 @@ public class EnhancedDoubleHasherTest extends AbstractHasherTest {
|
|||
|
||||
@Test
|
||||
void testModEdgeCases() {
|
||||
for (long dividend : new long[] { -1, -2, -3, -6378683, -23567468136887892L, Long.MIN_VALUE, 345, 678686,
|
||||
67868768686878924L, Long.MAX_VALUE }) {
|
||||
for (int divisor : new int[] { 1, 2, 3, 5, 13, Integer.MAX_VALUE }) {
|
||||
for (long dividend : new long[] {-1, -2, -3, -6378683, -23567468136887892L, Long.MIN_VALUE, 345, 678686,
|
||||
67868768686878924L, Long.MAX_VALUE}) {
|
||||
for (int divisor : new int[] {1, 2, 3, 5, 13, Integer.MAX_VALUE}) {
|
||||
assertEquals((int) Long.remainderUnsigned(dividend, divisor), EnhancedDoubleHasher.mod(dividend, divisor),
|
||||
() -> String.format("failure with dividend=%s and divisor=%s.", dividend, divisor));
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ public class HasherCollectionTest extends AbstractHasherTest {
|
|||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
return new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 2, 4, 6, 8, 10, 12, 14, 16, 18,
|
||||
20, 22, 24, 26, 28, 30, 32, 34 };
|
||||
return new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 2, 4, 6, 8, 10, 12, 14, 16, 18,
|
||||
20, 22, 24, 26, 28, 30, 32, 34};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -55,7 +55,13 @@ public class IndexFilterTest {
|
|||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({ "1, 64", "2, 64", "3, 64", "7, 357", "7, 17", })
|
||||
@CsvSource({
|
||||
"1, 64",
|
||||
"2, 64",
|
||||
"3, 64",
|
||||
"7, 357",
|
||||
"7, 17",
|
||||
})
|
||||
void testFilter(int k, int m) {
|
||||
Shape shape = Shape.fromKM(k, m);
|
||||
BitSet used = new BitSet(m);
|
||||
|
|
|
@ -45,13 +45,13 @@ public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTe
|
|||
3L => ...0011
|
||||
@formatter:on
|
||||
*/
|
||||
TestingBitMapProducer producer = new TestingBitMapProducer(new long[] { 1L, 2L, 3L });
|
||||
TestingBitMapProducer producer = new TestingBitMapProducer(new long[] {1L, 2L, 3L});
|
||||
return IndexProducer.fromBitMapProducer(producer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
return new int[]{0, 65, 128, 129};
|
||||
return new int[] {0, 65, 128, 129};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,7 +72,7 @@ public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTe
|
|||
assertEquals(Integer.valueOf(0 + 128), lst.get(2));
|
||||
assertEquals(Integer.valueOf(1 + 128), lst.get(3));
|
||||
|
||||
BitMapProducer producer = new TestingBitMapProducer(new long[] { 0xFFFFFFFFFFFFFFFFL });
|
||||
BitMapProducer producer = new TestingBitMapProducer(new long[] {0xFFFFFFFFFFFFFFFFL});
|
||||
underTest = IndexProducer.fromBitMapProducer(producer);
|
||||
lst = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public class IndexProducerTest {
|
|||
|
||||
@Test
|
||||
public void fromBitMapProducerTest() {
|
||||
TestingBitMapProducer producer = new TestingBitMapProducer(new long[] { 1L, 2L, 3L });
|
||||
TestingBitMapProducer producer = new TestingBitMapProducer(new long[] {1L, 2L, 3L});
|
||||
IndexProducer underTest = IndexProducer.fromBitMapProducer(producer);
|
||||
List<Integer> lst = new ArrayList<>();
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class IndexProducerTest {
|
|||
assertEquals(Integer.valueOf(0 + 128), lst.get(2));
|
||||
assertEquals(Integer.valueOf(1 + 128), lst.get(3));
|
||||
|
||||
producer = new TestingBitMapProducer(new long[] { 0xFFFFFFFFFFFFFFFFL });
|
||||
producer = new TestingBitMapProducer(new long[] {0xFFFFFFFFFFFFFFFFL});
|
||||
underTest = IndexProducer.fromBitMapProducer(producer);
|
||||
lst = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ public class SetOperationsTest {
|
|||
protected final long bigHashValue = 0xFFFFFFEL;
|
||||
private final Shape shape = Shape.fromKM(17, 72);
|
||||
|
||||
|
||||
private static void assertSymmetricOperation(int expected, ToIntBiFunction<BloomFilter, BloomFilter> operation,
|
||||
BloomFilter filter1, BloomFilter filter2) {
|
||||
assertEquals(expected, operation.applyAsInt(filter1, filter2), "op(filter1, filter2)");
|
||||
|
@ -71,7 +70,7 @@ public class SetOperationsTest {
|
|||
BloomFilter filter2 = createFilter(shape, from1);
|
||||
|
||||
// identical filters should have no distance.
|
||||
double expected = 0;
|
||||
double expected = 0;
|
||||
assertSymmetricOperation(expected, SetOperations::cosineDistance, filter1, filter2);
|
||||
|
||||
Shape shape2 = Shape.fromKM(2, 72);
|
||||
|
@ -215,16 +214,16 @@ public class SetOperationsTest {
|
|||
@Test
|
||||
public final void testOrCardinality() {
|
||||
Shape shape = Shape.fromKM(3, 128);
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63, 64 }));
|
||||
BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 64, 69 }));
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63 }));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 64, 69 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63}));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 63 }));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 64, 69 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63}));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(4, SetOperations::orCardinality, filter1, filter2);
|
||||
}
|
||||
|
||||
|
@ -232,32 +231,32 @@ public class SetOperationsTest {
|
|||
public final void testOrCardinalityWithDifferentLengthFilters() {
|
||||
Shape shape = Shape.fromKM(3, 128);
|
||||
Shape shape2 = Shape.fromKM(3, 192);
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63, 64 }));
|
||||
BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] { 5, 64, 169 }));
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63 }));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] { 5, 64, 169 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63}));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 63 }));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] { 5, 64, 169 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63}));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
assertSymmetricOperation(4, SetOperations::orCardinality, filter1, filter2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testAndCardinality() {
|
||||
Shape shape = Shape.fromKM(3, 128);
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63, 64 }));
|
||||
BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 64, 69 }));
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63 }));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 64, 69 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63}));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(0, SetOperations::andCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 63 }));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 64, 69 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63}));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2);
|
||||
}
|
||||
|
||||
|
@ -265,37 +264,37 @@ public class SetOperationsTest {
|
|||
public final void testAndCardinalityWithDifferentLengthFilters() {
|
||||
Shape shape = Shape.fromKM(3, 128);
|
||||
Shape shape2 = Shape.fromKM(3, 192);
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63, 64 }));
|
||||
BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] { 5, 64, 169 }));
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63 }));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] { 5, 64, 169 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63}));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
assertSymmetricOperation(0, SetOperations::andCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 63 }));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] { 5, 64, 169 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63}));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testXorCardinality() {
|
||||
Shape shape = Shape.fromKM(3, 128);
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63, 64 }));
|
||||
BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 64, 69 }));
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63 }));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 64, 69 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63}));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(5, SetOperations::xorCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 63 }));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 64, 69 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63}));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(3, SetOperations::xorCardinality, filter1, filter2);
|
||||
|
||||
Shape bigShape = Shape.fromKM(3, 192);
|
||||
filter1 = createFilter(bigShape, IndexProducer.fromIndexArray(new int[] { 1, 63, 185}));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 63, 69 }));
|
||||
filter1 = createFilter(bigShape, IndexProducer.fromIndexArray(new int[] {1, 63, 185}));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63, 69}));
|
||||
assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2);
|
||||
}
|
||||
|
||||
|
@ -304,24 +303,23 @@ public class SetOperationsTest {
|
|||
Shape shape = Shape.fromKM(3, 128);
|
||||
Shape shape2 = Shape.fromKM(3, 192);
|
||||
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63, 64 }));
|
||||
BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] { 5, 64, 169 }));
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 1, 63 }));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] { 5, 64, 169 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63}));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
assertSymmetricOperation(5, SetOperations::xorCardinality, filter1, filter2);
|
||||
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] { 5, 63 }));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] { 5, 64, 169 }));
|
||||
filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63}));
|
||||
filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
assertSymmetricOperation(3, SetOperations::xorCardinality, filter1, filter2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public final void testCommutativityOnMismatchedSizes() {
|
||||
BitMapProducer p1 = BitMapProducer.fromBitMapArray(new long[] { 0x3L, 0x5L });
|
||||
BitMapProducer p2 = BitMapProducer.fromBitMapArray(new long[] { 0x1L });
|
||||
BitMapProducer p1 = BitMapProducer.fromBitMapArray(new long[] {0x3L, 0x5L});
|
||||
BitMapProducer p2 = BitMapProducer.fromBitMapArray(new long[] {0x1L});
|
||||
|
||||
assertEquals(SetOperations.orCardinality(p1, p2), SetOperations.orCardinality(p2, p1));
|
||||
assertEquals(SetOperations.xorCardinality(p1, p2), SetOperations.xorCardinality(p2, p1));
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.commons.collections4.bloomfilter;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for the {@link SimpleBloomFilter}.
|
||||
*/
|
||||
|
|
|
@ -33,7 +33,7 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest<SparseBloomFi
|
|||
|
||||
@Test
|
||||
public void testBitMapProducerEdgeCases() {
|
||||
int[] values = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 65, 66, 67, 68, 69, 70, 71 };
|
||||
int[] values = {1, 2, 3, 4, 5, 6, 7, 8, 9, 65, 66, 67, 68, 69, 70, 71};
|
||||
BloomFilter bf = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
|
||||
|
||||
// verify exit early before bitmap boundary
|
||||
|
@ -57,7 +57,7 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest<SparseBloomFi
|
|||
assertEquals(1, passes[0]);
|
||||
|
||||
// verify add extra if all values in first bitmap
|
||||
values = new int[] { 1, 2, 3, 4 };
|
||||
values = new int[] {1, 2, 3, 4};
|
||||
bf = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
|
||||
passes[0] = 0;
|
||||
assertTrue(bf.forEachBitMap(l -> {
|
||||
|
@ -68,7 +68,7 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest<SparseBloomFi
|
|||
|
||||
// verify exit early if all values in first bitmap and predicate returns false
|
||||
// on 2nd block
|
||||
values = new int[] { 1, 2, 3, 4 };
|
||||
values = new int[] {1, 2, 3, 4};
|
||||
bf = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
|
||||
passes[0] = 0;
|
||||
assertFalse(bf.forEachBitMap(l -> {
|
||||
|
|
Loading…
Reference in New Issue