// keep track of the next item that we want to retain
boolean wantToRetainMore = iter.hasNext();
long nextToRetain = wantToRetainMore ? iter.nextLong() : 0;
// scan all items, keeping only the ones to keep
IntIterator posIter = keys.activeIndexIterator(true);
while (posIter.hasNext()) {
final int pos = posIter.nextInt();
final long cur = keys.getKey(pos);
while (wantToRetainMore && nextToRetain < cur) {
// gone past next to retain, advance it
wantToRetainMore = iter.hasNext();
nextToRetain = wantToRetainMore ? iter.nextLong() : 0;