it.unimi.dsi.mg4j.index
Interface IndexIterator

All Superinterfaces:
DocumentIterator, IntIterator, Iterator

public interface IndexIterator
extends DocumentIterator

An iterator over an inverted list.

An index iterator scans the inverted list of an indexed term. Each integer returned by the iterator is the index of a document containing the term. If the index contains counts, they can be obtained after each call to IntIterator.nextInt() using count(). Then, if the index contains occurrences they can be obtained as an itearator using positions(), or stored into an array using positions(int[]).

Note that this interface extends DocumentIterator. The intervals returned for a document are exactly length-one intervals corresponding to the positions returned by positions().


Method Summary
 int count()
          Returns the count, that is, the number of occurrences of the term in the current document.
 int frequency()
          Returns the frequency, that is, the number of documents that will be returned by this iterator.
 int[] positionArray()
          Returns the positions at which the term appears in the current document in an array.
 IntIterator positions()
          Returns the positions at which the term appears in the current document.
 int positions(int[] positions)
          Stores the positions at which the term appears in the current document in a given array.
 
Methods inherited from interface it.unimi.dsi.mg4j.search.DocumentIterator
document, indices, intervalIterator, intervalIterator, intervalIterators, nextDocument, skipTo
 
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntIterator
nextInt, skip
 
Methods inherited from interface java.util.Iterator
hasNext, next, remove
 

Method Detail

frequency

public int frequency()
Returns the frequency, that is, the number of documents that will be returned by this iterator.

Returns:
the number of documents that will be returned by this iterator.

count

public int count()
Returns the count, that is, the number of occurrences of the term in the current document.

Returns:
the count (number of occurrences) of the term in the current document.
Throws:
UnsupportedOperationException - if this index does not contain counts.

positions

public IntIterator positions()
Returns the positions at which the term appears in the current document. TODO: decide whether to return null or throw an exception.

Returns:
the positions of the term occurrences, or null if the index does not contain occurrences.
Throws:
UnsupportedOperationException - if this index does not contain positions.

positions

public int positions(int[] positions)
Stores the positions at which the term appears in the current document in a given array.

If the array is not large enough (i.e., it does not contain count() elements), this method will return a negative number (the opposite of the count).

Parameters:
positions - an array that will be used to store positions.
Returns:
the count; it will have the sign changed if positions cannot hold all positions.
Throws:
UnsupportedOperationException - if this index does not contain positions.

positionArray

public int[] positionArray()
Returns the positions at which the term appears in the current document in an array.

Implementations are allowed to return the same array across different calls to this method.

Returns:
an array whose first count() elements contain the document positions.
Throws:
UnsupportedOperationException - if this index does not contain positions.