Exemplo n.º 1
0
        /// <summary>
        /// Increases the memory allocation.
        /// </summary>
        private void IncreaseEdgeSize(long size)
        {
            var oldLength = _edges.Length;

            _edges.Resize(size);
            _edgeData.Resize(size / EDGE_SIZE);
            _edgeShapes.Resize(size / EDGE_SIZE);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Increases the memory allocation.
        /// </summary>
        private void IncreaseEdgeSize(long size)
        {
            var oldLength = _edges.Length;

            _edges.Resize(size);
            for (long idx = oldLength; idx < size; idx++)
            {
                _edges[idx] = NO_EDGE;
            }
            _edgeData.Resize(size / EDGE_SIZE);
            _edgeShapes.Resize(size / EDGE_SIZE);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Increases the memory allocation.
        /// </summary>
        private void IncreaseEdgeSize(long size)
        {
            if (_readonly)
            {
                throw new Exception("Graph is readonly.");
            }

            var oldLength = _edges.Length;

            _edges.Resize(size);
            _edgeData.Resize(size / EDGE_SIZE);
            _edgeShapes.Resize(size / EDGE_SIZE);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a new in-memory graph.
 /// </summary>
 /// <param name="sizeEstimate"></param>
 /// <param name="coordinateArray"></param>
 /// <param name="vertexArray"></param>
 /// <param name="edgesArray"></param>
 /// <param name="edgeDataArray"></param>
 /// <param name="edgeShapeArray"></param>
 public DirectedGraph(long sizeEstimate, HugeArrayBase <GeoCoordinateSimple> coordinateArray,
                      HugeArrayBase <uint> vertexArray, HugeArrayBase <uint> edgesArray, HugeArrayBase <TEdgeData> edgeDataArray, HugeCoordinateCollectionIndex edgeShapeArray)
 {
     _nextVertexId = 1;
     _nextEdgeId   = 0;
     _vertices     = vertexArray;
     _vertices.Resize(sizeEstimate);
     _coordinates = coordinateArray;
     _coordinates.Resize(sizeEstimate);
     _edges = edgesArray;
     _edges.Resize(sizeEstimate * 3 * EDGE_SIZE);
     _edgeData = edgeDataArray;
     _edgeData.Resize(sizeEstimate * 3);
     _edgeShapes = edgeShapeArray;
     _edgeShapes.Resize(sizeEstimate * 3);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new in-memory graph.
 /// </summary>
 /// <param name="sizeEstimate"></param>
 /// <param name="coordinateArray"></param>
 /// <param name="vertexArray"></param>
 /// <param name="edgesArray"></param>
 /// <param name="edgeDataArray"></param>
 /// <param name="edgeShapeArray"></param>
 protected MemoryGraph(long sizeEstimate, IHugeArray <GeoCoordinateSimple> coordinateArray, IHugeArray <uint> vertexArray, IHugeArray <uint> edgesArray, IHugeArray <TEdgeData> edgeDataArray, HugeCoordinateCollectionIndex edgeShapeArray)
 {
     _nextVertexId = 1;
     _nextEdgeId   = 0;
     _vertices     = vertexArray;
     _vertices.Resize(sizeEstimate);
     for (int idx = 0; idx < sizeEstimate; idx++)
     {
         _vertices[idx] = NO_EDGE;
     }
     _coordinates = coordinateArray;
     _coordinates.Resize(sizeEstimate);
     _edges = edgesArray;
     _edges.Resize(sizeEstimate * 3 * EDGE_SIZE);
     for (int idx = 0; idx < sizeEstimate * 3 * EDGE_SIZE; idx++)
     {
         _edges[idx] = NO_EDGE;
     }
     _edgeData = edgeDataArray;
     _edgeData.Resize(sizeEstimate * 3);
     _edgeShapes = edgeShapeArray;
     _edgeShapes.Resize(sizeEstimate * 3);
 }
        public void TestResize()
        {
            OsmSharp.Math.Random.StaticRandomGenerator.Set(116542346);

            var box = new GeoCoordinateBox(
                new GeoCoordinate(90, 180),
                new GeoCoordinate(-90, -180));
            var size = 100;
            var maxCollectionSize   = 4;
            var referenceDictionary = new Dictionary <long, ICoordinateCollection>();
            var coordinates         = new HugeCoordinateCollectionIndex(400);

            for (int idx = 0; idx < size; idx++)
            {
                var currentSize      = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(maxCollectionSize) + 1;
                var coordinatesArray = new GeoCoordinate[currentSize];
                while (currentSize > 0)
                {
                    coordinatesArray[currentSize - 1] = box.GenerateRandomIn(OsmSharp.Math.Random.StaticRandomGenerator.Get());
                    currentSize--;
                }
                var coordinatesCollection = new CoordinateArrayCollection <GeoCoordinate>(coordinatesArray);
                referenceDictionary[idx] = coordinatesCollection;
                coordinates[idx]         = coordinatesCollection;
            }

            // check result.
            for (int idx = 0; idx < size; idx++)
            {
                var referenceCollection = referenceDictionary[idx];
                var collection          = coordinates[idx];

                referenceCollection.Reset();
                collection.Reset();

                while (referenceCollection.MoveNext())
                {
                    Assert.IsTrue(collection.MoveNext());
                    Assert.AreEqual(referenceCollection.Latitude, collection.Latitude);
                    Assert.AreEqual(referenceCollection.Longitude, collection.Longitude);
                }
                Assert.IsFalse(collection.MoveNext());
            }

            // change size and check result.
            var newSize = 75;

            coordinates.Resize(newSize);

            // check result.
            Assert.AreEqual(75, coordinates.LengthIndex);
            for (var idx = 0; idx < newSize; idx++)
            {
                var referenceCollection = referenceDictionary[idx];
                var collection          = coordinates[idx];

                referenceCollection.Reset();
                collection.Reset();

                while (referenceCollection.MoveNext())
                {
                    Assert.IsTrue(collection.MoveNext());
                    Assert.AreEqual(referenceCollection.Latitude, collection.Latitude);
                    Assert.AreEqual(referenceCollection.Longitude, collection.Longitude);
                }
                Assert.IsFalse(collection.MoveNext());
            }
        }