Home / Function/ optimiseSelectorsAndHuffmanTables() — netty Function Reference

optimiseSelectorsAndHuffmanTables() — netty Function Reference

Architecture documentation for the optimiseSelectorsAndHuffmanTables() function in Bzip2HuffmanStageEncoder.java from the netty codebase.

Function java Buffer Allocators calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  6c8d4db0_a5fa_6428_35e7_adc043759e22["optimiseSelectorsAndHuffmanTables()"]
  9201fec0_464b_c827_7f9e_b36517971a73["Bzip2HuffmanStageEncoder"]
  6c8d4db0_a5fa_6428_35e7_adc043759e22 -->|defined in| 9201fec0_464b_c827_7f9e_b36517971a73
  6e4766a4_37c9_7b63_401b_81d6c95ccc03["encode()"]
  6e4766a4_37c9_7b63_401b_81d6c95ccc03 -->|calls| 6c8d4db0_a5fa_6428_35e7_adc043759e22
  f573bb0a_c805_07db_0e53_25b4b166f047["generateHuffmanCodeLengths()"]
  6c8d4db0_a5fa_6428_35e7_adc043759e22 -->|calls| f573bb0a_c805_07db_0e53_25b4b166f047
  style 6c8d4db0_a5fa_6428_35e7_adc043759e22 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java lines 205–259

    private void optimiseSelectorsAndHuffmanTables(final boolean storeSelectors) {
        final char[] mtfBlock = this.mtfBlock;
        final byte[] selectors = this.selectors;
        final int[][] huffmanCodeLengths = this.huffmanCodeLengths;
        final int mtfLength = this.mtfLength;
        final int mtfAlphabetSize = this.mtfAlphabetSize;

        final int totalTables = huffmanCodeLengths.length;
        final int[][] tableFrequencies = new int[totalTables][mtfAlphabetSize];

        int selectorIndex = 0;

        // Find the best table for each group of 50 block bytes based on the current Huffman code lengths
        for (int groupStart = 0; groupStart < mtfLength;) {

            final int groupEnd = Math.min(groupStart + HUFFMAN_GROUP_RUN_LENGTH, mtfLength) - 1;

            // Calculate the cost of this group when encoded by each table
            int[] cost = new int[totalTables];
            for (int i = groupStart; i <= groupEnd; i++) {
                final int value = mtfBlock[i];
                for (int j = 0; j < totalTables; j++) {
                    cost[j] += huffmanCodeLengths[j][value];
                }
            }

            // Find the table with the least cost for this group
            byte bestTable = 0;
            int bestCost = cost[0];
            for (byte i = 1 ; i < totalTables; i++) {
                final int tableCost = cost[i];
                if (tableCost < bestCost) {
                    bestCost = tableCost;
                    bestTable = i;
                }
            }

            // Accumulate symbol frequencies for the table chosen for this block
            final int[] bestGroupFrequencies = tableFrequencies[bestTable];
            for (int i = groupStart; i <= groupEnd; i++) {
                bestGroupFrequencies[mtfBlock[i]]++;
            }

            // Store a selector indicating the table chosen for this block
            if (storeSelectors) {
                selectors[selectorIndex++] = bestTable;
            }
            groupStart = groupEnd + 1;
        }

        // Generate new Huffman code lengths based on the frequencies for each table accumulated in this iteration
        for (int i = 0; i < totalTables; i++) {
            generateHuffmanCodeLengths(mtfAlphabetSize, tableFrequencies[i], huffmanCodeLengths[i]);
        }
    }

Domain

Subdomains

Called By

Frequently Asked Questions

What does optimiseSelectorsAndHuffmanTables() do?
optimiseSelectorsAndHuffmanTables() is a function in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java.
Where is optimiseSelectorsAndHuffmanTables() defined?
optimiseSelectorsAndHuffmanTables() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java at line 205.
What does optimiseSelectorsAndHuffmanTables() call?
optimiseSelectorsAndHuffmanTables() calls 1 function(s): generateHuffmanCodeLengths.
What calls optimiseSelectorsAndHuffmanTables()?
optimiseSelectorsAndHuffmanTables() is called by 1 function(s): encode.

Analyze Your Own Codebase

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

Try Supermodel Free