Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Deserializes a tags index from the given stream.
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static TagsIndex Deserialize(System.IO.Stream stream)
        {
            long size;
            var  tagsIndex = MemoryMappedIndex <int[]> .Deserialize(stream, MemoryMappedDelegates.ReadFromIntArray, MemoryMappedDelegates.WriteToIntArray, false, out size);

            stream.Seek(size, System.IO.SeekOrigin.Begin);
            var limitedStream = new LimitedStream(stream);
            var stringIndex   = MemoryMappedIndex <string> .Deserialize(limitedStream, MemoryMappedDelegates.ReadFromString, MemoryMappedDelegates.WriteToString, false);

            return(new TagsIndex(stringIndex, tagsIndex));
        }