예제 #1
0
        public void TestStructuresOfArraysSerialize()
        {
            var randomGenerator = new RandomGenerator(66707770); // make this deterministic.

            var index = new MemoryMappedIndex <int[]>(new MemoryMappedStream(new MemoryStream()),
                                                      MemoryMappedDelegates.ReadFromIntArray, MemoryMappedDelegates.WriteToIntArray);
            var indexRef = new Dictionary <long, int[]>();

            // add the data.
            var testCount = 10;

            while (testCount > 0)
            {
                var data = randomGenerator.GenerateArray(512, 512);
                indexRef.Add(index.Add(data), data);
                testCount--;
            }

            MemoryMappedIndex <int[]> deserializedIndex;

            using (var stream = new MemoryStream())
            {
                var size = index.Serialize(stream);
                deserializedIndex = MemoryMappedIndex <int[]> .Deserialize(stream,
                                                                           MemoryMappedDelegates.ReadFromIntArray, MemoryMappedDelegates.WriteToIntArray, false);

                // get the data and check.
                foreach (var entry in indexRef)
                {
                    var data = index.Get(entry.Key);
                    Assert.AreEqual(indexRef[entry.Key], data);
                }
            }
        }
예제 #2
0
        public void TestStringSerialize()
        {
            var randomGenerator = new RandomGenerator(66707770); // make this deterministic.

            var index = new MemoryMappedIndex <string>(new MemoryMappedStream(new MemoryStream()),
                                                       MemoryMappedDelegates.ReadFromString, MemoryMappedDelegates.WriteToString);
            var indexRef = new Dictionary <long, string>();

            // add the data.
            var testCount = 10;

            while (testCount > 0)
            {
                var data = randomGenerator.GenerateString(
                    randomGenerator.Generate(256) + 32);
                indexRef.Add(index.Add(data), data);
                testCount--;
            }

            MemoryMappedIndex <string> deserializedIndex;

            using (var stream = new MemoryStream())
            {
                var size = index.Serialize(stream);
                deserializedIndex = MemoryMappedIndex <string> .Deserialize(stream,
                                                                            MemoryMappedDelegates.ReadFromString, MemoryMappedDelegates.WriteToString, false);

                // get the data and check.
                foreach (var entry in indexRef)
                {
                    var data = index.Get(entry.Key);
                    Assert.AreEqual(deserializedIndex.Get(entry.Key), data);
                }
            }
        }
예제 #3
0
        public void TestStructuresOfArraysSerialize()
        {
            var randomGenerator = new RandomGenerator(66707770); // make this deterministic.

            var index = new MemoryMappedIndex<int[]>(new MemoryMappedStream(new MemoryStream()),
                MemoryMappedDelegates.ReadFromIntArray, MemoryMappedDelegates.WriteToIntArray);
            var indexRef = new Dictionary<long, int[]>();

            // add the data.
            var testCount = 10;
            while (testCount > 0)
            {
                var data = randomGenerator.GenerateArray(512, 512);
                indexRef.Add(index.Add(data), data);
                testCount--;
            }

            MemoryMappedIndex<int[]> deserializedIndex;
            using (var stream = new MemoryStream())
            {
                var size = index.Serialize(stream);
                deserializedIndex = MemoryMappedIndex<int[]>.Deserialize(stream,
                    MemoryMappedDelegates.ReadFromIntArray, MemoryMappedDelegates.WriteToIntArray, false);

                // get the data and check.
                foreach (var entry in indexRef)
                {
                    var data = index.Get(entry.Key);
                    Assert.AreEqual(indexRef[entry.Key], data);
                }
            }
        }
예제 #4
0
        public void TestStringSerialize()
        {
            var randomGenerator = new RandomGenerator(66707770); // make this deterministic.

            var index = new MemoryMappedIndex<string>(new MemoryMappedStream(new MemoryStream()),
                MemoryMappedDelegates.ReadFromString, MemoryMappedDelegates.WriteToString);
            var indexRef = new Dictionary<long, string>();

            // add the data.
            var testCount = 10;
            while (testCount > 0)
            {
                var data = randomGenerator.GenerateString(
                    randomGenerator.Generate(256) + 32);
                indexRef.Add(index.Add(data), data);
                testCount--;
            }

            MemoryMappedIndex<string> deserializedIndex;
            using (var stream = new MemoryStream())
            {
                var size = index.Serialize(stream);
                deserializedIndex = MemoryMappedIndex<string>.Deserialize(stream,
                    MemoryMappedDelegates.ReadFromString, MemoryMappedDelegates.WriteToString, false);

                // get the data and check.
                foreach (var entry in indexRef)
                {
                    var data = index.Get(entry.Key);
                    Assert.AreEqual(deserializedIndex.Get(entry.Key), data);
                }
            }
        }