示例#1
0
        public void Encode()
        {
            var symbolQuantityDic = createDictionary();
            var builder           = new HuffmanCodecBuilder <Tuple <byte, DefaultableSymbol <byte> > >();
            var tree       = builder.BuildTree(new PairComparer(), symbolQuantityDic);
            var coder      = builder.GetCoder(tree);
            var coderInput = new PairHuffmanCoderInput(inputReader);

            coder.Encode(coderInput, new HuffmanCoderOutput(coderOutputWriter));
            coderOutputWriter.CreateFileBytes(HuffmanEncodeModel.Block, coderInput.isSpecialSymbol, SymbolQuantityMapConverter.PairIntToExtConvert(symbolQuantityDic, coder.GetEncodingDictionary()));
        }
示例#2
0
        private Dictionary <Tuple <byte, DefaultableSymbol <byte> >, int> createDictionary()
        {
            var symbolQuantityDic            = new Dictionary <Tuple <byte, DefaultableSymbol <byte> >, int>();
            PairHuffmanCoderInput coderInput = new PairHuffmanCoderInput(inputReader);

            do
            {
                Tuple <byte, DefaultableSymbol <byte> > symbol = coderInput.Read();
                if (symbolQuantityDic.ContainsKey(symbol))
                {
                    ++symbolQuantityDic[symbol];
                }
                else
                {
                    symbolQuantityDic.Add(symbol, 1);
                }
            } while (!coderInput.IsEnd());

            inputReader.Reset();

            return(symbolQuantityDic);
        }