Search in sources :

Example 11 with OfInt

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);
    }
}
Also used : OfInt(java.util.PrimitiveIterator.OfInt) Random(java.util.Random) Test(org.testng.annotations.Test)

Example 12 with OfInt

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;
}
Also used : OfInt(java.util.PrimitiveIterator.OfInt) TreeSet(java.util.TreeSet)

Example 13 with OfInt

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;
}
Also used : OfInt(java.util.PrimitiveIterator.OfInt)

Example 14 with OfInt

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;
}
Also used : OfInt(java.util.PrimitiveIterator.OfInt)

Example 15 with OfInt

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());
}
Also used : OfInt(java.util.PrimitiveIterator.OfInt) Test(org.junit.jupiter.api.Test)

Aggregations

OfInt (java.util.PrimitiveIterator.OfInt)22 Test (org.junit.jupiter.api.Test)12 Random (java.util.Random)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 TreeSet (java.util.TreeSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Hasher (org.apache.commons.collections4.bloomfilter.hasher.Hasher)2 Shape (org.apache.commons.collections4.bloomfilter.hasher.Shape)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 IntBuffer (java.nio.IntBuffer)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1