示例#1
0
        /// <summary>
        /// Reads an encoded value from a <see cref="BitReader"/>.
        /// </summary>
        public int Read(BitReader reader)
        {
            var u   = Codes.UnaryZeros.Read(reader) - 1;
            var len = (int)((reader.Read(u) | (1ul << u)) - 1);

            return((int)(reader.Read(len) | (1ul << len)));
        }
        /// <summary>
        /// Reads an encoded value from a <see cref="BitReader"/>.
        /// </summary>
        public int Read(BitReader reader)
        {
            int value = (int)reader.Read(bits - 1);

            if (value < extra)
            {
                return(value);
            }
            return(value * 2 + (int)reader.Read(1) - extra);
        }
示例#3
0
        /// <summary>
        /// Gets the value corresponding to a code.
        /// </summary>
        public int Read(BitReader reader)
        {
            int value = 1;

            while (reader.Read(1) != 0)
            {
                value = (int)(reader.Read(value) | (1UL << value));
            }

            return(value);
        }
示例#4
0
        /// <summary>
        /// Reads an encoded value from a <see cref="BitReader"/>.
        /// </summary>
        public int Read(BitReader reader)
        {
            int f     = Codes.Fibonacci.Read(reader) - 1;
            int value = (int)reader.Read(f);

            return(value | (1 << f));
        }
示例#5
0
        /// <summary>
        /// Gets the value corresponding to a Fibonacci code.
        /// </summary>
        public int Read(BitReader reader)
        {
            int  value = 0;
            int  f     = 0;
            bool bit   = false;

            while (true)
            {
                if (reader.Read(1) == 0)
                {
                    bit = false;
                }
                else if (bit)
                {
                    break;
                }
                else
                {
                    bit    = true;
                    value += fib[f];
                }

                f++;
            }

            return(value);
        }
示例#6
0
        public void BitStreamTest()
        {
            var g     = new Generator("BitStreamTest");
            var codes = new List <Code>();

            for (int i = 0; i < 10000; i++)
            {
                var bits   = g.UInt64();
                var length = g.Int32(65);
                bits >>= 64 - length;
                var code = new Code(bits, length);
                codes.Add(code);
            }

            var writer = new BitWriter(1000);

            foreach (var code in codes)
            {
                writer.Write(code);
            }

            var buffer = writer.ToArray();
            var reader = new BitReader(buffer);

            foreach (var code in codes)
            {
                ulong bits = reader.Read(code.Length);
                Assert.AreEqual(code.Bits, bits);
            }
        }
示例#7
0
        /// <summary>
        /// Reads an encoded value from a <see cref="BitReader"/>.
        /// </summary>
        public int Read(BitReader reader)
        {
            int value = 1;

            while ((int)reader.Read(1) == tally)
            {
                value++;
            }

            return(value);
        }
示例#8
0
        /// <summary>
        /// Gets the value corresponding to a code.
        /// </summary>
        public int Read(BitReader reader)
        {
            int value = 0;
            int power = 1;

            while (true)
            {
                bool done = reader.Read(1) == 0;
                value += power * encoding.Read(reader);
                if (done)
                {
                    return(value);
                }
                power *= n;
            }
        }
示例#9
0
        /// <summary>
        /// Reads an encoded value from a <see cref="BitReader"/>.
        /// </summary>
        public int Read(BitReader reader)
        {
            int u = Codes.UnaryOnes.Read(reader) - 1;

            if (u == 0)
            {
                return(0);
            }
            int value = 1;

            while (--u > 0)
            {
                value = (int)reader.Read(value) | (1 << value);
            }

            return(value);
        }
示例#10
0
        /// <summary>
        /// Reads an encoded value from a <see cref="BitReader"/>.
        /// </summary>
        public int Read(BitReader reader)
        {
            var u = Codes.UnaryZeros.Read(reader) - 1;

            return((int)reader.Read(u) | (1 << u));
        }
示例#11
0
 /// <summary>
 /// Gets the value corresponding to a code.
 /// </summary>
 public int Read(BitReader reader)
 {
     return((int)reader.Read(bitCount));
 }
示例#12
0
        /// <summary>
        /// Reads an encoded value from a <see cref="BitReader"/>.
        /// </summary>
        public int Read(BitReader reader)
        {
            int u = Codes.UnaryOnes.Read(reader) - 1;

            return((int)reader.Read(exponentOf2) + (u << exponentOf2));
        }