Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private FrequencyTable CreateFrequencyTable(String fileString)
        {
            var table = new FrequencyTable();

            table.CreateFrequencyTable(fileString);

            return(table);
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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());
        }
Esempio n. 5
0
 private String Encode(Coder coder, String text, FrequencyTable table)
 {
     return(coder.Encode(text, table));
 }