Example #1
0
        public void Decode()
        {
            var builder      = new HuffmanCodecBuilder <byte>();
            var tree         = builder.BuildTree(Comparer <byte> .Default, symbolQuantityDic);
            var decoder      = builder.GetDecoder(tree);
            var symbolsCount = symbolQuantityDic.Sum(x => x.Value);

            decoder.Decode(new HuffmanDecoderInput(decoderReader), new StandardHuffmanDecoderOutput(decoderFileWriter, symbolsCount));
        }
        public void Decode()
        {
            var builder      = new HuffmanCodecBuilder <Tuple <byte, DefaultableSymbol <byte> > >();
            var tree         = builder.BuildTree(new PairComparer(), symbolQuantityDic);
            var decoder      = builder.GetDecoder(tree);
            int symbolsCount = symbolQuantityDic.Sum(x => x.Value);

            decoder.Decode(new HuffmanDecoderInput(decoderReader), new PairHuffmanDecoderOutput(decoderFileWriter, symbolsCount, isByteCountEven));
        }
        public void Encode()
        {
            Dictionary <byte, int> symbolQuantityDic = createDictionary();
            var           builder      = new HuffmanCodecBuilder <byte>();
            var           tree         = builder.BuildTree(Comparer <byte> .Default, symbolQuantityDic);
            ICoder <byte> huffmanCoder = builder.GetCoder(tree);

            huffmanCoder.Encode(new StandardHuffmanCoderInput(inputReader), new HuffmanCoderOutput(coderOutputWriter));
            coderOutputWriter.CreateFileBytes(HuffmanEncodeModel.Standard, false, SymbolQuantityMapConverter.StandardIntToExtConvert(symbolQuantityDic, huffmanCoder.GetEncodingDictionary()));
        }
Example #4
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()));
        }
        private Dictionary <DefaultableSymbol <byte>, IDecoder <byte> > createDecoderDictionary()
        {
            Dictionary <DefaultableSymbol <byte>, IDecoder <byte> > coderDictionary = new Dictionary <DefaultableSymbol <byte>, IDecoder <byte> >();

            foreach (DefaultableSymbol <byte> key in perSymbolDictionary.Keys)
            {
                var builder = new HuffmanCodecBuilder <byte>();
                var tree    = builder.BuildTree(Comparer <byte> .Default, perSymbolDictionary[key]);
                var decoder = builder.GetDecoder(tree);
                coderDictionary.Add(key, decoder);
            }
            return(coderDictionary);
        }