it.unimi.dsi.mg4j.search
Class AbstractOrderedIntervalDocumentIterator
java.lang.Object
it.unimi.dsi.fastutil.ints.AbstractIntIterator
it.unimi.dsi.mg4j.search.AbstractDocumentIterator
it.unimi.dsi.mg4j.search.AbstractCompositeDocumentIterator
it.unimi.dsi.mg4j.search.AbstractIntersectionDocumentIterator
it.unimi.dsi.mg4j.search.AbstractOrderedIntervalDocumentIterator
- All Implemented Interfaces:
- IntIterator, DocumentIterator, Iterable<Interval>, Iterator<Integer>
- Direct Known Subclasses:
- ConsecutiveDocumentIterator, OrderedAndDocumentIterator
public abstract class AbstractOrderedIntervalDocumentIterator
- extends AbstractIntersectionDocumentIterator
An abstract document iterator helping in the implementation of ConsecutiveDocumentIterator
and OrderedAndDocumentIterator
.
Method Summary |
int |
nextDocument()
Returns the next document provided by this document iterator, or -1 if no more documents are available. |
int |
skipTo(int n)
Skips all documents smaller than n . |
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntIterator |
skip |
DEBUG
public static final boolean DEBUG
- See Also:
- Constant Field Values
ASSERTS
public static final boolean ASSERTS
- See Also:
- Constant Field Values
AbstractOrderedIntervalDocumentIterator
protected AbstractOrderedIntervalDocumentIterator(DocumentIterator[] documentIterator)
throws IOException
- Creates a new abstract document iterator.
- Parameters:
documentIterator
- the underlying document iterators (at least one). The must all return the same
singleton set as DocumentIterator.indices()
.
- Throws:
IOException
nextDocument
public int nextDocument()
throws IOException
- Description copied from interface:
DocumentIterator
- Returns the next document provided by this document iterator, or -1 if no more documents are available.
Warning: the specification of this method has significantly changed as of MG4J 1.2.
The special return value -1 is used to mark the end of iteration (a NoSuchElementException
would have been thrown before in that case, so ho harm should be caused by this change). The reason
for this change is providing fully lazy iteration over documents. Fully lazy iteration
does not provide an hasNext()
method—you have to actually ask for the next
element and check the return value. Fully lazy iteration is much lighter on method calls (half) and
in most (if not all) MG4J classes leads to a much simpler logic. Moreover, DocumentIterator.nextDocument()
can be specified as throwing an IOException
, which avoids the pernicious proliferation
of try/catch blocks in very short, low-level methods (it was having a detectable impact on performance).
- Specified by:
nextDocument
in interface DocumentIterator
- Overrides:
nextDocument
in class AbstractIntersectionDocumentIterator
- Returns:
- the next document, or -1 if no more documents are available.
- Throws:
IOException
skipTo
public int skipTo(int n)
throws IOException
- Description copied from interface:
DocumentIterator
- Skips all documents smaller than
n
.
Define the current document k
associated with this document iterator
as follows:
If k
is larger than or equal to n
, then
this method does nothing and returns k
. Otherwise, a
call to this method is equivalent to
while( ( k = nextDocument() ) < n && k != -1 );
return k == -1 ? Integer.MAX_VALUE : k;
Thus, when a result k
≠ Integer.MAX_VALUE
is returned, the state of this iterator
will be exactly the same as after a call to DocumentIterator.nextDocument()
that returned k
.
In particular, the first document larger than or equal to n
(when returned
by this method) will not be returned by the next call to
DocumentIterator.nextDocument()
.
- Specified by:
skipTo
in interface DocumentIterator
- Overrides:
skipTo
in class AbstractIntersectionDocumentIterator
- Parameters:
n
- a document pointer.
- Returns:
- a document pointer larger than or equal to
n
if available, Integer.MAX_VALUE
otherwise.
- Throws:
IOException