Class Huffman


  • final class Huffman
    extends java.lang.Object
    Utilities for building Huffman decoding tables.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int MAX_LENGTH  
    • Constructor Summary

      Constructors 
      Constructor Description
      Huffman()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static int buildHuffmanTable​(int[] tableGroup, int tableIdx, int rootBits, int[] codeLengths, int codeLengthsSize)
      Builds Huffman lookup table assuming code lengths are in symbol order.
      private static int getNextKey​(int key, int len)
      Returns reverse(reverse(key, len) + 1, len).
      private static int nextTableBitSize​(int[] count, int len, int rootBits)  
      private static void replicateValue​(int[] table, int offset, int step, int end, int item)
      Stores item in table[0], table[step], table[2 * step] .., table[end].
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Huffman

        Huffman()
    • Method Detail

      • getNextKey

        private static int getNextKey​(int key,
                                      int len)
        Returns reverse(reverse(key, len) + 1, len).

        reverse(key, len) is the bit-wise reversal of the len least significant bits of key.

      • replicateValue

        private static void replicateValue​(int[] table,
                                           int offset,
                                           int step,
                                           int end,
                                           int item)
        Stores item in table[0], table[step], table[2 * step] .., table[end].

        Assumes that end is an integer multiple of step.

      • nextTableBitSize

        private static int nextTableBitSize​(int[] count,
                                            int len,
                                            int rootBits)
        Parameters:
        count - histogram of bit lengths for the remaining symbols,
        len - code length of the next processed symbol.
        Returns:
        table width of the next 2nd level table.
      • buildHuffmanTable

        static int buildHuffmanTable​(int[] tableGroup,
                                     int tableIdx,
                                     int rootBits,
                                     int[] codeLengths,
                                     int codeLengthsSize)
        Builds Huffman lookup table assuming code lengths are in symbol order.
        Returns:
        number of slots used by resulting Huffman table