use of java.util.PrimitiveIterator.OfInt in project jenetics by jenetics.
the class RandomIndexStreamTest method reference.
@Test
public void reference() {
final int size = 5000;
final double p = 0.5;
final Random random1 = new Random(0);
final Random random2 = new Random(0);
for (int j = 0; j < 1; ++j) {
final OfInt it = indexes(random1, size, p).iterator();
final IndexStream stream2 = ReferenceRandomStream(size, p, random2);
while (it.hasNext()) {
Assert.assertEquals(it.nextInt(), stream2.next());
}
Assert.assertFalse(it.hasNext());
Assert.assertEquals(stream2.next(), -1);
}
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class HasherBloomFilter method contains.
@Override
public boolean contains(final Hasher hasher) {
verifyHasher(hasher);
final Set<Integer> set = new TreeSet<>();
hasher.iterator(getShape()).forEachRemaining((IntConsumer) set::add);
final OfInt iter = this.hasher.iterator(getShape());
while (iter.hasNext()) {
final int idx = iter.nextInt();
set.remove(idx);
if (set.isEmpty()) {
return true;
}
}
return false;
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class AbstractBloomFilter method contains.
@Override
public boolean contains(final Hasher hasher) {
verifyHasher(hasher);
final long[] buff = getBits();
final OfInt iter = hasher.iterator(shape);
while (iter.hasNext()) {
final int idx = iter.nextInt();
BloomFilterIndexer.checkPositive(idx);
final int buffIdx = BloomFilterIndexer.getLongIndex(idx);
final long buffOffset = BloomFilterIndexer.getLongBit(idx);
if ((buff[buffIdx] & buffOffset) == 0) {
return false;
}
}
return true;
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class BitSetBloomFilter method contains.
@Override
public boolean contains(final Hasher hasher) {
verifyHasher(hasher);
final OfInt iter = hasher.iterator(getShape());
while (iter.hasNext()) {
if (!bitSet.get(iter.nextInt())) {
return false;
}
}
return true;
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class DynamicHasherBuilderTest method buildTest_byteArray.
/**
* Tests that hashing a byte array works as expected.
*/
@Test
public void buildTest_byteArray() {
final byte[] bytes = testString.getBytes();
final DynamicHasher hasher = builder.with(bytes).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());
}
Aggregations