public class BufferIntIteratorFlyweight extends Object implements PeekableIntIterator
wrap(ImmutableRoaringBitmap)
For better performance, consider the ImmutableRoaringBitmap.forEach(org.roaringbitmap.IntConsumer)
method.Constructor and Description |
---|
BufferIntIteratorFlyweight()
Creates an instance that is not ready for iteration.
|
BufferIntIteratorFlyweight(ImmutableRoaringBitmap r)
Creates an instance that is ready for iteration.
|
Modifier and Type | Method and Description |
---|---|
void |
advanceIfNeeded(int minval)
If needed, advance as long as the next value is smaller than minval
The advanceIfNeeded method is used for performance reasons, to skip
over unnecessary repeated calls to next.
|
PeekableIntIterator |
clone()
Creates a copy of the iterator.
|
boolean |
hasNext() |
int |
next() |
int |
peekNext()
Look at the next value without advancing
The peek is useful when working with several iterators at once.
|
void |
wrap(ImmutableRoaringBitmap r)
Prepares a bitmap for iteration
|
public BufferIntIteratorFlyweight()
wrap(ImmutableRoaringBitmap)
.public BufferIntIteratorFlyweight(ImmutableRoaringBitmap r)
r
- bitmap to be iterated overpublic PeekableIntIterator clone()
PeekableIntIterator
clone
in interface IntIterator
clone
in interface PeekableIntIterator
clone
in class Object
public boolean hasNext()
hasNext
in interface IntIterator
public int next()
next
in interface IntIterator
public void wrap(ImmutableRoaringBitmap r)
r
- bitmap to be iterated overpublic void advanceIfNeeded(int minval)
PeekableIntIterator
PeekableIntIterator j = // get an iterator
int val = // first value from my other data structure
j.advanceIfNeeded(val);
while ( j.hasNext() ) {
if(j.next() == val) {
// ah! ah! val is in the intersection...
// do something here
val = // get next value?
}
j.advanceIfNeeded(val);
}
The benefit of calling advanceIfNeeded is that each such call
can be much faster than repeated calls to "next". The underlying
implementation can "skip" over some data.advanceIfNeeded
in interface PeekableIntIterator
minval
- thresholdpublic int peekNext()
PeekableIntIterator
PriorityQueue pq = new PriorityQueue(100,
new Comparator<PeekableIntIterator>() {
public int compare(PeekableIntIterator a,
PeekableIntIterator b) {
return a.peek() - b.peek();
}
});
//... populate pq
while(! pq.isEmpty() ) {
// get iterator with a smallest value
PeekableIntIterator pi = pq.poll();
int x = pi.next(); // advance
// do something with x
if(pi.hasNext()) pq.add(pi)
}
Notice how the peek method allows you to compare iterators in a way
that the next method could not do.peekNext
in interface PeekableIntIterator
Copyright © 2018. All rights reserved.