Пример #1
0
        private void btnCompress_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text == string.Empty)
            {
                MessageBox.Show("Please enter Content");
                return;
            }

            _huffmannEncodedMap.Clear();
            var uniqueMap = _contentHandler.GetUniqueCharacterToFrequencyMapSortedByFreqInDescOrder(textBox1.Text);

            var result = _graphCreator.CreateGraph(uniqueMap);

            if (result)
            {
                var graph = _graphCreator.GetCreatedGraph();

                IGraphTraversal graphTraversal = new GraphTraversal();
                var             dictionary     = graphTraversal.GetHuffmannEncodingForCharacters(graph);

                foreach (var item in dictionary)
                {
                    _huffmannEncodedMap.Add(new DisplayData {
                        Key = item.Key.ToString(), Value = item.Value
                    });
                }
                listViewEncoding.DataContext = _huffmannEncodedMap;


                //get encoded bit data
                string message  = string.Empty;
                var    charList = textBox1.Text.ToCharArray().ToList();
                foreach (var item in charList)
                {
                    message += dictionary[item];
                }



                txbHuffmannCode.DataContext = new DisplayData {
                    Key = message
                };
            }
        }