it.unimi.dsi.mg4j.index
Class SkipIndexReader

java.lang.Object
  extended byit.unimi.dsi.mg4j.index.IndexReader
      extended byit.unimi.dsi.mg4j.index.SkipIndexReader
All Implemented Interfaces:
CompressionFlags

public class SkipIndexReader
extends IndexReader

Provides facilities to read a skip inverted index from an InputBitStream. Please consult the SkipIndexWriter documentation for more information about the structure of a skip inverted index.

This class is used to read inverted lists with skips. Its functioning is completely analogous to IndexReader.

Note that Index provides a much easier interface to index access. Instead of creating an IndexReader explicitly, you can use Index.getReader().

Since:
0.6
Author:
Paolo Boldi, Sebastiano Vigna

Field Summary
protected static int BEFORE_TOWER
          This value of IndexReader.state means that we are positioned just before a tower.
protected static int FIRST_UNUSED_STATE
          This is the first unused state.
protected  SkipIndex skipIndex
          The reference skip index.
 
Fields inherited from class it.unimi.dsi.mg4j.index.IndexReader
b, BEFORE_COUNT, BEFORE_FREQUENCY, BEFORE_POINTER, BEFORE_POSITIONS, count, currentDocument, frequency, ibs, index, log2b, numberOfDocumentRecord, relativeFrequency, state, term
 
Fields inherited from interface it.unimi.dsi.mg4j.index.CompressionFlags
ARITH, CODING_NAME, COUNTS_DEFAULT, COUNTS_DELTA, COUNTS_GAMMA, COUNTS_SHIFT, DELTA, FREQUENCIES_DEFAULT, FREQUENCIES_DELTA, FREQUENCIES_GAMMA, FREQUENCIES_SHIFT, GAMMA, GOLOMB, INTERP, NIBBLE, NO_COUNTS, NO_POSITIONS, NONE, POINTERS_DEFAULT, POINTERS_DELTA, POINTERS_GAMMA, POINTERS_GOLOMB, POINTERS_SHIFT, POSITIONS_ARITH, POSITIONS_DEFAULT, POSITIONS_DELTA, POSITIONS_GAMMA, POSITIONS_GOLOMB, POSITIONS_INTERP, POSITIONS_SHIFT, POSITIONS_SKEWED_GOLOMB, SKEWED_GOLOMB, UNARY, ZETA
 
Constructor Summary
SkipIndexReader(Index index)
          Creates a new skip index reader, with the specified underlying Index and default buffer size.
SkipIndexReader(Index index, InputBitStream ibs)
          Creates a new skip index reader, with the specified underlying Index and input bit stream.
SkipIndexReader(Index index, int bufferSize)
          Creates a new skip index reader, with the specified underlying Index.
SkipIndexReader(InputBitStream ibs, int N, long flags, int q, int h)
          Deprecated. Please use Index.getReader() or IndexReader.IndexReader(Index).
SkipIndexReader(InputBitStream ibs, LongList offsets, IntList sizes, int N, long flags, int q, int h)
          Deprecated. Please use Index.getReader() or IndexReader.IndexReader(Index).
SkipIndexReader(InputBitStream ibs, LongList offsets, int N, long flags, int q, int h)
          Deprecated. Please use Index.getReader() or IndexReader.IndexReader(Index).
 
Method Summary
protected  boolean justAfterPointer()
          Returns true if we are positioned just after a pointer.
 int readDocumentPointer()
          Reads a document pointer from a given InputBitStream.
 int readFrequency()
          Reads and returns the frequency (number of documents where the term appears).
 int readPositionCount()
          Reads the position count for the current document.
 boolean skipTo(int p)
          Skips to the first document record whose document pointer is greater than or equal to the given value.
 String toString()
           
 
Methods inherited from class it.unimi.dsi.mg4j.index.IndexReader
close, currentDocumentPointer, documents, documents, endOfList, position, readBits, readDocumentPositions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

skipIndex

protected final SkipIndex skipIndex
The reference skip index. This variable shadows (and copies) IndexReader.index to avoid excessive type casting.


BEFORE_TOWER

protected static final int BEFORE_TOWER
This value of IndexReader.state means that we are positioned just before a tower.

See Also:
Constant Field Values

FIRST_UNUSED_STATE

protected static final int FIRST_UNUSED_STATE
This is the first unused state. Subclasses may start from this value to define new states.

See Also:
Constant Field Values
Constructor Detail

SkipIndexReader

public SkipIndexReader(Index index)
                throws IOException
Creates a new skip index reader, with the specified underlying Index and default buffer size.

Parameters:
index - the index.

SkipIndexReader

public SkipIndexReader(Index index,
                       int bufferSize)
                throws IOException
Creates a new skip index reader, with the specified underlying Index.

Parameters:
index - the index.
bufferSize - the size of the buffer of the underlying input bit stream.

SkipIndexReader

public SkipIndexReader(Index index,
                       InputBitStream ibs)
                throws IOException
Creates a new skip index reader, with the specified underlying Index and input bit stream.

Parameters:
index - the index.
ibs - the underlying bit stream.

SkipIndexReader

public SkipIndexReader(InputBitStream ibs,
                       LongList offsets,
                       IntList sizes,
                       int N,
                       long flags,
                       int q,
                       int h)
                throws IOException
Deprecated. Please use Index.getReader() or IndexReader.IndexReader(Index).

Creates a new skip index reader, with the specified underlying InputBitStream.

Parameters:
ibs - the underlying input bit stream.
offsets - the offset list; may be null if you do not plan using IndexReader.position(int).
sizes - the size list; may be null if your code does not require it.
N - the number of documents in the collection.
flags - a bit mask setting the coding techniques to be used (see the IndexReader introduction).
q - the quantum.
h - the maximum height of a skip tower.

SkipIndexReader

public SkipIndexReader(InputBitStream ibs,
                       LongList offsets,
                       int N,
                       long flags,
                       int q,
                       int h)
                throws IOException
Deprecated. Please use Index.getReader() or IndexReader.IndexReader(Index).

Creates a new index reader, with the specified underlying InputBitStream.

Parameters:
ibs - the underlying input bit stream.
offsets - the offset list; may be null if you do not plan using IndexReader.position(int).
N - the number of documents in the collection.
flags - a bit mask setting the coding techniques to be used (see the IndexReader introduction).
q - the quantum.
h - the maximum height of a skip tower.

SkipIndexReader

public SkipIndexReader(InputBitStream ibs,
                       int N,
                       long flags,
                       int q,
                       int h)
                throws IOException
Deprecated. Please use Index.getReader() or IndexReader.IndexReader(Index).

Creates a new index reader, with the specified underlying InputBitStream.

Parameters:
ibs - the underlying input bit stream.
N - the number of documents in the collection.
flags - a bit mask setting the coding techniques to be used (see the IndexReader introduction).
q - the quantum.
h - the maximum height of a skip tower.
Method Detail

readFrequency

public int readFrequency()
                  throws IOException,
                         IllegalStateException
Description copied from class: IndexReader
Reads and returns the frequency (number of documents where the term appears). The underlying bit stream must be positioned on the beginning of an inverted list, or at the real end of an inverted list (not only IndexReader.endOfList() must return true, but also all data contained in the last document record must have been read).

After that, you are ready to read the document records.

Overrides:
readFrequency in class IndexReader
Returns:
the frequency.
Throws:
IOException - if an exception is thrown by the underlying stream
IllegalStateException

readDocumentPointer

public int readDocumentPointer()
                        throws IOException
Description copied from class: IndexReader
Reads a document pointer from a given InputBitStream. This method returns the document pointer; after this, you can use the stream to read the positions.

Overrides:
readDocumentPointer in class IndexReader
Throws:
IOException - if an exception is thrown by the underlying stream

readPositionCount

public int readPositionCount()
                      throws IOException
Description copied from class: IndexReader
Reads the position count for the current document.

Overrides:
readPositionCount in class IndexReader
Returns:
the count, that is, the number of positions of the current term in the current document.
Throws:
IOException - if an exception is thrown by the underlying stream

justAfterPointer

protected boolean justAfterPointer()
Returns true if we are positioned just after a pointer.

Overrides:
justAfterPointer in class IndexReader
Returns:
true if we are positioned just after a pointer.

skipTo

public boolean skipTo(int p)
               throws IOException
Description copied from class: IndexReader
Skips to the first document record whose document pointer is greater than or equal to the given value.

If this method returns true, then there is one record satisfying the condition, and the index is positioned over it. If this method returns false, then the condition is not satisfied and the index is positioned on the last document record.

In any case, this method leaves the index in the same state as after a call to IndexReader.readDocumentPointer(), unless it is called when IndexReader.endOfList() is true, in which case it does nothing and returns false.

Overrides:
skipTo in class IndexReader
Parameters:
p - a document pointer.
Returns:
true if we found a record whose document pointer is greater than or equal to p.
Throws:
IOException

toString

public String toString()