Class HuffmanCanoncialCodeGenerator<T>

  • Type Parameters:
    T - type of the symbols in the alphabet being huffman-encoded

    public final class HuffmanCanoncialCodeGenerator<T>
    extends Object
    Given a set of HuffmanParams, creates the set of canonical codes that are be used to read/write symbols from/to an output/input stream.
    • Constructor Detail

      • HuffmanCanoncialCodeGenerator

        public HuffmanCanoncialCodeGenerator​(HuffmanParams<T> huffmanParams)
        Parameters:
        huffmanParams - HuffmanParams to use for this helper
    • Method Detail

      • getCanonicalCodeWords

        public List<HuffmanBitCode<T>> getCanonicalCodeWords()
        Return the canonical code words for this helper's HuffmanParams as a list of HuffmanBitCodes.
        Returns:
        list of HuffmanBitCode for this helper's HuffmanParams
      • write

        public final long write​(BitOutputStream bitOutputStream,
                                T symbol)
        Parameters:
        bitOutputStream - stream to which the symbol should be written
        symbol - symbol from the alphabet to be written to the stream
        Returns:
        the length of the codeword that was written
      • read

        public final T read​(BitInputStream bitInputStream)
        Read a single huffman-encoded symbol from a stream
        Parameters:
        bitInputStream - stream from which a symbol should read
        Returns:
        symbol read from the stream
      • getCodeWordLenForValue

        public int getCodeWordLenForValue​(T value)