use of java.util.PrimitiveIterator.OfInt 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());
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class DynamicHasherBuilderTest method buildTest_UnencodedString.
/**
* Tests that hashing a string works as expected.
*/
@Test
public void buildTest_UnencodedString() {
final byte[] bytes = testString.getBytes(StandardCharsets.UTF_16LE);
final DynamicHasher hasher = builder.withUnencoded(testString).build();
final int expected = (int) Math.floorMod((long) hf.apply(bytes, 0), (long) shape.getNumberOfBits());
final OfInt iter = hasher.iterator(shape);
assertTrue(iter.hasNext());
assertEquals(expected, iter.nextInt());
assertFalse(iter.hasNext());
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class DynamicHasherBuilderTest method buildTest_String.
/**
* Tests that hashing a string works as expected.
*/
@Test
public void buildTest_String() {
final byte[] bytes = testString.getBytes(StandardCharsets.UTF_8);
final DynamicHasher hasher = builder.with(testString, StandardCharsets.UTF_8).build();
final int expected = (int) Math.floorMod((long) hf.apply(bytes, 0), (long) shape.getNumberOfBits());
final OfInt iter = hasher.iterator(shape);
assertTrue(iter.hasNext());
assertEquals(expected, iter.nextInt());
assertFalse(iter.hasNext());
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class DynamicHasherTest method testGetBits.
/**
* Tests that the expected bits are returned from hashing.
*/
@Test
public void testGetBits() {
final int[] expected = { 6, 69, 44, 19, 10, 57, 48, 23, 70, 61, 36, 11, 2, 49, 24, 15, 62 };
final Hasher hasher = builder.with("Hello", StandardCharsets.UTF_8).build();
final OfInt iter = hasher.iterator(shape);
for (final int element : expected) {
assertTrue(iter.hasNext());
assertEquals(element, iter.nextInt());
}
assertFalse(iter.hasNext());
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class StaticHasherTest method testGetBits_DuplicateValues.
/**
* Tests that iterator does not return duplicates and orders the indices.
*/
@Test
public void testGetBits_DuplicateValues() {
final int[] input = { 6, 69, 44, 19, 10, 57, 48, 23, 70, 61, 36, 11, 2, 49, 24, 15, 62, 1, 63, 53, 43, 17, 7, 69, 59, 49, 39, 13, 3, 65, 55, 45, 35, 25 };
final int[] expected = { 1, 2, 3, 6, 7, 10, 11, 13, 15, 17, 19, 23, 24, 25, 35, 36, 39, 43, 44, 45, 48, 49, 53, 55, 57, 59, 61, 62, 63, 65, 69, 70 };
final StaticHasher hasher = new StaticHasher(Arrays.stream(input).iterator(), shape);
final OfInt iter = hasher.iterator(shape);
for (final int element : expected) {
assertTrue(iter.hasNext());
assertEquals(element, iter.nextInt());
}
assertFalse(iter.hasNext());
}
Aggregations