Search in sources :

Example 1 with HashFunctionIdentity

use of org.apache.commons.collections4.bloomfilter.hasher.HashFunctionIdentity in project commons-collections by apache.

the class HasherBloomFilterTest method getBitsTest_LowestBitOnly.

/**
 * Test the edge case where the filter has only 1 bit in the lowest index and the getBits()
 * function returns an array of length 1.
 */
@Test
public void getBitsTest_LowestBitOnly() {
    final BloomFilter filter = createEmptyFilter(shape);
    // Set the lowest bit index only.
    filter.merge(new Hasher() {

        @Override
        public OfInt iterator(final Shape shape) {
            return Arrays.stream(new int[] { 0 }).iterator();
        }

        @Override
        public HashFunctionIdentity getHashFunctionIdentity() {
            return shape.getHashFunctionIdentity();
        }
    });
    assertArrayEquals(new long[] { 1L }, filter.getBits());
}
Also used : OfInt(java.util.PrimitiveIterator.OfInt) Hasher(org.apache.commons.collections4.bloomfilter.hasher.Hasher) DynamicHasher(org.apache.commons.collections4.bloomfilter.hasher.DynamicHasher) Shape(org.apache.commons.collections4.bloomfilter.hasher.Shape) HashFunctionIdentity(org.apache.commons.collections4.bloomfilter.hasher.HashFunctionIdentity) Test(org.junit.jupiter.api.Test)

Aggregations

OfInt (java.util.PrimitiveIterator.OfInt)1 DynamicHasher (org.apache.commons.collections4.bloomfilter.hasher.DynamicHasher)1 HashFunctionIdentity (org.apache.commons.collections4.bloomfilter.hasher.HashFunctionIdentity)1 Hasher (org.apache.commons.collections4.bloomfilter.hasher.Hasher)1 Shape (org.apache.commons.collections4.bloomfilter.hasher.Shape)1 Test (org.junit.jupiter.api.Test)1