Search in sources :

Example 1 with OfLong

use of java.util.PrimitiveIterator.OfLong in project netty by netty.

the class LongLongHashMapTest method randomOperations.

@Test
public void randomOperations() {
    int operations = 6000;
    ThreadLocalRandom tlr = ThreadLocalRandom.current();
    Map<Long, Long> expected = new HashMap<Long, Long>();
    LongLongHashMap actual = new LongLongHashMap(-1);
    OfLong itr = tlr.longs(0, operations).limit(operations * 50).iterator();
    while (itr.hasNext()) {
        long value = itr.nextLong();
        if (expected.containsKey(value)) {
            assertThat(actual.get(value)).isEqualTo(expected.get(value));
            if (tlr.nextBoolean()) {
                actual.remove(value);
                expected.remove(value);
                assertThat(actual.get(value)).isEqualTo(-1);
            } else {
                long v = expected.get(value);
                assertThat(actual.put(value, -v)).isEqualTo(expected.put(value, -v));
            }
        } else {
            assertThat(actual.get(value)).isEqualTo(-1);
            assertThat(actual.put(value, value)).isEqualTo(-1);
            expected.put(value, value);
        }
    }
}
Also used : OfLong(java.util.PrimitiveIterator.OfLong) HashMap(java.util.HashMap) OfLong(java.util.PrimitiveIterator.OfLong) ThreadLocalRandom(io.netty.util.internal.ThreadLocalRandom) Test(org.junit.jupiter.api.Test)

Example 2 with OfLong

use of java.util.PrimitiveIterator.OfLong in project gridss by PapenfussLab.

the class DeBruijnSequenceGraphNodeUtil method basesDifferent.

/**
 * Returns the number of bases difference between the two paths
 * @param k
 * @param pathA
 * @param pathB
 * @param forwardKmerTraversal sequence to successor next kmers
 * @return number of bases difference
 */
public static int basesDifferent(int k, LongStream pathA, LongStream pathB, boolean forwardKmerTraversal) {
    OfLong itA = pathA.iterator();
    OfLong itB = pathB.iterator();
    if (!itA.hasNext() || !itB.hasNext())
        return 0;
    int diff = KmerEncodingHelper.basesDifference(k, itA.nextLong(), itB.nextLong());
    while (itA.hasNext() && itB.hasNext()) {
        if (forwardKmerTraversal) {
            if (!KmerEncodingHelper.lastBaseMatches(k, itA.nextLong(), itB.nextLong())) {
                diff++;
            }
        } else {
            if (!KmerEncodingHelper.firstBaseMatches(k, itA.nextLong(), itB.nextLong())) {
                diff++;
            }
        }
    }
    return diff;
}
Also used : OfLong(java.util.PrimitiveIterator.OfLong)

Aggregations

OfLong (java.util.PrimitiveIterator.OfLong)2 ThreadLocalRandom (io.netty.util.internal.ThreadLocalRandom)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1