Esempio n. 1
0
        static void SomeExample2()
        {
            var radix4Symbols = new Pair <int, Rational>[]
            {
                new Pair <int, Rational>(1, new Rational(22, 100)),
                new Pair <int, Rational>(2, new Rational(20, 100)),
                new Pair <int, Rational>(3, new Rational(18, 100)),
                new Pair <int, Rational>(4, new Rational(15, 100)),
                new Pair <int, Rational>(5, new Rational(10, 100)),
                new Pair <int, Rational>(6, new Rational(8, 100)),
                new Pair <int, Rational>(7, new Rational(5, 100)),
                new Pair <int, Rational>(8, new Rational(2, 100)),
                new Pair <int, Rational>(9, new Rational(0, 100)),
                new Pair <int, Rational>(10, new Rational(0, 100))
            };
            var radix4Huffman = Coding.Huffman(radix4Symbols, 4);

            var sourceSymbols = new Pair <int, Rational>[]
            {
                new Pair <int, Rational>(1, new Rational(27, 40)),
                new Pair <int, Rational>(2, new Rational(9, 40)),
                new Pair <int, Rational>(3, new Rational(3, 40)),
                new Pair <int, Rational>(4, new Rational(1, 40))
            };
            var source2 = Coding.Power(sourceSymbols, 2).ToList();
            var source3 = Coding.Power(sourceSymbols, 3).ToList();
            var source4 = Coding.Power(sourceSymbols, 4).ToList();
            var source5 = Coding.Power(sourceSymbols, 5).ToList();
            var source6 = Coding.Power(sourceSymbols, 6).ToList();

            var huffmanCode  = Coding.Huffman(sourceSymbols);
            var huffmanCode2 = Coding.Huffman(source2);
            //var huffmanCode3 = Coding.Huffman(source3);
            //var huffmanCode4 = Coding.Huffman(source4);
            //var huffmanCode5 = Coding.Huffman(source5);
            //var huffmanCode6 = Coding.Huffman(source6);

            var blockSource = new Pair <int, Rational>[]
            {
                new Pair <int, Rational>(1, new Rational(1, 2)),
                new Pair <int, Rational>(2, new Rational(1, 2))
            };

            var blockSource4 = Coding.Power(blockSource, 4);
            var blockHuffman = Coding.Huffman(blockSource4);

            var fibonacciSource = new List <Pair <int, Rational> >();
            int fibonacciCount  = 10;
            var fibonacciDenom  = Discrete.Fibonacci(fibonacciCount + 2) - 1;

            for (int i = 1; i <= fibonacciCount; i++)
            {
                fibonacciSource.Add(new Pair <int, Rational>(i, new Rational(Discrete.Fibonacci(i), fibonacciDenom)));
            }

            var fibonacciHuffman = Coding.Huffman(fibonacciSource);

            var encoding = Coding.ArithmeticEncode(new int[] { 3, 1, 2, 1, 1 }, sourceSymbols, 4);

            var output = Coding.Lz78Encode("foo bar ra fo obar foo foo foo foo bar bar rab rab ra fbar".ToList()).ToList();

            var aSource = new Pair <int, Rational>[]
            {
                new Pair <int, Rational>(1, new Rational(2, 5)),
                new Pair <int, Rational>(2, new Rational(1, 5)),
                new Pair <int, Rational>(3, new Rational(1, 5)),
                new Pair <int, Rational>(4, new Rational(1, 5))
            };

            var aOutput = Coding.ArithmeticEncode(new int[] { 2, 1, 3, 4 }, aSource, 4);
        }