public void VerifyEncoding_largecorpus()
        {
            string input  = TestResources.RFC5_Text;
            int    len    = input.Length;
            var    data   = new MemoryStream();
            var    writer = new BitBinaryWriter(data);
            var    reader = new BitBinaryReader(data);

            var compressor = new DynamicHuffman <char>(OriginalNYT);

            for (int i = 0; i < len; ++i)
            {
                compressor.WriteCode(input[i], writer.Write, writer.Write);
            }
            writer.Flush();
            data.Position = 0;

            var decompressor = new DynamicHuffman <char>(OriginalNYT);

            for (int i = 0; i < len; ++i)
            {
                Assert.AreEqual(input[i], decompressor.GetSymbol(reader.ReadBoolean, reader.ReadChar));
            }
            Assert.AreEqual(data.Position, data.Length);
        }
コード例 #2
0
        public void BitBinaryWriterCompatible()
        {
            var stream = new MemoryStream();
            var writer = new BitBinaryWriter(stream);
            var reader = new BitBinaryReader(stream);

            foreach (TestValue value in _testValuesWithBits)
            {
                value.Write(writer);
            }

            writer.Flush();
            stream.Position = 0;

            foreach (TestValue value in _testValuesWithBits)
            {
                value.Read(reader);
            }
        }
コード例 #3
0
        public static unsafe void Serialize(BinaryWriter writer, double *values, int count)
        {
            // Reserve one byte for future versioning.
            writer.Write((byte)1);
            SerializationUtils.WriteUInt32AsBase128(writer, (uint)count);
            if (count > 0)
            {
                BitBinaryWriter bitWriter     = new BitBinaryWriter(writer);
                var             previousState = new DoubleValueState(0, -1, -1);

                for (int i = 0; i < count; ++i)
                {
                    DoubleValueState newState;
                    WriteDouble(bitWriter, values[i], previousState, out newState);
                    previousState = newState;
                }

                bitWriter.Flush();
            }
        }
        public void VerifyEncoding_astrachan_()
        {
            string input  = "astrachan_";
            var    data   = new MemoryStream();
            var    writer = new BitBinaryWriter(data);
            var    reader = new BitBinaryReader(data);

            var compressor = new DynamicHuffman <char>(OriginalNYT);

            for (int i = 0; i < input.Length; ++i)
            {
                compressor.WriteCode(input[i], writer.Write, writer.Write);
            }
            writer.Flush();
            data.Position = 0;

            var decompressor = new DynamicHuffman <char>(OriginalNYT);

            for (int i = 0; i < input.Length; ++i)
            {
                Assert.AreEqual(input[i], decompressor.GetSymbol(reader.ReadBoolean, reader.ReadChar));
            }
            Assert.AreEqual(data.Position, data.Length);
        }