public class HuffmanTree
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Class and Description |
---|---|
class |
HuffmanTree.HCode |
Constructor and Description |
---|
HuffmanTree(char[] a,
int[] f) |
HuffmanTree(java.lang.String textFileName)
Constructor
Read the text file, analyze it and build a Huffman tree with respect to the text in
file with name textFileName.
|
Modifier and Type | Method and Description |
---|---|
void |
AnalyzeAndReset(java.lang.String text)
Analyze text and build a Huffman tree
|
java.lang.String |
decode(HuffmanTree.HCode code) |
java.lang.String |
decode(java.lang.String codeString)
The input is binary string in ASCII symbols, '1' and '0'.
|
java.lang.String |
decodeFile(java.lang.String fileName) |
java.lang.String |
encode(java.lang.String text)
This method encodes the text string using the Huffman codes in root.
|
HuffmanTree.HCode |
encodeFile(java.lang.String textFileName)
Encode the text file using the Huffman tree in root.
|
HuffmanTree.HCode |
encodeFile(java.lang.String textFileName,
java.lang.String codeFileName)
This method encodes the text file using the Huffman codes in root.
|
java.lang.String |
findCode(char a) |
void |
printCodeWords() |
public HuffmanTree(java.lang.String textFileName)
textFileName
- is the input filepublic HuffmanTree(char[] a, int[] f)
a
- array of alphabetsf
- array of frequenciespublic void AnalyzeAndReset(java.lang.String text)
text
- us the text to be analyzedpublic HuffmanTree.HCode encodeFile(java.lang.String textFileName)
textFileName
- This is plain text file to be analyzed and encoded.public HuffmanTree.HCode encodeFile(java.lang.String textFileName, java.lang.String codeFileName)
textFileName
- This is plain text file to be encoded.codeFileName
- This is the file that stores the serialized HCode object (i.e., encoded text).public java.lang.String encode(java.lang.String text)
text
- is to be encodedpublic java.lang.String decodeFile(java.lang.String fileName)
fileName
- should contain HTreeNode followed bt HCodepublic java.lang.String decode(HuffmanTree.HCode code)
code
- is HCodepublic java.lang.String decode(java.lang.String codeString)
codeString
- a bit stream of the code wordspublic java.lang.String findCode(char a)
public void printCodeWords()