Beispiel #1
0
        private static string DecodeWithHuffman(string dictFilename, byte[] bytes)
        {
            var serializedDict = File.ReadAllText(dictFilename);
            var rates          = serializedDict.Split('操').Select(x =>
            {
                var chr  = x[0];
                var rate = int.Parse(x.Substring(1, x.Length - 1));
                return(new { chr, rate });
            }).ToDictionary(x => x.chr, x => x.rate);
            var huffmanTree = new HuffmanDecoder();

            huffmanTree.BuildWithRates(rates);
            return(huffmanTree.Decode(new BitArray(bytes)));
        }