Bloom filter code clean-up

Correct whitespace issues.

Javadoc additions and corrections.
This commit is contained in:
Alex Herbert 2022-11-05 22:06:15 +00:00
parent a251c18dae
commit 3071aea62d
39 changed files with 149 additions and 138 deletions

View File

@ -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);
}

View File

@ -58,7 +58,7 @@ public interface BitMapProducer {
* 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.

View File

@ -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);
}
/**

View File

@ -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>

View File

@ -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.

View File

@ -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());
}
}
@ -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

View File

@ -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

View File

@ -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);

View File

@ -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();

View File

@ -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};
}
}

View File

@ -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};
}
}

View File

@ -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} };
}

View File

@ -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}};
}
}

View File

@ -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};
}
}

View File

@ -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};
}
}

View File

@ -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}};
}
}

View File

@ -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};
}
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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,8 +114,9 @@ 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(
@ -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));
}

View File

@ -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));
}

View File

@ -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

View File

@ -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);

View File

@ -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<>();

View File

@ -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<>();

View File

@ -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)");
@ -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));

View File

@ -16,7 +16,6 @@
*/
package org.apache.commons.collections4.bloomfilter;
/**
* Tests for the {@link SimpleBloomFilter}.
*/

View File

@ -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 -> {