it.unimi.dsi.mg4j.search
Class AbstractUnionDocumentIterator

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.AbstractUnionDocumentIterator
All Implemented Interfaces:
IntIterator, DocumentIterator, Iterable<Interval>, Iterator<Integer>
Direct Known Subclasses:
MultiTermIndexIterator, OrDocumentIterator

public abstract class AbstractUnionDocumentIterator
extends AbstractCompositeDocumentIterator

A document iterator on documents, generating the union of the documents returned by a number of document iterators.

The pattern of this class is the same as that of AbstractIntersectionDocumentIterator. Additionally, this class provides a mechanism that makes accessible the set of component document iterators that are positioned on the current document.


Nested Class Summary
 
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
protected  int[] curr
          The reference array used for the queue.
protected  int[] front
          The IndirectPriorityQueue.front(int[]) of queue, if frontSize is not -1.
protected  int frontSize
          The number of valid entries in front, or -1 if the front has not been computed for the current document.
protected  IntHeapSemiIndirectPriorityQueue queue
          A heap-based semi-indirect priority queue used to keep track of the currently scanned integers.
 
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, weight
 
Constructor Summary
protected AbstractUnionDocumentIterator(DocumentIterator... documentIterator)
          Creates a new document iterator that computes the OR of the given array of iterators.
 
Method Summary
<T> T
acceptOnTruePaths(DocumentIteratorVisitor<T> visitor)
          Invokes acceptOnTruePaths(DocumentIteratorVisitor) only on component iterators positioned on the current document.
protected  int computeFront()
          Forces computation of the current front, returning the number of indices it contains.
protected abstract  IntervalIterator getComposedIntervalIterator(Index index)
           
 IntervalIterator intervalIterator(Index index)
          Returns the interval iterator of this document iterator for the given index.
 Reference2ReferenceMap<Index,IntervalIterator> intervalIterators()
          Returns an unmodifiable map from indices to interval iterators.
 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.AbstractCompositeDocumentIterator
accept, dispose, indices, intervalIterator, toString
 
Methods inherited from class it.unimi.dsi.mg4j.search.AbstractDocumentIterator
document, hasNext, iterator, nextInt, weight, weight
 
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, weight, weight
 
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntIterator
skip
 
Methods inherited from interface java.util.Iterator
hasNext, next, remove
 

Field Detail

queue

protected final IntHeapSemiIndirectPriorityQueue queue
A heap-based semi-indirect priority queue used to keep track of the currently scanned integers.


front

protected final int[] front
The IndirectPriorityQueue.front(int[]) of queue, if frontSize is not -1.


curr

protected final int[] curr
The reference array used for the queue.


frontSize

protected int frontSize
The number of valid entries in front, or -1 if the front has not been computed for the current document.

Constructor Detail

AbstractUnionDocumentIterator

protected AbstractUnionDocumentIterator(DocumentIterator... documentIterator)
                                 throws IOException
Creates a new document iterator that computes the OR of the given array of iterators.

Parameters:
documentIterator - the iterators to be joined.
Throws:
IOException
Method Detail

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().

Parameters:
n - a document pointer.
Returns:
a document pointer larger than or equal to n if available, Integer.MAX_VALUE otherwise.
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).

Returns:
the next document, or -1 if no more documents are available.
Throws:
IOException

computeFront

protected int computeFront()
Forces computation of the current front, returning the number of indices it contains.

After a call to this method, the first elements of front contain the indices of the component document iterators that are positioned on the current document. If the front has already been computed for the current document, this method has no side effects.

Returns:
the size of the current front (the number of valid entries in front).

intervalIterators

public Reference2ReferenceMap<Index,IntervalIterator> intervalIterators()
                                                                 throws IOException
Description copied from interface: DocumentIterator
Returns an unmodifiable map from indices to interval iterators.

After a call to DocumentIterator.nextDocument(), this map can be used to retrieve the intervals in the current document. An invocation of Map.get(java.lang.Object) on this map with argument index yields the same result as intervalIterator(index).

Returns:
a map from indices to interval iterators over the current document.
Throws:
IOException
See Also:
DocumentIterator.intervalIterator(Index)

intervalIterator

public IntervalIterator intervalIterator(Index index)
                                  throws IOException
Description copied from interface: DocumentIterator
Returns the interval iterator of this document iterator for the given index.

After a call to DocumentIterator.nextDocument(), this iterator can be used to retrieve the intervals in the current document (the one returned by DocumentIterator.nextDocument()) for the index index.

Note that if all indices have positions, it is guaranteed that at least one index will return an interval. However, for disjunctive queries it cannot be guaranteed that all indices will return an interval.

Indices without positions always return IntervalIterators.TRUE. Thus, in presence of indices without positions it is possible that no intervals at all are available.

Parameters:
index - an index (must be one over which the query was built).
Returns:
an interval iterator over the current document in index.
Throws:
IOException

getComposedIntervalIterator

protected abstract IntervalIterator getComposedIntervalIterator(Index index)

acceptOnTruePaths

public <T> T acceptOnTruePaths(DocumentIteratorVisitor<T> visitor)
                    throws IOException
Invokes acceptOnTruePaths(DocumentIteratorVisitor) only on component iterators positioned on the current document.

Specified by:
acceptOnTruePaths in interface DocumentIterator
Overrides:
acceptOnTruePaths in class AbstractCompositeDocumentIterator
Parameters:
visitor - a visitor.
Returns:
true if the visit should continue.
Throws:
IOException
See Also:
DocumentIterator.accept(DocumentIteratorVisitor), CounterCollectionVisitor