private void ButtonEncodeClick(object sender, EventArgs e) { var filePath = TestFiles.TestFile3; var fileString = ReadFile(filePath); textBoxSource.Text = fileString; var encodedText = fileString; while (true) { var frecuencyTable = CreateFrequencyTable(encodedText); frequencies.Add(frecuencyTable); var coder = new Coder(); encodedText = Encode(coder, encodedText, frecuencyTable); coders.Add(coder); var newText = CompressText(encodedText); var newFrequencyTable = CreateFrequencyTable(newText); var newCoder = new Coder(); var newEncodedText = Encode(newCoder, newText, newFrequencyTable); if (!IsTextCompressed(newEncodedText, encodedText)) { if (compressors.Count > 1) { compressors.RemoveAt(compressors.Count - 1); } break; } i++; encodedText = newText; } textBoxEncoded.Text = encodedText; ShowFrequencyTable(frequencies[0]); }
private String Encode(Coder coder, String text, FrequencyTable table) { return(coder.Encode(text, table)); }