Esempio n. 1
0
        internal static void IntrospectiveSort <T>(Span <T> keys, Comparison <T> comparer)
        {
            Debug.Assert(keys != null);
            Debug.Assert(comparer != null);
            Debug.Assert(keys.Length >= 0);

            if (keys.Length < 2)
            {
                return;
            }

            IntroSort(keys, 0, keys.Length - 1, 2 * IntrospectiveSortUtilities.FloorLog2PlusOne(keys.Length), comparer);
        }
Esempio n. 2
0
        public static void Sort <T>(this Span <T> keys, Comparison <T> comparer)
        {
            Debug.Assert(keys != null, "Check the arguments in the caller!");
            Debug.Assert(keys.Length >= 0, "Check the arguments in the caller!");

            if (comparer == null)
            {
                throw new ArgumentNullException(nameof(comparer));
            }

            // Add a try block here to detect bogus comparisons
            try
            {
                IntrospectiveSort(keys, comparer);
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("IComparerFailed", e);
            }
        }