org.apache.lucene.facet.encoding
Class VInt8IntEncoder
java.lang.Object
org.apache.lucene.facet.encoding.IntEncoder
org.apache.lucene.facet.encoding.VInt8IntEncoder
public final class VInt8IntEncoder
- extends IntEncoder
An IntEncoder
which implements variable length encoding. A number is
encoded as follows:
- If it is less than 127 and non-negative, i.e. uses only 7 bits, it is
encoded as a single byte: 0bbbbbbb.
- If it occupies more than 7 bits, it is represented as a series of bytes,
each byte carrying 7 bits. All but the last byte have the MSB set, the last
one has it unset.
Example:
- n = 117 = 01110101: This has less than 8 significant bits, therefore is
encoded as 01110101 = 0x75.
- n = 100000 = (binary) 11000011010100000. This has 17 significant bits,
thus needs three Vint8 bytes. Pad it to a multiple of 7 bits, then split it
into chunks of 7 and add an MSB, 0 for the last byte, 1 for the others:
1|0000110 1|0001101 0|0100000 = 0x86 0x8D 0x20.
NOTE: although this encoder is not limited to values ≥ 0, it is not
recommended for use with negative values, as their encoding will result in 5
bytes written to the output stream, rather than 4. For such values, either
use SimpleIntEncoder
or write your own version of variable length
encoding, which can better handle negative values.
- WARNING: This API is experimental and might change in incompatible ways in the next release.
VInt8IntEncoder
public VInt8IntEncoder()
encode
public void encode(IntsRef values,
BytesRef buf)
- Description copied from class:
IntEncoder
- Encodes the values to the given buffer. Note that the buffer's offset and
length are set to 0.
- Specified by:
encode
in class IntEncoder
createMatchingDecoder
public IntDecoder createMatchingDecoder()
- Description copied from class:
IntEncoder
- Returns an
IntDecoder
which can decode the values that were encoded
with this encoder.
- Specified by:
createMatchingDecoder
in class IntEncoder
toString
public String toString()
- Overrides:
toString
in class Object
Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.