Beispiel #1
0
 public EncodedFile encodeFile()
 {
     char[] charset = getCharset();
     int[] weights = getCharFrequencies(charset);
     HuffmanTree tree = new HuffmanTree(charset, weights);
     string[] codes = tree.getCodes(charset);
     string encoded = encodeToString(charset, codes);
     string huffmanData = tree.getBinaryRepresentation();
     Console.WriteLine(tree.getHuffmanCode(','));                //TEST TEST TEST
     EncodedFile enf = new EncodedFile("E:\\Users\\Alexander Weaver\\My Documents\\encodedTEST.hct", EncodedFile.CREATE_NEW);
     writeEncodedFile(enf, huffmanData, encoded);
     return enf;
 }
Beispiel #2
0
 //Produces a lookup dictionary which maps a given encoded binary symbol, in string format to the symbol's corresponding ASCII character
 private Dictionary<string, char> getCodeDictionary(HuffmanTree tree)
 {
     Dictionary<string, char> table = new Dictionary<string, char>();
     char[] charset = tree.getCharset();
     for (int i = 0; i < charset.Length; ++i) {
         try {
             table.Add(tree.getHuffmanCode(charset[i]), charset[i]);
         } catch {
             continue;   //...
         }
     }
     return table;
 }