Ejemplo n.º 1
0
        /// <summary>
        /// Tests writing to an array.
        /// </summary>
        public static void TestWrite(ArrayProfile profile)
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                       FileMode.Create, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var array = new Array <int>(map, Global.ArrayTestLength,
                                                profile);

                    var perf = new PerformanceInfoConsumer(
                        string.Format("Write Array: {0}", profile.ToString()),
                        1000);
                    perf.Start();
                    for (var i = 0; i < array.Length; i++)
                    {
                        array[i] = i * 2;

                        if (Global.Verbose && i % (array.Length / 100) == 0)
                        {
                            perf.Report("Writing... {0}%", i, array.Length - 1);
                        }
                    }
                    perf.Stop();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Tests read from an array.
        /// </summary>
        public static void TestReadRandom(ArrayProfile profile)
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                       FileMode.Open, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var array = new Array <int>(map.CreateInt32(mapStream.Length / 4), profile);

                    var size = 1000000;
                    var perf = new PerformanceInfoConsumer(
                        string.Format("Read Random Array: {0} {1}", size, profile.ToString()),
                        1000);
                    perf.Start();
                    var rand = new Random();
                    for (var i = 0; i < size; i++)
                    {
                        var ran = (long)rand.Next((int)array.Length);
                        var val = array[ran];
                        if (val != ran * 2)
                        { // oeps, something went wrong here!
                            throw new System.Exception();
                        }

                        if (Global.Verbose && i % (size / 100) == 0)
                        {
                            perf.Report("Reading... {0}%", i, size);
                        }
                    }
                    perf.Stop();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deserializes a meta-collection from the given stream.
        /// </summary>
        public static MetaCollection Deserialize(Stream stream, ArrayProfile profile)
        {
            var version = stream.ReadByte();

            if (version != 1)
            {
                throw new Exception(string.Format("Cannot deserialize meta-data collection: Invalid version #: {0}, upgrade Itinero.", version));
            }

            var byteHeader = stream.ReadByte();
            var type       = MetaCollection.GetTypeForHeader(byteHeader);

            var bytes = new byte[8];

            stream.Read(bytes, 0, 8);
            var length = BitConverter.ToInt64(bytes, 0);

            if (type == typeof(int))
            {
                return(new MetaCollection <int>(MetaCollection.DeserializeArray <int>(
                                                    stream, profile, length, 4)));
            }
            if (type == typeof(uint))
            {
                return(new MetaCollection <uint>(MetaCollection.DeserializeArray <uint>(
                                                     stream, profile, length, 4)));
            }
            if (type == typeof(long))
            {
                return(new MetaCollection <long>(MetaCollection.DeserializeArray <long>(
                                                     stream, profile, length, 8)));
            }
            if (type == typeof(ulong))
            {
                return(new MetaCollection <ulong>(MetaCollection.DeserializeArray <ulong>(
                                                      stream, profile, length, 8)));
            }
            if (type == typeof(float))
            {
                return(new MetaCollection <float>(MetaCollection.DeserializeArray <float>(
                                                      stream, profile, length, 4)));
            }
            if (type == typeof(double))
            {
                return(new MetaCollection <double>(MetaCollection.DeserializeArray <double>(
                                                       stream, profile, length, 8)));
            }
            throw new Exception(string.Format(
                                    "Meta collection not supported for type {0}: MetaCollection can only handle integer types or float and double.",
                                    type));
        }
Ejemplo n.º 4
0
        static DirectedGraphProfile()
        {
            DirectedGraphProfile directedGraphProfile = new DirectedGraphProfile();

            directedGraphProfile.VertexProfile = (ArrayProfile)ArrayProfile.Aggressive8;
            ArrayProfile arrayProfile = new ArrayProfile();
            int          num1         = 1024;

            arrayProfile.BufferSize = num1;
            int num2 = 16;

            arrayProfile.CacheSize            = num2;
            directedGraphProfile.EdgeProfile  = arrayProfile;
            DirectedGraphProfile.Aggressive24 = directedGraphProfile;
        }
Ejemplo n.º 5
0
        static GraphProfile()
        {
            GraphProfile graphProfile = new GraphProfile();

            graphProfile.VertexProfile = (ArrayProfile)ArrayProfile.Aggressive8;
            ArrayProfile arrayProfile = new ArrayProfile();
            int          num1         = 1024;

            arrayProfile.BufferSize = num1;
            int num2 = 16;

            arrayProfile.CacheSize    = num2;
            graphProfile.EdgeProfile  = arrayProfile;
            GraphProfile.Aggressive24 = graphProfile;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deserializes an array.
        /// </summary>
        protected static ArrayBase <T> DeserializeArray <T>(Stream stream, ArrayProfile profile, long length, int elementSize)
        {
            ArrayBase <T> data;

            if (profile == null)
            { // just create arrays and read the data.
                data = new MemoryArray <T>(length);
                data.CopyFrom(stream);
            }
            else
            { // create accessors over the exact part of the stream that represents items/edges.
                var position  = stream.Position;
                var byteCount = length * elementSize;
                var map       = new MemoryMapStream(new CappedStream(stream, position, byteCount));
                var accessor  = MemoryMap.GetCreateAccessorFuncFor <T>()(map, length);
                data = new Array <T>(accessor, profile);
                stream.Seek(position + byteCount, SeekOrigin.Begin);
            }
            return(data);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Deserializes an index from the given stream.
        /// </summary>
        public static Index Deserialize(Stream stream, ArrayProfile profile = null)
        {
            var bytes = new byte[8];

            stream.Read(bytes, 0, 8);
            var size = BitConverter.ToInt64(bytes, 0);

            ArrayBase <ulong> data;

            if (profile == null)
            { // just create arrays and read the data.
                data = new MemoryArray <ulong>(size);
                data.CopyFrom(stream);
            }
            else
            { // create accessors over the exact part of the stream that represents vertices/edges.
                var position = stream.Position;
                var map1     = new MemoryMapStream(new CappedStream(stream, position, size * 8));
                data = new Array <ulong>(map1.CreateUInt64(size), profile);
            }

            return(new Index(data));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Deserializes a db.
        /// </summary>
        public static MetaCollectionDb Deserialize(Stream stream, ArrayProfile profile = null)
        {
            var version = stream.ReadByte();

            if (version != 1)
            {
                if (version != 1)
                {
                    throw new Exception(string.Format("Cannot deserialize meta-data db: Invalid version #: {0}, upgrade Itinero.", version));
                }
            }

            var collections = new Dictionary <string, MetaCollection>();
            var count       = stream.ReadByte();

            for (var i = 0; i < count; i++)
            {
                var name       = stream.ReadWithSizeString();
                var collection = MetaCollection.Deserialize(stream, profile);

                collections[name] = collection;
            }
            return(new MetaCollectionDb(collections));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a new list.
 /// </summary>
 public List(MemoryMap map, long capacity, ArrayProfile arrayProfile)
 {
     _data = ArrayBase <T> .CreateFor(map, capacity, arrayProfile);
 }