public static BitArray Encode(string source, Node node) { List <bool> encodedSource = new List <bool>(); for (int i = 0; i < source.Length; i++) { List <bool> encodedSymbol = node.Traverse(source[i], new List <bool>()); encodedSource.AddRange(encodedSymbol); } BitArray bits = new BitArray(encodedSource.ToArray()); return(bits); }
public static void SaveDictionnary(string source, Node node) { string file = ""; for (int i = 0; i < source.Length; i++) { List <bool> encodedSymbol = node.Traverse(source[i], new List <bool>()); file += source[i] + ": "; foreach (bool bit in new BitArray(encodedSymbol.ToArray())) { file += Convert.ToInt32(bit); } file += "\n"; } file.Replace("\n", Environment.NewLine); using (StreamWriter sw = File.CreateText("dico.txt")) sw.WriteLine(file); }