public void CompareSpeedOfSorting_SmallBalancedSort_vs_HilbertIndex()
        {
            var points = TestData(20000, 50, 20, 1000000, 100, 500, out int bitsPerDimension);

            var timer1 = new Stopwatch();
            var timer2 = new Stopwatch();
            var timer3 = new Stopwatch();

            // 1. HilbertIndex
            timer1.Start();
            var hIndex = new HilbertIndex(points.Select(p => new HilbertPoint(p.Coordinates, bitsPerDimension)));
            var sortedPointsFromIndex = hIndex.SortedPoints;

            timer1.Stop();
            var hilbertIndexTime = timer1.ElapsedMilliseconds;

            // 2. HilbertSort.SmallBalancedSort
            timer2.Start();
            timer3.Start();
            PointBalancer balancer = new PointBalancer(points);

            timer3.Stop();
            HilbertSort.SmallBalancedSort(points, ref balancer);
            timer2.Stop();
            var inplaceSortTime = timer2.ElapsedMilliseconds;
            var balancerTime    = timer3.ElapsedMilliseconds;

            var message = $"HilbertIndex required {hilbertIndexTime/1000.0} sec.  In-place Sort required {inplaceSortTime/1000.0} sec, of which {balancerTime/1000.0} sec is Balancer ctor.  Relative Cost = {HilbertSort.RelativeSortCost}";

            Console.WriteLine(message);
            Assert.Greater(hilbertIndexTime, inplaceSortTime, message);
        }
        public void InPlaceSort_NarrowClusters()
        {
            var           points          = TestData(20000, 50, 20, 1000000, 10, 30, out int bitsPerDimension);
            PointBalancer balancer        = new PointBalancer(points);
            var           unoptimizedSort = HilbertSort.BalancedSort(points.ToList(), ref balancer).ToArray();

            HilbertSort.SmallBalancedSort(points, ref balancer);
            CollectionAssert.AreEqual(unoptimizedSort, points, "Not in same order");
        }
        public void InPlaceSortRelativeCost()
        {
            var clusters      = new[] { 10, 20, 50, 100 };
            var stdDeviations = new[] { 20, 100, 200, 1000, 2000 };
            var dimensions    = 50;
            var numPoints     = 20000;
            var report        = "Clusters,Standard Deviation,Relative Cost\n";

            foreach (var k in clusters)
            {
                foreach (var sd in stdDeviations)
                {
                    var           points   = TestData(numPoints, dimensions, k, 1000000, sd, sd, out int bitsPerDimension);
                    PointBalancer balancer = new PointBalancer(points);
                    HilbertSort.SmallBalancedSort(points, ref balancer);
                    var cost = HilbertSort.RelativeSortCost;
                    report += $"{k},{sd},{cost}\n";
                }
            }
            Console.WriteLine($"\n\nFinal report:\n\n{report}");
        }