org.apache.lucene.util.encoding
Class DGapIntEncoder

java.lang.Object
  extended by org.apache.lucene.util.encoding.IntEncoder
      extended by org.apache.lucene.util.encoding.IntEncoderFilter
          extended by org.apache.lucene.util.encoding.DGapIntEncoder

public class DGapIntEncoder
extends IntEncoderFilter

An IntEncoderFilter which encodes the gap between the given values, rather than the values themselves. This encoder usually yields better encoding performance space-wise (i.e., the final encoded values consume less space) if the values are 'close' to each other.

NOTE: this encoder assumes the values are given to encode(int) in an ascending sorted manner, which ensures only positive values are encoded and thus yields better performance. If you are not sure whether the values are sorted or not, it is possible to chain this encoder with SortingIntEncoder to ensure the values will be sorted before encoding.

WARNING: This API is experimental and might change in incompatible ways in the next release.

Field Summary
 
Fields inherited from class org.apache.lucene.util.encoding.IntEncoderFilter
encoder
 
Fields inherited from class org.apache.lucene.util.encoding.IntEncoder
out
 
Constructor Summary
DGapIntEncoder(IntEncoder encoder)
          Initializes with the given encoder.
 
Method Summary
 IntDecoder createMatchingDecoder()
          Returns an IntDecoder which matches this encoder.
 void encode(int value)
          Encodes an integer to the output stream given in reInit
 void reInit(OutputStream out)
          Reinitializes the encoder with the give OutputStream.
 String toString()
           
 
Methods inherited from class org.apache.lucene.util.encoding.IntEncoderFilter
close
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DGapIntEncoder

public DGapIntEncoder(IntEncoder encoder)
Initializes with the given encoder.

Method Detail

encode

public void encode(int value)
            throws IOException
Description copied from class: IntEncoder
Encodes an integer to the output stream given in reInit

Specified by:
encode in class IntEncoder
Throws:
IOException

createMatchingDecoder

public IntDecoder createMatchingDecoder()
Description copied from class: IntEncoder
Returns an IntDecoder which matches this encoder. Every encoder must return an IntDecoder and null is not a valid value. If an encoder is just a filter, it should at least return its wrapped encoder's matching decoder.

NOTE: this method should create a new instance of the matching decoder and leave the instance sharing to the caller. Returning the same instance over and over is risky because encoders and decoders are not thread safe.

Specified by:
createMatchingDecoder in class IntEncoder

reInit

public void reInit(OutputStream out)
Description copied from class: IntEncoder
Reinitializes the encoder with the give OutputStream. For re-usability it can be changed without the need to reconstruct a new object.

NOTE: after calling IntEncoder.close(), one must call this method even if the output stream itself hasn't changed. An example case is that the output stream wraps a byte[], and the output stream itself is reset, but its instance hasn't changed. Some implementations of IntEncoder may write some metadata about themselves to the output stream, and therefore it is imperative that one calls this method before encoding any data.

Overrides:
reInit in class IntEncoderFilter

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.