generateHuffmanCodeLengths() — netty Function Reference
Architecture documentation for the generateHuffmanCodeLengths() function in Bzip2HuffmanStageEncoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD f573bb0a_c805_07db_0e53_25b4b166f047["generateHuffmanCodeLengths()"] 9201fec0_464b_c827_7f9e_b36517971a73["Bzip2HuffmanStageEncoder"] f573bb0a_c805_07db_0e53_25b4b166f047 -->|defined in| 9201fec0_464b_c827_7f9e_b36517971a73 6c8d4db0_a5fa_6428_35e7_adc043759e22["optimiseSelectorsAndHuffmanTables()"] 6c8d4db0_a5fa_6428_35e7_adc043759e22 -->|calls| f573bb0a_c805_07db_0e53_25b4b166f047 style f573bb0a_c805_07db_0e53_25b4b166f047 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java lines 123–154
private static void generateHuffmanCodeLengths(final int alphabetSize,
final int[] symbolFrequencies, final int[] codeLengths) {
final int[] mergedFrequenciesAndIndices = new int[alphabetSize];
final int[] sortedFrequencies = new int[alphabetSize];
// The Huffman allocator needs its input symbol frequencies to be sorted, but we need to
// return code lengths in the same order as the corresponding frequencies are passed in.
// The symbol frequency and index are merged into a single array of
// integers - frequency in the high 23 bits, index in the low 9 bits.
// 2^23 = 8,388,608 which is higher than the maximum possible frequency for one symbol in a block
// 2^9 = 512 which is higher than the maximum possible alphabet size (== 258)
// Sorting this array simultaneously sorts the frequencies and
// leaves a lookup that can be used to cheaply invert the sort.
for (int i = 0; i < alphabetSize; i++) {
mergedFrequenciesAndIndices[i] = (symbolFrequencies[i] << 9) | i;
}
Arrays.sort(mergedFrequenciesAndIndices);
for (int i = 0; i < alphabetSize; i++) {
sortedFrequencies[i] = mergedFrequenciesAndIndices[i] >>> 9;
}
// Allocate code lengths - the allocation is in place,
// so the code lengths will be in the sortedFrequencies array afterwards
Bzip2HuffmanAllocator.allocateHuffmanCodeLengths(sortedFrequencies, HUFFMAN_ENCODE_MAX_CODE_LENGTH);
// Reverse the sort to place the code lengths in the same order as the symbols whose frequencies were passed in
for (int i = 0; i < alphabetSize; i++) {
codeLengths[mergedFrequenciesAndIndices[i] & 0x1ff] = sortedFrequencies[i];
}
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does generateHuffmanCodeLengths() do?
generateHuffmanCodeLengths() is a function in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java.
Where is generateHuffmanCodeLengths() defined?
generateHuffmanCodeLengths() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java at line 123.
What calls generateHuffmanCodeLengths()?
generateHuffmanCodeLengths() is called by 1 function(s): optimiseSelectorsAndHuffmanTables.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free