Class Huff

  • All Implemented Interfaces:
    None, PostMortem

    public class Huff
    extends java.lang.Object
    implements None, PostMortem
    A Huffman encoder/decoder. It operates over a domain of integers, which may map to characters or other symbols. Symbols that are used frequently are given shorter codes than symbols that are used infrequently. This usually produces shorter messages. Initially, all of the symbols are given the same weight. The weight of a symbol is incremented by the tick method. The generate method is used to generate the encoding table. The table must be generated before encoding or decoding. You may regenerate the table with the latest weights at any time. After a million ticks, it is assumed that the distribution is well understood and that no more regeneration will be required.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int education
      The number of characters to process before generation is no longer done.
      • Fields inherited from interface totalcross.json.zip.None

        none
    • Constructor Summary

      Constructors 
      Constructor Description
      Huff​(int domain)
      Construct a Huffman encoder/decoder.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void generate()
      Generate the encoding/decoding table.
      boolean postMortem​(PostMortem pm)
      Compare two Huffman tables.
      int read​(BitReader bitreader)
      Read bits until a symbol can be identified.
      void tick​(int value)
      Increase the weight associated with a value by 1.
      void write​(int value, BitWriter bitwriter)
      Write the bits corresponding to a symbol.
      • Methods inherited from class java.lang.Object

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

      • education

        public static final int education
        The number of characters to process before generation is no longer done.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Huff

        public Huff​(int domain)
        Construct a Huffman encoder/decoder.
        Parameters:
        domain - The number of values known to the object.
    • Method Detail

      • generate

        public void generate()
        Generate the encoding/decoding table. The table determines the bit sequences used by the read and write methods.
      • postMortem

        public boolean postMortem​(PostMortem pm)
        Compare two Huffman tables.
        Specified by:
        postMortem in interface PostMortem
        Parameters:
        pm - Another object of the same type.
        Returns:
        true if they match.
      • read

        public int read​(BitReader bitreader)
                 throws JSONException
        Read bits until a symbol can be identified. The weight of the read symbol will be incremented.
        Parameters:
        bitreader - The source of bits.
        Returns:
        The integer value of the symbol.
        Throws:
        JSONException
      • tick

        public void tick​(int value)
        Increase the weight associated with a value by 1.
        Parameters:
        value - The number of the symbol to tick
      • write

        public void write​(int value,
                          BitWriter bitwriter)
                   throws JSONException
        Write the bits corresponding to a symbol. The weight of the symbol will be incremented.
        Parameters:
        value - The number of the symbol to write
        bitwriter - The destination of the bits.
        Throws:
        JSONException