예제 #1
0
        private void tsmiДеревоХаффмана_Click(object sender, EventArgs e)
        {
            var tree = new HaffmanTree <char>(new Alphabet(rtbIncoming.Text).ToKeyValuePairs());

            new HaffmanForm(tree).Show();
            Updated = UpdateUIHaffman;
            Updated();
        }
예제 #2
0
 public HaffmanForm(HaffmanTree <char> tree)
 {
     InitializeComponent();
     if (tree.Root != null)
     {
         TreeBypass(tree.Root, tvHaffmanTree.Nodes.Add(""));
     }
     tvHaffmanTree.ExpandAll();
 }
예제 #3
0
 private static void TreeBypass(HaffmanTree <char> .HaffmanTreeNode <char> root, TreeNode node)
 {
     while (true)
     {
         if (root.Left == null)
         {
             node.Text = $"\"{root.Value}\" ({root.Weight}) - {node.FullPath}";
             return;
         }
         TreeBypass(root.Left, node.Nodes.Add("0"));
         root = root.Right;
         node = node.Nodes.Add("1");
     }
 }
예제 #4
0
        private void UpdateUIHaffman()
        {
            var alphabet = new Alphabet(rtbIncoming.Text);
            var result   = "";
            var tree     = new HaffmanTree <char>(alphabet.ToKeyValuePairs());
            var count    = 0;

            alphabet.SortByFrequency(reverse: true);

            foreach (var ch in alphabet.Chars)
            {
                var charCode = tree.GetCharCode(ch);
                count  += charCode.Length * alphabet.GetFrequency(ch);
                result += $"{ch}\t{alphabet.GetFrequency(ch)}\t{alphabet.GetRelativeFrequency(ch):0.000000}\t\t{charCode}\r\n";
            }

            tbAlphabet.Text      = result;
            lCharCount.Text      = alphabet.CharCount.ToString();
            lBitCount.Text       = alphabet.GetBitCount(_encoding).ToString();
            lBitPerChar.Text     = alphabet.GetBitPerChar(_encoding).ToString("0.###");
            lEntropy.Text        = alphabet.Entropy.ToString("0.###");
            lZippedCount.Text    = $"Количество бит сжатого текста: {count}";
            lEntropy.BorderSides = ToolStripStatusLabelBorderSides.Right;
        }