public SpatialSplitInfo Split(string otherFileName)
        {
            var latSize = BoundingRect.LatSize;
            var lonSize = BoundingRect.LonSize;

            var allNodes = ReadAllNodes();
            var allWays  = ReadAllWays();
            var allItems = new List <IMapObject>(nodesCount + waysCount);

            allItems.AddRange(allNodes);
            allItems.AddRange(allWays);

            Comparison <IMapObject> comparison;
            var splitByLatitude = latSize >= lonSize;

            if (splitByLatitude)
            {
                comparison = (a, b) => a.MidLat - b.MidLat;
            }
            else
            {
                comparison = (a, b) => a.MidLon - b.MidLon;
            }

            var splitter = new QuickSortSplitter <IMapObject>(Comparer <IMapObject> .Create(comparison));
            var position = splitter.Split(allItems, allItems.Count / 100);

            var splitValue = splitByLatitude ? allItems[position].MidLat : allItems[position].MidLon;


            var task = Task.Run(() =>
            {
                Clear();
                AddAll(this, allItems, 0, position);
            });

            var other = new SpatialBlock(otherFileName);

            AddAll(other, allItems, position, allItems.Count);

            task.Wait();

            return(new SpatialSplitInfo
            {
                SplitByLatitude = splitByLatitude,
                SplitValue = splitValue,
                FirstChild = new SpatialSplitInfo {
                    Block = this
                },
                SecondChild = new SpatialSplitInfo {
                    Block = other
                }
            });
        }
Esempio n. 2
0
        public void TestSplitSubsequences()
        {
            var rnd = new Random(125);

            var arr = new int[1000];

            for (var i = 0; i < arr.Length; i++)
            {
                arr[i] = i % 300;
            }

            var splitter = new QuickSortSplitter <int>();

            var result = splitter.Split(arr);

            result.Should().Be(500);
            Console.WriteLine($"{splitter.runCount}/{splitter.totalLength}.");

            var max = arr.Take(500).Max();
            var min = arr.Skip(500).Min();

            max.Should().BeLessOrEqualTo(min);
        }