final class Bzip2HuffmanStageEncoder
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static int |
HUFFMAN_HIGH_SYMBOL_COST
Used in initial Huffman table generation.
|
private int[][] |
huffmanCodeLengths
The Canonical Huffman code lengths for each table.
|
private int[][] |
huffmanMergedCodeSymbols
Merged code symbols for each table.
|
private int |
mtfAlphabetSize
The number of unique values in the
mtfBlock array. |
private char[] |
mtfBlock
The output of the Move To Front Transform and Run Length Encoding[2] stages.
|
private int |
mtfLength
The actual number of values contained in the
mtfBlock array. |
private int[] |
mtfSymbolFrequencies
The global frequencies of values within the
mtfBlock array. |
private byte[] |
selectors
The selectors for each segment.
|
private Bzip2BitWriter |
writer
The
Bzip2BitWriter to which the Huffman tables and data is written. |
Constructor and Description |
---|
Bzip2HuffmanStageEncoder(Bzip2BitWriter writer,
char[] mtfBlock,
int mtfLength,
int mtfAlphabetSize,
int[] mtfSymbolFrequencies) |
Modifier and Type | Method and Description |
---|---|
private void |
assignHuffmanCodeSymbols()
Assigns Canonical Huffman codes based on the calculated lengths.
|
(package private) void |
encode(ByteBuf out)
Encodes and writes the block data.
|
private static void |
generateHuffmanCodeLengths(int alphabetSize,
int[] symbolFrequencies,
int[] codeLengths)
Generate a Huffman code length table for a given list of symbol frequencies.
|
private void |
generateHuffmanOptimisationSeeds()
Generate initial Huffman code length tables, giving each table a different low cost section
of the alphabet that is roughly equal in overall cumulative frequency.
|
private void |
optimiseSelectorsAndHuffmanTables(boolean storeSelectors)
Co-optimise the selector list and the alternative Huffman table code lengths.
|
private static int |
selectTableCount(int mtfLength)
Selects an appropriate table count for a given MTF length.
|
private void |
writeBlockData(ByteBuf out)
Writes out the encoded block data.
|
private void |
writeSelectorsAndHuffmanTables(ByteBuf out)
Write out the selector list and Huffman tables.
|
private static final int HUFFMAN_HIGH_SYMBOL_COST
private final Bzip2BitWriter writer
Bzip2BitWriter
to which the Huffman tables and data is written.private final char[] mtfBlock
private final int mtfLength
mtfBlock
array.private final int mtfAlphabetSize
mtfBlock
array.private final int[] mtfSymbolFrequencies
mtfBlock
array.private final int[][] huffmanCodeLengths
private final int[][] huffmanMergedCodeSymbols
private final byte[] selectors
Bzip2HuffmanStageEncoder(Bzip2BitWriter writer, char[] mtfBlock, int mtfLength, int mtfAlphabetSize, int[] mtfSymbolFrequencies)
writer
- The Bzip2BitWriter
which provides bit-level writesmtfBlock
- The MTF block datamtfLength
- The actual length of the MTF blockmtfAlphabetSize
- The size of the MTF block's alphabetmtfSymbolFrequencies
- The frequencies the MTF block's symbolsprivate static int selectTableCount(int mtfLength)
mtfLength
- The length to select a table count forprivate static void generateHuffmanCodeLengths(int alphabetSize, int[] symbolFrequencies, int[] codeLengths)
alphabetSize
- The total number of symbolssymbolFrequencies
- The frequencies of the symbolscodeLengths
- The array to which the generated code lengths should be writtenprivate void generateHuffmanOptimisationSeeds()
optimiseSelectorsAndHuffmanTables(boolean)
.private void optimiseSelectorsAndHuffmanTables(boolean storeSelectors)
storeSelectors
- If true
, write out the (final) chosen selectorsprivate void assignHuffmanCodeSymbols()
private void writeSelectorsAndHuffmanTables(ByteBuf out)
private void writeBlockData(ByteBuf out)
void encode(ByteBuf out)