コード例 #1
0
        private Dictionary <DefaultableSymbol <byte>, Dictionary <byte, int> > createSymbolDictionary()
        {
            var perSymbolDictionary = new Dictionary <DefaultableSymbol <byte>, Dictionary <byte, int> >();
            DefaultableSymbol <byte> previousSymbol;

            perSymbolDictionary.Add(new DefaultableSymbol <byte>(true), new Dictionary <byte, int>()
            {
                { inputReader.Current, 1 }
            });
            previousSymbol = new DefaultableSymbol <byte>(inputReader.Current);
            while (inputReader.MoveNext())
            {
                if (!perSymbolDictionary.ContainsKey(previousSymbol))
                {
                    perSymbolDictionary.Add(previousSymbol, new Dictionary <byte, int>());
                }
                if (perSymbolDictionary[previousSymbol].ContainsKey(inputReader.Current))
                {
                    ++perSymbolDictionary[previousSymbol][inputReader.Current];
                }
                else
                {
                    perSymbolDictionary[previousSymbol].Add(inputReader.Current, 1);
                }
                previousSymbol = new DefaultableSymbol <byte>(inputReader.Current);
            }
            ;
            inputReader.Reset();
            this.symbolDictionary = perSymbolDictionary;
            return(perSymbolDictionary);
        }
コード例 #2
0
        public void Encode()
        {
            DefaultableSymbol <byte> previousSymbol;
            Dictionary <DefaultableSymbol <byte>, ICoder <byte> > coderDictionary = createCoderDictionary();

            coderDictionary[new DefaultableSymbol <byte>(true)].Encode(new MarkowHuffmanCoderInput(inputReader.Current), new HuffmanCoderOutput(coderOutputWriter));
            previousSymbol = new DefaultableSymbol <byte>(inputReader.Current);
            while (inputReader.MoveNext())
            {
                coderDictionary[previousSymbol].Encode(new MarkowHuffmanCoderInput(inputReader.Current), new HuffmanCoderOutput(coderOutputWriter));
                previousSymbol = new DefaultableSymbol <byte>(inputReader.Current);
            }
            coderOutputWriter.CreateFileBytes(HuffmanEncodeModel.Markov, true, SymbolQuantityMapConverter.MarkowIntToExtConvert(this.symbolDictionary, CreateEncodingDictionaries(coderDictionary)));
        }
コード例 #3
0
        public void Decode()
        {
            DefaultableSymbol <byte> previousSymbol;
            Dictionary <DefaultableSymbol <byte>, IDecoder <byte> > decoderDictionary = createDecoderDictionary();
            MarkowHuffmanDecoderOutput markowHuffmanDecoderOutput = new MarkowHuffmanDecoderOutput(decoderFileWriter);

            decoderDictionary[new DefaultableSymbol <byte>(true)].Decode(new HuffmanDecoderInput(decoderReader), markowHuffmanDecoderOutput);
            previousSymbol = new DefaultableSymbol <byte>(markowHuffmanDecoderOutput.DecodedSymbol);
            int symbolsDecoded = 1;

            while (symbolsDecoded < symbolsCount)
            {
                markowHuffmanDecoderOutput = new MarkowHuffmanDecoderOutput(decoderFileWriter);
                decoderDictionary[previousSymbol].Decode(new HuffmanDecoderInput(decoderReader), markowHuffmanDecoderOutput);
                previousSymbol = new DefaultableSymbol <byte>(markowHuffmanDecoderOutput.DecodedSymbol);
                ++symbolsDecoded;
            }
        }