Package it.unimi.dsi.sux4j.mph.codec
Class Codec.Huffman.Coder
- java.lang.Object
-
- it.unimi.dsi.sux4j.mph.codec.Codec.Huffman.Coder
-
- All Implemented Interfaces:
Codec.Coder
- Enclosing class:
- Codec.Huffman
public static final class Codec.Huffman.Coder extends java.lang.Object implements Codec.Coder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCodec.Huffman.Coder.Decoder
-
Constructor Summary
Constructors Constructor Description Coder(long[] codeWord, int[] codewordLength, long[] symbol, it.unimi.dsi.fastutil.longs.Long2IntMap symbol2Rank, int escapedSymbolLength)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcodewordLength(long symbol)Returns the length of the codeword associated with the given symbol.longencode(long symbol)Returns the codeword associated with a symbol, or −1 if the provided symbol should be escaped.longescape()Returns the escape codeword, if it exists.intescapedSymbolLength()Returns the length in bit of an escaped symbol, or zero if there are no escaped symbols.Codec.Huffman.Coder.DecodergetDecoder()Return a decoder associated with this coder.intmaxCodewordLength()Returns the maximum length of a codeword (including escaped symbols).
-
-
-
Method Detail
-
encode
public long encode(long symbol)
Description copied from interface:Codec.CoderReturns 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
Codec.Coder.escapedSymbolLength()bits.- Specified by:
encodein interfaceCodec.Coder- Parameters:
symbol- a symbol.- Returns:
- the associated codeword.
-
codewordLength
public int codewordLength(long symbol)
Description copied from interface:Codec.CoderReturns the length of the codeword associated with the given symbol.For escaped symbols, the returned values is the length of the escape codeword plus
Codec.Coder.escapedSymbolLength().- Specified by:
codewordLengthin interfaceCodec.Coder- Parameters:
symbol- a symbol provided at construction time.- Returns:
- the length of the codeword associated with the given symbol.
-
maxCodewordLength
public int maxCodewordLength()
Description copied from interface:Codec.CoderReturns the maximum length of a codeword (including escaped symbols).- Specified by:
maxCodewordLengthin interfaceCodec.Coder- Returns:
- the maximum length of a codeword (including escaped symbols).
-
escape
public long escape()
Description copied from interface:Codec.CoderReturns 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.
- Specified by:
escapein interfaceCodec.Coder- Returns:
- the escape codeword, if it exists.
-
escapedSymbolLength
public int escapedSymbolLength()
Description copied from interface:Codec.CoderReturns the length in bit of an escaped symbol, or zero if there are no escaped symbols.- Specified by:
escapedSymbolLengthin interfaceCodec.Coder- Returns:
- the length in bit of an escaped symbol, or zero if there are no escaped symbols.
-
getDecoder
public Codec.Huffman.Coder.Decoder getDecoder()
Description copied from interface:Codec.CoderReturn a decoder associated with this coder.- Specified by:
getDecoderin interfaceCodec.Coder- Returns:
- a decoder associated with this coder.
-
-