Package totalcross.json.zip
Class Huff
- java.lang.Object
-
- totalcross.json.zip.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.
-
-
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 voidgenerate()Generate the encoding/decoding table.booleanpostMortem(PostMortem pm)Compare two Huffman tables.intread(BitReader bitreader)Read bits until a symbol can be identified.voidtick(int value)Increase the weight associated with a value by 1.voidwrite(int value, BitWriter bitwriter)Write the bits corresponding to a symbol.
-
-
-
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
-
-
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:
postMortemin interfacePostMortem- 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 JSONExceptionWrite the bits corresponding to a symbol. The weight of the symbol will be incremented.- Parameters:
value- The number of the symbol to writebitwriter- The destination of the bits.- Throws:
JSONException
-
-