/// <summary> /// Ersetzt den Huffmanncode durch die ASCII zeichen /// </summary> /// <param name="huffmann"></param> /// <returns></returns> public string Huffmann_Ascii(string huffmann) { var keynotFound = false; var valueString = ""; string buchstabe = ""; for (int i = 0; i < huffmann.Length; i++) { if (keynotFound) { buchstabe += huffmann.Substring(i, 1); } else { buchstabe = huffmann.Substring(i, 1); } if (HuffmannToAscii.ContainsKey(buchstabe)) { valueString += HuffmannToAscii[buchstabe]; keynotFound = false; } else { keynotFound = true; } } return(valueString); }
/// <summary> /// Liest die Codetabelle aus dem übergebenen Dateinamen aus und Speichert die Werte in den Dictionaries /// </summary> /// <param name="filename"></param> public void ReadCodeTable(string filename) { HuffmannToAscii.Clear(); AsciiToHuffmann.Clear(); var file = new System.IO.StreamReader(filename); while (!file.EndOfStream) { var line = file.ReadLine(); var parts = line.Split(';'); if (parts.Length == 2) { HuffmannToAscii.Add(parts[1], parts[0]); AsciiToHuffmann.Add(parts[0], parts[1]); } } }