use of org.roaringbitmap.PeekableIntIterator in project narchy by automenta.
the class CountMinRoar method whileEachInt.
public void whileEachInt(IntIntPredicate each) {
PeekableIntIterator s = set.getIntIterator();
int next;
while (s.hasNext() && each.accept(next = s.next(), count(next))) ;
}
use of org.roaringbitmap.PeekableIntIterator in project narchy by automenta.
the class MatchConstraint method combineConstraints.
public static PrediTerm<Derivation> combineConstraints(AndCondition a) {
RoaringBitmap constraints = new RoaringBitmap();
@NotNull PrediTerm[] cond1 = a.cond;
for (int i = 0, cl = cond1.length; i < cl; i++) {
Term x = cond1[i];
if (x instanceof MatchConstraint) {
constraints.add(i);
}
}
if (constraints.getCardinality() < 2) {
return a;
} else {
// identify contiguous runs of constraints
// inclusive
List<IntIntPair> ranges = new FasterList<>(1);
int start = -1, end = -1;
PeekableIntIterator ii = constraints.getIntIterator();
while (ii.hasNext()) {
int next = ii.next();
if (start == -1) {
start = end = next;
} else {
if (next == end + 1) {
end++;
} else {
if (end - start >= 1) {
// compile that range
ranges.add(pair(start, end));
}
// broken
start = -1;
}
}
}
if (end - start >= 1)
ranges.add(pair(start, end));
if (ranges.size() > 1)
throw new TODO();
IntIntPair rr = ranges.get(0);
List<PrediTerm<Derivation>> l = new FasterList();
int i;
for (i = 0; i < start; i++) {
l.add(a.cond[i]);
}
CompoundConstraint.the(Util.map(MatchConstraint.class::cast, MatchConstraint[]::new, ArrayUtils.subarray(a.cond, rr.getOne(), rr.getTwo() + 1))).forEach(l::add);
i = end + 1;
for (; i < a.cond.length; i++) {
l.add(a.cond[i]);
}
return AndCondition.the((List) l);
}
}
use of org.roaringbitmap.PeekableIntIterator in project RoaringBitmap by RoaringBitmap.
the class TestRoaringBitmap method report128.
@Test
public void report128() {
MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
bitmap.add(59798854);
bitmap.add(91274955);
bitmap.add(97569495);
bitmap.add(101993170);
PeekableIntIterator it = bitmap.getIntIterator();
it.advanceIfNeeded(100620278);
Assert.assertTrue(it.hasNext());
Assert.assertEquals(101993170, it.next());
Assert.assertFalse(it.hasNext());
}
use of org.roaringbitmap.PeekableIntIterator in project RoaringBitmap by RoaringBitmap.
the class TestIntIteratorFlyweight method testIterationFromBitmap.
@Test
public void testIterationFromBitmap() {
final Random source = new Random(0xcb000a2b9b5bdfb6l);
final int[] data = takeSortedAndDistinct(source, 450000);
MutableRoaringBitmap bitmap = MutableRoaringBitmap.bitmapOf(data);
BufferIntIteratorFlyweight iter = new BufferIntIteratorFlyweight(bitmap);
Assert.assertEquals(iter.peekNext(), data[0]);
Assert.assertEquals(iter.peekNext(), data[0]);
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]);
}
BufferReverseIntIteratorFlyweight reverseIter = new BufferReverseIntIteratorFlyweight(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 testEmptySkips.
@Test
public void testEmptySkips() {
MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
PeekableIntIterator it = bitmap.getIntIterator();
it.advanceIfNeeded(0);
}
Aggregations