protected override IList <int> DoIntersect(IList <int> arr1, IList <int> arr2)
        {
            var halfM = arr1.Count / 2;
            var v1    = arr1[halfM];
            var halfN = binarySearch(arr2, v1);

            _intersecter1.Intersect(new PartialList <int>(arr1, 0, halfM), new PartialList <int>(arr2, 0, halfN));
            _intersecter2.Intersect(new PartialList <int>(arr1, halfM), new PartialList <int>(arr2, halfN));
            Time = _intersecter1.Time + _intersecter2.Time;
            return(_intersecter1.Result.Concat(_intersecter2.Result).ToList());
        }
Esempio n. 2
0
        private static void displayIntersect(IIntersecter intersecter, IGenerator generator, string text, int?count = null, int?comparisons = null)
        {
            intersecter.Intersect(generator.Array1, generator.Array2);

            Console.WriteLine($"{text} intersecter:");
            colorWrite($"Comparisons: {intersecter.Comparisons}", () =>
            {
                if (comparisons == null)
                {
                    return(ConsoleColor.White);
                }
                switch (intersecter.Comparisons.CompareTo(comparisons.Value))
                {
                case -1:
                    return(ConsoleColor.Green);

                default:
                case 0:
                    return(ConsoleColor.White);

                case 1:
                    return(ConsoleColor.Red);
                }
            });
            if (comparisons == null)
            {
                Console.WriteLine();
            }
            else
            {
                var perc = 100 * (double)intersecter.Comparisons / comparisons.Value;
                Console.WriteLine($" ({perc:#.00}%)");
            }
            //Console.WriteLine($"Time: {intersecter.Time.TotalMilliseconds}");
            colorWrite($"Count: {intersecter.Result.Count}\r\n", () => count == null || intersecter.Result.Count == count ? ConsoleColor.White : ConsoleColor.Red);
        }