private IList <String> GenerateCodes(FrequencyTable table) { var codes = new List <String>(); var number = 1; while (true) { for (var i = 0; i < Math.Pow(2, number); i++) { var code = this.GetBinary(i, number); if (IsValid(code)) { codes.Add(code); } if (codes.Count >= table.SybmolsFrequency.Count) { break; } } if (codes.Count >= table.SybmolsFrequency.Count) { break; } number++; } return(codes); }
private FrequencyTable CreateFrequencyTable(String fileString) { var table = new FrequencyTable(); table.CreateFrequencyTable(fileString); return(table); }
private void ShowFrequencyTable(FrequencyTable table) { foreach (var symbol in table.SortedSymbols) { textBoxFrequency.Text += String.Concat("'", symbol, "' - ", table.SybmolsFrequency[symbol]); textBoxFrequency.Text += String.Concat(" - ", coders[0].CodesTable[symbol], Environment.NewLine); } }
public String Encode(String text, FrequencyTable table) { var codes = GenerateCodes(table); var symbolsFrequency = table.SortedSymbols; FillTables(symbolsFrequency, codes); var stringBuiler = new StringBuilder(); foreach (var symbol in text) { stringBuiler.Append(CodesTable[symbol]); stringBuiler.Append(Separator); } stringBuiler.Remove(stringBuiler.Length - Separator.Length, Separator.Length); return(stringBuiler.ToString()); }
private String Encode(Coder coder, String text, FrequencyTable table) { return(coder.Encode(text, table)); }