예제 #1
0
        public (string, HuffmanTree) CondenseToTree(string w)
        {
            var tree = HuffmanTree.AssembleTree(CharCountDeterminer.GetAllFromString(w));

            var b         = new BitInputStream();
            var charArray = w.ToCharArray();

            var first = charArray[0];

            b.AddFromStringSource(tree[first]);

            for (var i = 1; i < charArray.Length; i++)
            {
                var current = charArray[i];

                var relPath = tree[current];
                b.AddFromStringSource(relPath);
            }

            var output = new StringBuilder();

            b.Flush();
            output.Append(b.ToChars());

            return(output.ToString(), tree);
        }
예제 #2
0
        public HuffmanChain(string w)
        {
            overall = HuffmanTree.AssembleTree(CharCountDeterminer.GetAllFromString(w));


            trees = new Dictionary <char, HuffmanTree>();
            foreach (var c in GetAllChars(w))
            {
                var afterChar = CharCountDeterminer.GetCountsFromStringForAfterChar(w, c);
                trees.Add(c, HuffmanTree.AssembleTree(afterChar));
            }
        }