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);
}
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);
}
}
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);
}
}
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);
}
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))) ;
}
Aggregations