Пример #1
0
        private static HuffmanCoder CreateFromText(string text)
        {
            var leafNodes = text.ToCharArray()
                            .GroupBy(c => c)
                            .Select(g => new TreeNode(g.Key, ((double)g.Count()) / text.Length));

            return(HuffmanCoder.Create(leafNodes));
        }
Пример #2
0
        private static HuffmanCoder CreateFromSignature(string signature)
        {
            var leafNodes = signature.Split("|^").Select(s =>
            {
                var ss        = s.Split(",^");
                var c         = Utilities.StrToChar(ss[0]);
                var probValue = double.Parse(ss[1]);

                return(new TreeNode(c, probValue));
            });

            return(HuffmanCoder.Create(leafNodes));
        }