Home / Class/ Bzip2HuffmanStageEncoder Class — netty Architecture

Bzip2HuffmanStageEncoder Class — netty Architecture

Architecture documentation for the Bzip2HuffmanStageEncoder class in Bzip2HuffmanStageEncoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  9201fec0_464b_c827_7f9e_b36517971a73["Bzip2HuffmanStageEncoder"]
  ecc5890f_cbbb_3f5f_cb85_97dbd89966fd["Bzip2HuffmanStageEncoder.java"]
  9201fec0_464b_c827_7f9e_b36517971a73 -->|defined in| ecc5890f_cbbb_3f5f_cb85_97dbd89966fd
  38b2e3e0_610c_585c_25e2_1e0ea14134ad["Bzip2HuffmanStageEncoder()"]
  9201fec0_464b_c827_7f9e_b36517971a73 -->|method| 38b2e3e0_610c_585c_25e2_1e0ea14134ad
  867d4b39_213f_2fc7_9331_c8ff1f9815ea["selectTableCount()"]
  9201fec0_464b_c827_7f9e_b36517971a73 -->|method| 867d4b39_213f_2fc7_9331_c8ff1f9815ea
  f573bb0a_c805_07db_0e53_25b4b166f047["generateHuffmanCodeLengths()"]
  9201fec0_464b_c827_7f9e_b36517971a73 -->|method| f573bb0a_c805_07db_0e53_25b4b166f047
  2f7e4bf0_cbf0_8d52_74b2_e1e1992afc34["generateHuffmanOptimisationSeeds()"]
  9201fec0_464b_c827_7f9e_b36517971a73 -->|method| 2f7e4bf0_cbf0_8d52_74b2_e1e1992afc34
  6c8d4db0_a5fa_6428_35e7_adc043759e22["optimiseSelectorsAndHuffmanTables()"]
  9201fec0_464b_c827_7f9e_b36517971a73 -->|method| 6c8d4db0_a5fa_6428_35e7_adc043759e22
  03423df0_a173_2190_80e3_bf0104461e2b["assignHuffmanCodeSymbols()"]
  9201fec0_464b_c827_7f9e_b36517971a73 -->|method| 03423df0_a173_2190_80e3_bf0104461e2b
  1624131c_7091_382d_fded_6daf075febdb["writeSelectorsAndHuffmanTables()"]
  9201fec0_464b_c827_7f9e_b36517971a73 -->|method| 1624131c_7091_382d_fded_6daf075febdb
  8f0c4b68_6a3a_9507_84d8_686601b8a5e9["writeBlockData()"]
  9201fec0_464b_c827_7f9e_b36517971a73 -->|method| 8f0c4b68_6a3a_9507_84d8_686601b8a5e9
  6e4766a4_37c9_7b63_401b_81d6c95ccc03["encode()"]
  9201fec0_464b_c827_7f9e_b36517971a73 -->|method| 6e4766a4_37c9_7b63_401b_81d6c95ccc03

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java lines 28–374

final class Bzip2HuffmanStageEncoder {
    /**
     * Used in initial Huffman table generation.
     */
    private static final int HUFFMAN_HIGH_SYMBOL_COST = 15;

    /**
     * The {@link Bzip2BitWriter} to which the Huffman tables and data is written.
     */
    private final Bzip2BitWriter writer;

    /**
     * The output of the Move To Front Transform and Run Length Encoding[2] stages.
     */
    private final char[] mtfBlock;

    /**
     * The actual number of values contained in the {@link #mtfBlock} array.
     */
    private final int mtfLength;

    /**
     * The number of unique values in the {@link #mtfBlock} array.
     */
    private final int mtfAlphabetSize;

    /**
     * The global frequencies of values within the {@link #mtfBlock} array.
     */
    private final int[] mtfSymbolFrequencies;

    /**
     * The Canonical Huffman code lengths for each table.
     */
    private final int[][] huffmanCodeLengths;

    /**
     * Merged code symbols for each table. The value at each position is ((code length << 24) | code).
     */
    private final int[][] huffmanMergedCodeSymbols;

    /**
     * The selectors for each segment.
     */
    private final byte[] selectors;

    /**
     * @param writer The {@link Bzip2BitWriter} which provides bit-level writes
     * @param mtfBlock The MTF block data
     * @param mtfLength The actual length of the MTF block
     * @param mtfAlphabetSize The size of the MTF block's alphabet
     * @param mtfSymbolFrequencies The frequencies the MTF block's symbols
     */
    Bzip2HuffmanStageEncoder(final Bzip2BitWriter writer, final char[] mtfBlock,
                             final int mtfLength, final int mtfAlphabetSize, final int[] mtfSymbolFrequencies) {
        this.writer = writer;
        this.mtfBlock = mtfBlock;
        this.mtfLength = mtfLength;
        this.mtfAlphabetSize = mtfAlphabetSize;
        this.mtfSymbolFrequencies = mtfSymbolFrequencies;

        final int totalTables = selectTableCount(mtfLength);

        huffmanCodeLengths = new int[totalTables][mtfAlphabetSize];
        huffmanMergedCodeSymbols = new int[totalTables][mtfAlphabetSize];
        selectors = new byte[(mtfLength + HUFFMAN_GROUP_RUN_LENGTH - 1) / HUFFMAN_GROUP_RUN_LENGTH];
    }

    /**
     * Selects an appropriate table count for a given MTF length.
     * @param mtfLength The length to select a table count for
     * @return The selected table count
     */
    private static int selectTableCount(final int mtfLength) {
        if (mtfLength >= 2400) {
            return 6;
        }
        if (mtfLength >= 1200) {
            return 5;
        }
        if (mtfLength >= 600) {

Frequently Asked Questions

What is the Bzip2HuffmanStageEncoder class?
Bzip2HuffmanStageEncoder is a class in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java.
Where is Bzip2HuffmanStageEncoder defined?
Bzip2HuffmanStageEncoder is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java at line 28.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free