use of org.apache.commons.collections4.bloomfilter.hasher.Hasher in project commons-collections by apache.
the class AbstractBloomFilterTest method constructorTest_Hasher.
/**
* Tests that creating a filter with a hasher works as expected.
*/
@Test
public final void constructorTest_Hasher() {
final List<Integer> lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
final Hasher hasher = new StaticHasher(lst.iterator(), shape);
final BloomFilter bf = createFilter(hasher, shape);
final long[] lb = bf.getBits();
assertEquals(0x1FFFF, lb[0]);
assertEquals(1, lb.length);
}
use of org.apache.commons.collections4.bloomfilter.hasher.Hasher in project commons-collections by apache.
the class AbstractBloomFilterTest method xorCardinalityTest.
/**
* Tests that the andCardinality calculations are correct.
*
* @param filterFactory the factory function to create the filter
*/
private void xorCardinalityTest(final BiFunction<Hasher, Shape, BloomFilter> filterFactory) {
final List<Integer> lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
final Hasher hasher = new StaticHasher(lst.iterator(), shape);
final BloomFilter bf = createFilter(hasher, shape);
final List<Integer> lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape);
final BloomFilter bf2 = filterFactory.apply(hasher2, shape);
assertEquals(20, bf.xorCardinality(bf2));
}
use of org.apache.commons.collections4.bloomfilter.hasher.Hasher in project commons-collections by apache.
the class AbstractBloomFilterTest method orCardinalityTest.
/**
* Tests that the andCardinality calculations are correct.
*
* @param filterFactory the factory function to create the filter
*/
private void orCardinalityTest(final BiFunction<Hasher, Shape, BloomFilter> filterFactory) {
final List<Integer> lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
final Hasher hasher = new StaticHasher(lst.iterator(), shape);
final AbstractBloomFilter bf = createFilter(hasher, shape);
final List<Integer> lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape);
final BloomFilter bf2 = filterFactory.apply(hasher2, shape);
assertEquals(27, bf.orCardinality(bf2));
}
use of org.apache.commons.collections4.bloomfilter.hasher.Hasher in project commons-collections by apache.
the class AbstractBloomFilterTest method andCardinalityTest.
/**
* Tests that the andCardinality calculations are correct.
*
* @param filterFactory the factory function to create the filter
*/
private void andCardinalityTest(final BiFunction<Hasher, Shape, BloomFilter> filterFactory) {
final List<Integer> lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
final Hasher hasher = new StaticHasher(lst.iterator(), shape);
final BloomFilter bf = createFilter(hasher, shape);
final List<Integer> lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape);
final BloomFilter bf2 = filterFactory.apply(hasher2, shape);
assertEquals(7, bf.andCardinality(bf2));
}
use of org.apache.commons.collections4.bloomfilter.hasher.Hasher in project commons-collections by apache.
the class AbstractBloomFilterTest method constructorTest_WrongShape.
/**
* Tests that creating a Bloom filter with a Static hasher that has one shape and a
* different specified shape fails.
*/
@Test
public final void constructorTest_WrongShape() {
final Shape anotherShape = new Shape(testFunctionX, 3, 72, 17);
final List<Integer> lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
final Hasher hasher = new StaticHasher(lst.iterator(), anotherShape);
assertThrows(IllegalArgumentException.class, () -> createFilter(hasher, shape), "Should throw IllegalArgumentException");
}
Aggregations