Example #1
0
 /// <summary>
 /// Creates a new shape.
 /// </summary>
 internal Shape(ArrayBase <float> coordinates, long pointer, int size)
 {
     _coordinates = coordinates;
     _pointer     = pointer;
     _size        = size;
     _reversed    = false;
 }
Example #2
0
        /// <summary>
        /// Creates a new geometric graph.
        /// </summary>
        public GeometricGraph(MemoryMap map, GeometricGraphProfile profile, int edgeDataSize, int size)
        {
            if (profile == null)
            {
                _graph       = new Graph(map, edgeDataSize, size);
                _coordinates = new Array <float>(map, size * 2);
                for (var i = 0; i < _coordinates.Length; i++)
                {
                    _coordinates[i] = NO_COORDINATE;
                }
                _shapes = new ShapesArray(map, size);
            }
            else
            {
                _graph       = new Graph(map, profile.GraphProfile, edgeDataSize, size);
                _coordinates = new Array <float>(map, size * 2, profile.CoordinatesProfile);
                for (var i = 0; i < _coordinates.Length; i++)
                {
                    _coordinates[i] = NO_COORDINATE;
                }
                _shapes = new ShapesArray(map, size);
            }

            _createElevation = (s) =>
            {
                return(new Array <short>(map, size));
            };
        }
Example #3
0
 /// <summary>
 /// Ensures that this <see cref="ArrayBase{T}"/> has room for at least
 /// the given number of elements, resizing and filling the empty space
 /// with the given value if not.
 /// </summary>
 /// <typeparam name="T">
 /// The type of element stored in this array.
 /// </typeparam>
 /// <param name="array">
 /// This array.
 /// </param>
 /// <param name="minimumSize">
 /// The minimum number of elements that this array must fit.
 /// </param>
 /// <param name="fillValue">
 /// The value to use to fill in the empty spaces if we have to resize.
 /// </param>
 public static void EnsureMinimumSize <T>(this ArrayBase <T> array, long minimumSize, T fillValue)
 {
     if (array.Length < minimumSize)
     {
         IncreaseMinimumSize(array, minimumSize, fillEnd: true, fillValueIfNeeded: fillValue);
     }
 }
Example #4
0
 /// <summary>
 /// Creates a new routing network from existing data.
 /// </summary>
 private RoutingNetwork(GeometricGraph graph, ArrayBase <uint> edgeData,
                        float maxEdgeDistance = Constants.DefaultMaxEdgeDistance)
 {
     _graph           = graph;
     _edgeData        = edgeData;
     _maxEdgeDistance = maxEdgeDistance;
 }
Example #5
0
 /// <summary>
 /// Creates a new routing network.
 /// </summary>
 public RoutingNetwork(MemoryMap map, GeometricGraph graph,
                       float maxEdgeDistance = Constants.DefaultMaxEdgeDistance)
 {
     _graph           = graph;
     _edgeData        = Context.ArrayFactory.CreateMemoryBackedArray <uint>(_edgeDataSize * graph.EdgeCount);
     _maxEdgeDistance = maxEdgeDistance;
 }
Example #6
0
        private System.Collections.Generic.IDictionary <int[], uint> _collectionReverseIndex; // Holds all tag collections and their reverse index.

        /// <summary>
        /// Creates a new empty index.
        /// </summary>
        public AttributesIndex(AttributesIndexMode mode = AttributesIndexMode.ReverseCollectionIndex |
                               AttributesIndexMode.ReverseStringIndex)
        {
            _stringIndex            = new Index <string>();
            _collectionIndex        = new Index <int[]>();
            _isReadonly             = false;
            _mode                   = mode;
            _stringReverseIndex     = null;
            _collectionReverseIndex = null;

            if ((_mode & AttributesIndexMode.IncreaseOne) == AttributesIndexMode.IncreaseOne)
            {
                _index  = new MemoryArray <uint>(1024);
                _nextId = 0;
            }

            if ((_mode & AttributesIndexMode.ReverseStringIndex) == AttributesIndexMode.ReverseStringIndex ||
                (_mode & AttributesIndexMode.ReverseStringIndexKeysOnly) == AttributesIndexMode.ReverseStringIndexKeysOnly)
            {
                _stringReverseIndex = new System.Collections.Generic.Dictionary <string, int>();
            }
            if ((_mode & AttributesIndexMode.ReverseCollectionIndex) == AttributesIndexMode.ReverseCollectionIndex)
            {
                _collectionReverseIndex = new System.Collections.Generic.Dictionary <int[], uint>(new EqualityComparer());
            }
        }
Example #7
0
        /// <summary>
        /// Creates a new index.
        /// </summary>
        public AttributesIndex(MemoryMap map,
                               AttributesIndexMode mode = AttributesIndexMode.ReverseCollectionIndex |
                               AttributesIndexMode.ReverseStringIndex)
        {
            if (mode == AttributesIndexMode.None)
            {
                throw new ArgumentException("Cannot create a new index without a valid operating mode.");
            }

            _stringIndex            = new Index <string>(map);
            _collectionIndex        = new Index <int[]>(map);
            _isReadonly             = false;
            _mode                   = mode;
            _stringReverseIndex     = null;
            _collectionReverseIndex = null;

            if ((_mode & AttributesIndexMode.IncreaseOne) == AttributesIndexMode.IncreaseOne)
            { // create the increment-by-one data structures.
                _index  = new Array <uint>(map, 1024);
                _nextId = 0;
            }

            if ((_mode & AttributesIndexMode.ReverseStringIndex) == AttributesIndexMode.ReverseStringIndex ||
                (_mode & AttributesIndexMode.ReverseStringIndexKeysOnly) == AttributesIndexMode.ReverseStringIndexKeysOnly)
            {
                _stringReverseIndex = new Reminiscence.Collections.Dictionary <string, int>(map, 1024 * 16);
            }
            if ((_mode & AttributesIndexMode.ReverseCollectionIndex) == AttributesIndexMode.ReverseCollectionIndex)
            {
                _collectionReverseIndex = new Reminiscence.Collections.Dictionary <int[], uint>(map, 1024 * 16, new EqualityComparer());
            }
        }
Example #8
0
 /// <summary>
 /// Creates a new routing network.
 /// </summary>
 public RoutingNetwork(MemoryMap map, GeometricGraph graph,
                       float maxEdgeDistance = Constants.DefaultMaxEdgeDistance)
 {
     _graph           = graph;
     _edgeData        = new MemoryArray <uint>(_edgeDataSize * graph.EdgeCount);
     _maxEdgeDistance = maxEdgeDistance;
 }
Example #9
0
        public void Sort(ArrayBase <uint> transformations)
        {
            int num1 = 0;

            while ((long)num1 < (long)this._nextEdgeId)
            {
                if ((int)this._edges[(long)(num1 + 0)] != -1)
                {
                    this._edges[(long)(num1 + 0)] = transformations[(long)this._edges[(long)(num1 + 0)]];
                }
                if ((int)this._edges[(long)(num1 + 1)] != -1)
                {
                    this._edges[(long)(num1 + 1)] = transformations[(long)this._edges[(long)(num1 + 1)]];
                }
                num1 += this._edgeSize;
            }
            QuickSort.Sort((Func <long, long>)(i =>
            {
                if (i < 0L || i >= transformations.Length)
                {
                    return(long.MaxValue);
                }
                return((long)transformations[i]);
            }), (Action <long, long>)((i, j) =>
            {
                uint num2          = this._vertices[i];
                this._vertices[i]  = this._vertices[j];
                this._vertices[j]  = num2;
                uint num3          = transformations[i];
                transformations[i] = transformations[j];
                transformations[j] = num3;
            }), 0L, (long)this.VertexCount);
        }
Example #10
0
 internal Shape(ArrayBase <float> coordinates, long pointer, int size)
 {
     this._coordinates = coordinates;
     this._pointer     = pointer;
     this._size        = size;
     this._reversed    = false;
 }
        internal HeatMapTile(ulong tileId, uint resolution = 1024)
        {
            TileId      = tileId;
            _resolution = resolution;

            _data = new MemoryArray <uint>(_resolution * _resolution);
        }
Example #12
0
        public override bool Run()
        {
            bool array_defined = !string.IsNullOrWhiteSpace(to);

            if (!System.IO.File.Exists(HandleCommands(path)))
            {
                throw new KScriptExceptions.KScriptException(this, "File does not exist.");
            }

            var fileInfo = new System.IO.FileInfo(HandleCommands(path));

            ArrayBase values = new ArrayBase(
                new ArrayCollection(new List <IArray>()
            {
                new ArrayItem("Directory", fileInfo.Directory.FullName),
                new ArrayItem("Extension", fileInfo.Extension),
                new ArrayItem("Size", fileInfo.Length.ToString()),
                new ArrayItem("Name", fileInfo.Name),
                new ArrayItem("ReadOnly", ToBoolString(fileInfo.IsReadOnly)),
                new ArrayItem("LastWriteTime", fileInfo.LastWriteTimeUtc.ToString()),
                new ArrayItem("LastAccessTime", fileInfo.LastAccessTimeUtc.ToString())
            })
                );

            var key = array_defined ? to : "this";

            KScript().GetMultidimensionalArrays()
            .RemoveArrayIfExists(key)
            .AddArray(key, values);

            return(true);
        }
Example #13
0
 /// <summary>
 /// Creates a new shape.
 /// </summary>
 internal Shape(ArrayBase <float> coordinates, long pointer, int size, bool reversed)
 {
     _coordinates = coordinates;
     _pointer     = pointer;
     _size        = size;
     _reversed    = reversed;
 }
Example #14
0
 /// <summary>
 /// Creates a new mapped huge array.
 /// </summary>
 /// <param name="baseArray">The base array.</param>
 /// <param name="elementSize">The size of one mapped structure when translate to the simpler structure.</param>
 /// <param name="mapTo">The map to implementation.</param>
 /// <param name="mapFrom">The map from implementation.</param>
 public MappedArray(ArrayBase <T> baseArray, int elementSize, MapTo mapTo, MapFrom mapFrom)
 {
     _baseArray   = baseArray;
     _elementSize = elementSize;
     _mapTo       = mapTo;
     _mapFrom     = mapFrom;
 }
Example #15
0
 internal Enumerator(ArrayBase <uint> connections,
                     ArrayBase <uint> connectionsOrder, uint count)
 {
     _connections      = connections;
     _connectionsOrder = connectionsOrder;
     _count            = count;
 }
        private Graph(int zoom, int edgeDataSize, int tileSizeInIndex, SparseMemoryArray <byte> tiles,
                      int coordinateSizeInBytes, MemoryArray <byte> vertices, uint vertexPointer, MemoryArray <uint> edgePointers,
                      uint edgePointer, MemoryArray <byte> edges, ShapesArray shapes)
        {
            _zoom         = zoom;
            _edgeDataSize = edgeDataSize;
            _edgeSize     = 8 * 2 +        // the vertices.
                            4 * 2 +        // the pointers to previous edges.
                            _edgeDataSize; // the edge data package.

            if (TileSizeInIndex != tileSizeInIndex)
            {
                throw new ArgumentOutOfRangeException($"{nameof(tileSizeInIndex)}");
            }
            _tiles = tiles;
            if (CoordinateSizeInBytes != coordinateSizeInBytes)
            {
                throw new ArgumentOutOfRangeException($"{nameof(coordinateSizeInBytes)}");
            }
            _vertices      = vertices;
            _vertexPointer = vertexPointer;
            _edgePointers  = edgePointers;
            _edgePointer   = edgePointer;
            _edges         = edges;
            _shapes        = shapes;
        }
Example #17
0
        /// <summary>
        /// Adds elevation.
        /// </summary>
        public void AddElevation(ElevationHandler.GetElevationDelegate getElevationFunc)
        {
            if (_elevation == null)
            {
                _elevation = _createElevation(_coordinates.Length / 2);
            }

            for (var i = 0; i < _index.Length; i++)
            {
                ShapesArray.ExtractPointerAndSize(_index[i], out var pointer, out var size);
                if (size > 0)
                {
                    for (var p = 0; p < size; p++)
                    {
                        var lat = _coordinates[pointer + (p * 2)];
                        var lon = _coordinates[pointer + (p * 2) + 1];

                        var e = getElevationFunc(lat, lon);
                        if (e.HasValue)
                        {
                            _elevation[pointer / 2 + p] = e.Value;
                        }
                        else
                        {
                            _elevation[pointer / 2 + p] = NO_ELEVATION;
                        }
                    }
                }
            }
        }
Example #18
0
        /// <summary>
        /// Updates the given vertex.
        /// </summary>
        public void UpdateVertex(uint vertex, float latitude, float longitude, short?elevation = null)
        {
            if (vertex >= _coordinates.Length)
            {
                throw new ArgumentException(string.Format("Vertex {0} does not exist.", vertex));
            }
            if (_coordinates[vertex].Equals(NO_COORDINATE))
            {
                throw new ArgumentException(string.Format("Vertex {0} does not exist.", vertex));
            }

            _coordinates[vertex * 2]     = latitude;
            _coordinates[vertex * 2 + 1] = longitude;

            if (elevation != null)
            {
                if (_elevation == null)
                {
                    _elevation = _createElevation(_coordinates.Length / 2);
                    for (var i = 0; i < _elevation.Length; i++)
                    {
                        _elevation[i] = NO_ELEVATION;
                    }
                }
                _elevation[vertex] = elevation.Value;
            }
        }
Example #19
0
 /// <summary>
 /// Creates a new geometric graph.
 /// </summary>
 private GeometricGraph(Graph graph, ArrayBase <float> coordinates,
                        ShapesArray shapes)
 {
     _graph       = graph;
     _coordinates = coordinates;
     _shapes      = shapes;
 }
Example #20
0
        /// <summary>
        /// Sets the coordinates for the given id.
        /// </summary>
        private void Set(long id, ShapeBase shape)
        {
            if (id < 0 || id >= _index.Length)
            {
                throw new IndexOutOfRangeException();
            }

            if (shape == null)
            { // reset.
                _index[id] = 0;
                return;
            }

            GetPointerAndSize(id, out var pointer, out var size);
            if (pointer < 0 || shape.Count < size)
            { // add the coordinates at the end.
                SetPointerAndSize(id, _nextPointer, shape.Count);

                // increase the size of the coordinates if needed.
                _coordinates.EnsureMinimumSize(_nextPointer + (2 * shape.Count));
                _elevation?.EnsureMinimumSize((_nextPointer / 2) + shape.Count);

                for (var i = 0; i < shape.Count; i++)
                {
                    var coordinate = shape[i];
                    _coordinates[_nextPointer + (i * 2)]     = coordinate.Latitude;
                    _coordinates[_nextPointer + (i * 2) + 1] = coordinate.Longitude;

                    if (coordinate.Elevation.HasValue)
                    {
                        if (_elevation == null)
                        {
                            _elevation = _createElevation(_coordinates.Length / 2);
                        }
                        _elevation[_nextPointer / 2 + i] = coordinate.Elevation.Value;
                    }
                }
                _nextPointer += (2 * shape.Count);
            }
            else
            { // update coordinates in-place.
                SetPointerAndSize(id, pointer, shape.Count);
                for (var i = 0; i < shape.Count; i++)
                {
                    var coordinate = shape[i];
                    _coordinates[pointer + (i * 2)]     = coordinate.Latitude;
                    _coordinates[pointer + (i * 2) + 1] = coordinate.Longitude;

                    if (coordinate.Elevation.HasValue)
                    {
                        if (_elevation == null)
                        {
                            _elevation = _createElevation(_coordinates.Length / 2);
                        }
                        _elevation[_nextPointer / 2 + i] = coordinate.Elevation.Value;
                    }
                }
            }
        }
Example #21
0
        /// <summary>
        /// Creates a new stop links db.
        /// </summary>
        public StopLinksDb(uint size, RouterDb routerDb, string profileName)
        {
            _pointers    = new MemoryArray <uint>(size * 2);
            _data        = new MemoryArray <uint>(size * 2);
            _profileName = profileName;

            _id = routerDb.Guid;
        }
 /// <summary>
 /// Creates a new shape.
 /// </summary>
 internal Shape(ArrayBase <double> coordinates, ArrayBase <short> elevation, long pointer, int size)
 {
     _coordinates = coordinates;
     _elevation   = elevation;
     _pointer     = pointer;
     _size        = size;
     _reversed    = false;
 }
Example #23
0
        /// <summary>
        /// Creates a new connections db.
        /// </summary>
        private ConnectionsDb(DefaultSorting?sorting, ArrayBase <uint> connections, ArrayBase <uint> connectionsOrder)
        {
            _sorting          = sorting;
            _connections      = connections;
            _connectionsOrder = connectionsOrder;

            _nextConnectionId = (uint)(_connectionsOrder.Length);
        }
Example #24
0
 /// <summary>
 /// Creates a new shape.
 /// </summary>
 internal Shape(ArrayBase <float> coordinates, ArrayBase <short> elevation, long pointer, int size, bool reversed)
 {
     _coordinates = coordinates;
     _elevation   = elevation;
     _pointer     = pointer;
     _size        = size;
     _reversed    = reversed;
 }
Example #25
0
        private Index(ArrayBase <ulong> data)
        {
            _data    = data;
            _pointer = _data.Length;
            _mapped  = (data is Array <ulong>);

            this.IsDirty = false;
        }
Example #26
0
        /// <summary>
        /// Used for deserialization.
        /// </summary>
        private MappedAttributesIndex(ArrayBase <uint> data, AttributesIndex attributes)
        {
            _data       = data;
            _pointer    = (int)_data.Length;
            _attributes = attributes;

            _reverseIndex = null;
        }
 /// <summary>
 /// Creates a new shape.
 /// </summary>
 internal Shape(ArrayBase <double> coordinates, long pointer, int size, bool reversed)
 {
     _coordinates = coordinates;
     _elevation   = null;
     _pointer     = pointer;
     _size        = size;
     _reversed    = reversed;
 }
Example #28
0
        /// <summary>
        /// Deserializes an shapes index from the given stream.
        /// </summary>
        public static ShapesArray CreateFrom(Stream stream, bool copy, out long size, bool hasElevation = false)
        {
            var initialPosition = stream.Position;

            size = 0;
            var longBytes = new byte[8];

            stream.Read(longBytes, 0, 8);
            size += 8;
            var indexLength = BitConverter.ToInt64(longBytes, 0);

            stream.Read(longBytes, 0, 8);
            size += 8;
            var coordinatesLength = BitConverter.ToInt64(longBytes, 0);

            ArrayBase <ulong> index;
            ArrayBase <float> coordinates;
            ArrayBase <short> elevation = null;

            if (copy)
            { // just create arrays and read the data.
                index = Context.ArrayFactory.CreateMemoryBackedArray <ulong>(indexLength);
                index.CopyFrom(stream);
                size       += indexLength * 8;
                coordinates = Context.ArrayFactory.CreateMemoryBackedArray <float>(coordinatesLength);
                size       += coordinatesLength * 4;
                coordinates.CopyFrom(stream);
                if (hasElevation)
                {
                    elevation = Context.ArrayFactory.CreateMemoryBackedArray <short>(coordinatesLength / 2);
                    size     += coordinatesLength;
                    elevation.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, indexLength * 8));
                index = new Array <ulong>(map1.CreateUInt64(indexLength));
                size += indexLength * 8;
                var map2 = new MemoryMapStream(new CappedStream(stream, position + indexLength * 8,
                                                                coordinatesLength * 4));
                coordinates = new Array <float>(map2.CreateSingle(coordinatesLength));
                size       += coordinatesLength * 4;
                if (hasElevation)
                {
                    var map3 = new MemoryMapStream(new CappedStream(stream, position + indexLength * 8 + coordinatesLength * 4,
                                                                    coordinatesLength));
                    elevation = new Array <short>(map3.CreateInt16(coordinatesLength / 2));
                    size     += coordinatesLength;
                }
            }

            // make stream is positioned correctly.
            stream.Seek(initialPosition + size, System.IO.SeekOrigin.Begin);

            return(new ShapesArray(index, coordinates, elevation));
        }
Example #29
0
        /// <summary>
        /// Creates a new stop links db.
        /// </summary>
        private StopLinksDb(Guid id, string profileName, ArrayBase <uint> pointers, ArrayBase <uint> data)
        {
            _id          = id;
            _profileName = profileName;
            _pointers    = pointers;
            _data        = data;

            _nextPointer = (uint)pointers.Length;
        }
Example #30
0
        /// <summary>
        /// Creates a new index.
        /// </summary>
        public AttributesIndex(MemoryMap map,
                               AttributesIndexMode mode = AttributesIndexMode.ReverseCollectionIndex |
                               AttributesIndexMode.ReverseStringIndex)
        {
            if (mode == AttributesIndexMode.None)
            {
                throw new ArgumentException("Cannot create a new index without a valid operating mode.");
            }

            _stringIndex            = new Index <string>(map);
            _collectionIndex        = new Index <int[]>(map);
            _isReadonly             = false;
            _mode                   = mode;
            _stringReverseIndex     = null;
            _collectionReverseIndex = null;

            if ((_mode & AttributesIndexMode.IncreaseOne) == AttributesIndexMode.IncreaseOne)
            { // create the increment-by-one data structures.
                _index  = new Array <uint>(map, 1024);
                _nextId = 0;
            }

            if ((_mode & AttributesIndexMode.ReverseStringIndex) == AttributesIndexMode.ReverseStringIndex ||
                (_mode & AttributesIndexMode.ReverseStringIndexKeysOnly) == AttributesIndexMode.ReverseStringIndexKeysOnly)
            {
                _stringReverseIndex = new Reminiscence.Collections.Dictionary <string, int>(map, 1024 * 16);
            }
            if ((_mode & AttributesIndexMode.ReverseCollectionIndex) == AttributesIndexMode.ReverseCollectionIndex)
            {
                _collectionReverseIndex = new Reminiscence.Collections.Dictionary <int[], uint>(map, 1024 * 16,
                                                                                                new DelegateEqualityComparer <int[]>(
                                                                                                    (obj) =>
                {         // assumed the array is sorted.
                    var hash = obj.Length.GetHashCode();
                    for (int idx = 0; idx < obj.Length; idx++)
                    {
                        hash = hash ^ obj[idx].GetHashCode();
                    }
                    return(hash);
                },
                                                                                                    (x, y) =>
                {
                    if (x.Length == y.Length)
                    {
                        for (int idx = 0; idx < x.Length; idx++)
                        {
                            if (x[idx] != y[idx])
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                    return(false);
                }));
            }
        }