Class NOnesIntEncoder
- java.lang.Object
-
- org.apache.lucene.util.encoding.IntEncoder
-
- org.apache.lucene.util.encoding.ChunksIntEncoder
-
- org.apache.lucene.util.encoding.FourFlagsIntEncoder
-
- org.apache.lucene.util.encoding.NOnesIntEncoder
-
public class NOnesIntEncoder extends FourFlagsIntEncoder
A variation ofFourFlagsIntEncoder
which translates the data as follows:- Values ≥ 2 are trnalsated to
value+1
(2 ⇒ 3, 3 ⇒ 4 and so forth). - Any
N
occurrences of 1 are encoded as a single 2. - Otherwise, each 1 is encoded as 1.
Encoding examples:
- N = 4: the data 1,1,1,1,1 is translated to: 2, 1
- N = 3: the data 1,2,3,4,1,1,1,1,5 is translated to 1,3,4,5,2,1,6
Integer.MAX_VALUE
. 0 is not supported because it's not supported byFourFlagsIntEncoder
andInteger.MAX_VALUE
because this encoder translates N to N+1, which will cause an overflow andInteger.MAX_VALUE
will become a negative number, which is not supported as well.
This does not mean you cannot encodeInteger.MAX_VALUE
. If it is not the first value to encode, and you wrap this encoder withDGapIntEncoder
, then the value that will be sent to this encoder will beMAX_VAL - prev
.- WARNING: This API is experimental and might change in incompatible ways in the next release.
- Values ≥ 2 are trnalsated to
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.util.encoding.ChunksIntEncoder
encodeQueue, encodeQueueSize, encoder, indicator, ordinal
-
Fields inherited from class org.apache.lucene.util.encoding.IntEncoder
out
-
-
Constructor Summary
Constructors Constructor Description NOnesIntEncoder(int n)
Constructs an encoder with a given value of N (N: Number of consecutive '1's to be translated into single target value '2').
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Instructs the encoder to finish the encoding process.IntDecoder
createMatchingDecoder()
Returns anIntDecoder
which matches this encoder.void
encode(int value)
Small values (<=3) are stored in theindicator
while larger values are saved for later encoding in theChunksIntEncoder.encodeQueue
.void
reInit(OutputStream out)
Reinitializes the encoder with the giveOutputStream
.String
toString()
-
Methods inherited from class org.apache.lucene.util.encoding.ChunksIntEncoder
encodeChunk
-
-
-
-
Method Detail
-
close
public void close() throws IOException
Description copied from class:IntEncoder
Instructs the encoder to finish the encoding process. This method closes the output stream which was specified byreInit
. An implementation may do here additional cleanup required to complete the encoding, such as flushing internal buffers, etc.
Once this method was called, no further calls toencode
should be made before first callingreInit
.NOTE: overriding classes should make sure they either call
super.close()
or close the output stream themselves.- Overrides:
close
in classChunksIntEncoder
- Throws:
IOException
-
encode
public void encode(int value) throws IOException
Description copied from class:FourFlagsIntEncoder
Small values (<=3) are stored in theindicator
while larger values are saved for later encoding in theChunksIntEncoder.encodeQueue
. Since Vint8 will only encode values larger or equal to 4, the values saves for encoded are transformed to (value - 4).
When a chunk is ready (got 4 values), theChunksIntEncoder.encodeChunk()
takes control.- Overrides:
encode
in classFourFlagsIntEncoder
- Throws:
IOException
-
createMatchingDecoder
public IntDecoder createMatchingDecoder()
Description copied from class:IntEncoder
Returns anIntDecoder
which matches this encoder. Every encoder must return anIntDecoder
andnull
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.
- Overrides:
createMatchingDecoder
in classFourFlagsIntEncoder
-
reInit
public void reInit(OutputStream out)
Description copied from class:IntEncoder
Reinitializes the encoder with the giveOutputStream
. 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 ofIntEncoder
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 classChunksIntEncoder
-
toString
public String toString()
- Overrides:
toString
in classFourFlagsIntEncoder
-
-