it.unimi.dsi.mg4j.search
Class AbstractOrderedIntervalDocumentIterator

java.lang.Object
  extended by it.unimi.dsi.fastutil.ints.AbstractIntIterator
      extended by it.unimi.dsi.mg4j.search.AbstractDocumentIterator
          extended by it.unimi.dsi.mg4j.search.AbstractCompositeDocumentIterator
              extended by it.unimi.dsi.mg4j.search.AbstractIntersectionDocumentIterator
                  extended by 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.


Nested Class Summary
protected  class AbstractOrderedIntervalDocumentIterator.AbstractOrderedIndexIntervalIterator
          An abstract interval iterator helping in the implementation of ConsecutiveDocumentIterator and OrderedAndDocumentIterator internal interval iterator member classes.
protected  class AbstractOrderedIntervalDocumentIterator.AbstractOrderedIntervalIterator
          An abstract interval iterator helping in the implementation of ConsecutiveDocumentIterator and OrderedAndDocumentIterator interval iterator member classes.
 
Nested classes/interfaces inherited from class it.unimi.dsi.mg4j.search.AbstractCompositeDocumentIterator
AbstractCompositeDocumentIterator.AbstractCompositeIndexIntervalIterator, AbstractCompositeDocumentIterator.AbstractCompositeIntervalIterator
 
Nested classes/interfaces inherited from class it.unimi.dsi.mg4j.search.AbstractDocumentIterator
AbstractDocumentIterator.AbstractIntervalIterator
 
Field Summary
static boolean ASSERTS
           
static boolean DEBUG
           
 
Fields inherited from class it.unimi.dsi.mg4j.search.AbstractIntersectionDocumentIterator
currentIterators, intervalIterators, unmodifiableCurrentIterators
 
Fields inherited from class it.unimi.dsi.mg4j.search.AbstractCompositeDocumentIterator
documentIterator, indexIterator, indices, n, soleIndex
 
Fields inherited from class it.unimi.dsi.mg4j.search.AbstractDocumentIterator
last, next
 
Constructor Summary
protected AbstractOrderedIntervalDocumentIterator(DocumentIterator[] documentIterator)
          Creates a new abstract document iterator.
 
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 class it.unimi.dsi.mg4j.search.AbstractIntersectionDocumentIterator
getComposedIntervalIterator, intervalIterator, intervalIterators
 
Methods inherited from class it.unimi.dsi.mg4j.search.AbstractCompositeDocumentIterator
accept, acceptOnTruePaths, dispose, indices, intervalIterator, toString
 
Methods inherited from class it.unimi.dsi.mg4j.search.AbstractDocumentIterator
document, hasNext, iterator, nextInt
 
Methods inherited from class it.unimi.dsi.fastutil.ints.AbstractIntIterator
next, remove, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface it.unimi.dsi.mg4j.search.DocumentIterator
document, iterator, nextInt
 
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntIterator
skip
 
Methods inherited from interface java.util.Iterator
hasNext, next, remove
 

Field Detail

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values

ASSERTS

public static final boolean ASSERTS
See Also:
Constant Field Values
Constructor Detail

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
Method Detail

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 kInteger.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