Package it.unimi.dsi.sux4j.mph.codec
Interface Codec.Coder
- All Known Implementing Classes:
Codec.Binary.Coder
,Codec.Gamma.Coder
,Codec.Huffman.Coder
,Codec.Unary.Coder
,Codec.ZeroCodec.Coder
- Enclosing interface:
- Codec
public static interface Codec.Coder
A coder: provides methods to turn symbols into codewords.
-
Method Summary
Modifier and TypeMethodDescriptionint
codewordLength
(long symbol) Returns the length of the codeword associated with the given symbol.long
encode
(long symbol) Returns the codeword associated with a symbol, or −1 if the provided symbol should be escaped.default long
escape()
Returns the escape codeword, if it exists.default int
Returns the length in bit of an escaped symbol, or zero if there are no escaped symbols.Return a decoder associated with this coder.int
Returns the maximum length of a codeword (including escaped symbols).
-
Method Details
-
encode
long encode(long symbol) Returns the codeword associated with a symbol, or −1 if the provided symbol should be escaped.If a symbol needs to be escaped, it must be encoded using the escape codeword followed by the symbol written in a field of
escapedSymbolLength()
bits.- Parameters:
symbol
- a symbol.- Returns:
- the associated codeword.
-
codewordLength
int codewordLength(long symbol) Returns the length of the codeword associated with the given symbol.For escaped symbols, the returned values is the length of the escape codeword plus
escapedSymbolLength()
.- Parameters:
symbol
- a symbol provided at construction time.- Returns:
- the length of the codeword associated with the given symbol.
-
maxCodewordLength
int maxCodewordLength()Returns the maximum length of a codeword (including escaped symbols).- Returns:
- the maximum length of a codeword (including escaped symbols).
-
escapedSymbolLength
default int escapedSymbolLength()Returns the length in bit of an escaped symbol, or zero if there are no escaped symbols.- Returns:
- the length in bit of an escaped symbol, or zero if there are no escaped symbols.
-
escape
default long escape()Returns the escape codeword, if it exists.Note that the length of the escape codeword can be recovered by subtracting from the length of the codeword of an escaped symbol the length of an escaped symbol.
- Returns:
- the escape codeword, if it exists.
-
getDecoder
Codec.Decoder getDecoder()Return a decoder associated with this coder.- Returns:
- a decoder associated with this coder.
-