Esempio n. 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 GetDecoder_ReturnsOneSymbolDecoder_WhenOneSymbolOnly()
        {
            //given
            var builder  = new HuffmanCodecBuilder <char>();
            var treeRoot = new HuffmanTreeNode <char>(value: 'a', quantity: 1);
            //when
            var decoder = builder.GetDecoder(treeRoot);

            //then
            Assert.IsInstanceOfType(decoder, typeof(OneSymbolDecoder <char>));
        }
        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);
        }
        public void GetCoder_ReturnsHuffmanDecoder_WhenMoreThanOneSymbol()
        {
            //given when
            var builder    = new HuffmanCodecBuilder <char>();
            var treeRoot   = new HuffmanTreeNode <char>(value: 'a', quantity: 1);
            var leftChild  = new HuffmanTreeNode <char>(value: 'b', quantity: 1);
            var rightChild = new HuffmanTreeNode <char>(value: 'c', quantity: 1);

            treeRoot.LeftChild  = leftChild;
            treeRoot.RightChild = rightChild;
            leftChild.Parent    = rightChild.Parent = treeRoot;
            //when
            var decoder = builder.GetDecoder(treeRoot);

            //then
            Assert.IsInstanceOfType(decoder, typeof(HuffmanDecoder <char>));
        }