Package org.roaringbitmap.longlong
Class Roaring64Bitmap.PeekableIterator
- java.lang.Object
-
- org.roaringbitmap.longlong.Roaring64Bitmap.PeekableIterator
-
- All Implemented Interfaces:
java.lang.Cloneable
,LongIterator
,PeekableLongIterator
- Direct Known Subclasses:
Roaring64Bitmap.ForwardPeekableIterator
,Roaring64Bitmap.ReversePeekableIterator
- Enclosing class:
- Roaring64Bitmap
private abstract class Roaring64Bitmap.PeekableIterator extends java.lang.Object implements PeekableLongIterator
-
-
Field Summary
Fields Modifier and Type Field Description private PeekableCharIterator
charIterator
private byte[]
high
private LeafNodeIterator
keyIte
-
Constructor Summary
Constructors Constructor Description PeekableIterator(LeafNodeIterator keyIte)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
advanceIfNeeded(long minval)
If needed, for a forwards iterator advance as long as the next value is smaller than thresholdVal For a reverse iterator advance as long as the next value is greater than thresholdVal The advanceIfNeeded method is used for performance reasons, to skip over unnecessary repeated calls to next.PeekableLongIterator
clone()
Creates a copy of the iterator.(package private) abstract boolean
compare(long next, long val)
(package private) abstract boolean
compareHigh(byte[] next, byte[] val)
(package private) abstract PeekableCharIterator
getIterator(Container container)
boolean
hasNext()
long
next()
long
peekNext()
Look at the next value without advancing The peek is useful when working with several iterators at once.
-
-
-
Field Detail
-
keyIte
private final LeafNodeIterator keyIte
-
high
private byte[] high
-
charIterator
private PeekableCharIterator charIterator
-
-
Constructor Detail
-
PeekableIterator
PeekableIterator(LeafNodeIterator keyIte)
-
-
Method Detail
-
getIterator
abstract PeekableCharIterator getIterator(Container container)
-
compare
abstract boolean compare(long next, long val)
-
compareHigh
abstract boolean compareHigh(byte[] next, byte[] val)
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfaceLongIterator
- Returns:
- whether there is another value
-
next
public long next()
- Specified by:
next
in interfaceLongIterator
- Returns:
- next long value
-
advanceIfNeeded
public void advanceIfNeeded(long minval)
Description copied from interface:PeekableLongIterator
If needed, for a forwards iterator advance as long as the next value is smaller than thresholdVal For a reverse iterator advance as long as the next value is greater than thresholdVal The advanceIfNeeded method is used for performance reasons, to skip over unnecessary repeated calls to next. Suppose for example that you wish to compute the intersection between an ordered list of longs (e.g., longs[] x = {1,4,5}) and a PeekableIntIterator. You might do it as follows...
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.PeekableLongIterator j = // get an iterator long 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); }
- Specified by:
advanceIfNeeded
in interfacePeekableLongIterator
- Parameters:
minval
- threshold
-
peekNext
public long peekNext()
Description copied from interface:PeekableLongIterator
Look at the next value without advancing The peek is useful when working with several iterators at once. Suppose that you have 100 iterators, and you want to compute their intersections without materializing the result. You might do it as follows...
Notice how the peek method allows you to compare iterators in a way that the next method could not do.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 PeekableLongIterator pi = pq.poll(); long x = pi.next(); // advance // do something with x if(pi.hasNext()) pq.add(pi) }
- Specified by:
peekNext
in interfacePeekableLongIterator
- Returns:
- next value
-
clone
public PeekableLongIterator clone()
Description copied from interface:PeekableLongIterator
Creates a copy of the iterator.- Specified by:
clone
in interfaceLongIterator
- Specified by:
clone
in interfacePeekableLongIterator
- Overrides:
clone
in classjava.lang.Object
- Returns:
- a clone of the current iterator
-
-