public interface BatchIterator
extends java.lang.Cloneable
| 限定符和类型 | 方法和说明 |
|---|---|
void |
advanceIfNeeded(int target)
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.
|
default IntIterator |
asIntIterator(int[] buffer)
Creates a wrapper around the iterator so it behaves like an IntIterator
|
BatchIterator |
clone()
Creates a copy of the iterator.
|
boolean |
hasNext()
Returns true is there are more values to get.
|
int |
nextBatch(int[] buffer)
Writes the next batch of integers onto the buffer,
and returns how many were written.
|
int nextBatch(int[] buffer)
buffer - - the target to write ontoboolean hasNext()
BatchIterator clone()
default IntIterator asIntIterator(int[] buffer)
buffer - - array to buffer bits into (size 128-256 should be best).void advanceIfNeeded(int target)
int[] buffer = new int[128];
BatchIterator j = // get an iterator
int val = // first value from my other data structure
j.advanceIfNeeded(val);
while ( j.hasNext() ) {
int limit = j.nextBatch(buffer);
for (int i = 0; i < limit; i++) {
if (buffer[i] == val) {
// got it!
// 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.target - threshold