Search in sources :

Example 1 with PeekableIntIterator

use of org.roaringbitmap.PeekableIntIterator in project RoaringBitmap by RoaringBitmap.

the class TestIntIteratorFlyweight method testIteration.

@Test
public void testIteration() {
    final Random source = new Random(0xcb000a2b9b5bdfb6l);
    final int[] data = takeSortedAndDistinct(source, 450000);
    MutableRoaringBitmap bitmap = MutableRoaringBitmap.bitmapOf(data);
    BufferIntIteratorFlyweight iter = new BufferIntIteratorFlyweight();
    iter.wrap(bitmap);
    BufferIntIteratorFlyweight iter2 = new BufferIntIteratorFlyweight(bitmap);
    PeekableIntIterator j = bitmap.getIntIterator();
    for (int k = 0; k < data.length; k += 3) {
        iter2.advanceIfNeeded(data[k]);
        iter2.advanceIfNeeded(data[k]);
        j.advanceIfNeeded(data[k]);
        j.advanceIfNeeded(data[k]);
        Assert.assertEquals(j.peekNext(), data[k]);
        Assert.assertEquals(iter2.peekNext(), data[k]);
    }
    new BufferIntIteratorFlyweight(bitmap).advanceIfNeeded(-1);
    // should not crash
    bitmap.getIntIterator().advanceIfNeeded(-1);
    BufferReverseIntIteratorFlyweight reverseIter = new BufferReverseIntIteratorFlyweight();
    reverseIter.wrap(bitmap);
    final List<Integer> intIteratorCopy = asList(iter);
    final List<Integer> reverseIntIteratorCopy = asList(reverseIter);
    Assert.assertEquals(bitmap.getCardinality(), intIteratorCopy.size());
    Assert.assertEquals(bitmap.getCardinality(), reverseIntIteratorCopy.size());
    Assert.assertEquals(Ints.asList(data), intIteratorCopy);
    Assert.assertEquals(Lists.reverse(Ints.asList(data)), reverseIntIteratorCopy);
}
Also used : Random(java.util.Random) PeekableIntIterator(org.roaringbitmap.PeekableIntIterator) Test(org.junit.Test)

Example 2 with PeekableIntIterator

use of org.roaringbitmap.PeekableIntIterator in project RoaringBitmap by RoaringBitmap.

the class TestIterators method testSkipsRun.

@Test
public void testSkipsRun() {
    MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
    bitmap.add(4L, 100000L);
    bitmap.runOptimize();
    for (int i = 4; i < 100000; ++i) {
        PeekableIntIterator pii = bitmap.getIntIterator();
        pii.advanceIfNeeded(i);
        Assert.assertEquals(pii.peekNext(), i);
        Assert.assertEquals(pii.next(), i);
    }
}
Also used : PeekableIntIterator(org.roaringbitmap.PeekableIntIterator) Test(org.junit.Test)

Example 3 with PeekableIntIterator

use of org.roaringbitmap.PeekableIntIterator in project RoaringBitmap by RoaringBitmap.

the class TestIterators method testSkipsDense.

@Test
public void testSkipsDense() {
    MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
    int N = 100000;
    for (int i = 0; i < N; ++i) {
        bitmap.add(2 * i);
    }
    for (int i = 0; i < N; ++i) {
        PeekableIntIterator pii = bitmap.getIntIterator();
        pii.advanceIfNeeded(2 * i);
        Assert.assertEquals(pii.peekNext(), 2 * i);
        Assert.assertEquals(pii.next(), 2 * i);
    }
}
Also used : PeekableIntIterator(org.roaringbitmap.PeekableIntIterator) Test(org.junit.Test)

Example 4 with PeekableIntIterator

use of org.roaringbitmap.PeekableIntIterator in project RoaringBitmap by RoaringBitmap.

the class TestIterators method testSkips.

@Test
public void testSkips() {
    final Random source = new Random(0xcb000a2b9b5bdfb6l);
    final int[] data = takeSortedAndDistinct(source, 45000);
    MutableRoaringBitmap bitmap = MutableRoaringBitmap.bitmapOf(data);
    PeekableIntIterator pii = bitmap.getIntIterator();
    for (int i = 0; i < data.length; ++i) {
        pii.advanceIfNeeded(data[i]);
        Assert.assertEquals(data[i], pii.peekNext());
    }
    pii = bitmap.getIntIterator();
    for (int i = 0; i < data.length; ++i) {
        pii.advanceIfNeeded(data[i]);
        Assert.assertEquals(data[i], pii.next());
    }
    pii = bitmap.getIntIterator();
    for (int i = 1; i < data.length; ++i) {
        pii.advanceIfNeeded(data[i - 1]);
        pii.next();
        Assert.assertEquals(data[i], pii.peekNext());
    }
    bitmap.getIntIterator().advanceIfNeeded(-1);
}
Also used : Random(java.util.Random) PeekableIntIterator(org.roaringbitmap.PeekableIntIterator) Test(org.junit.Test)

Example 5 with PeekableIntIterator

use of org.roaringbitmap.PeekableIntIterator in project narchy by automenta.

the class CountMinRoar method whileEachShort.

public void whileEachShort(ShortIntPredicate each) {
    PeekableIntIterator s = set.getIntIterator();
    short next;
    while (s.hasNext() && each.accept(next = (short) s.next(), count(next))) ;
}
Also used : PeekableIntIterator(org.roaringbitmap.PeekableIntIterator)

Aggregations

PeekableIntIterator (org.roaringbitmap.PeekableIntIterator)11 Test (org.junit.Test)8 Random (java.util.Random)3 TODO (jcog.TODO)1 Util (jcog.Util)1 FasterList (jcog.list.FasterList)1 Term (nars.term.Term)1 PrediTerm (nars.term.pred.PrediTerm)1 IntIntPair (org.eclipse.collections.api.tuple.primitive.IntIntPair)1 NotNull (org.jetbrains.annotations.NotNull)1 RoaringBitmap (org.roaringbitmap.RoaringBitmap)1