示例#1
0
        // Do not add a constructor to this class because ArraySortHelper<T>.CreateSortHelper will not execute it

        #region IArraySortHelper<T> Members

        public void Sort(T[] keys, int index, int length, IComparer <T>?comparer)
        {
            Debug.Assert(keys != null, "Check the arguments in the caller!");
            Debug.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!");

            try
            {
                if (comparer == null || comparer == Comparer <T> .Default)
                {
                    IntrospectiveSort(keys, index, length);
                }
                else
                {
                    ArraySortHelper <T> .IntrospectiveSort(keys, index, length, comparer.Compare);
                }
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
            }
        }
示例#2
0
        public void Sort(T[] keys, int index, int length, IComparer <T> comparer)
        {
            Debug.Assert(keys != null, "Check the arguments in the caller!");
            Debug.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!");

            // Add a try block here to detect IComparers (or their
            // underlying IComparables, etc) that are bogus.
            try
            {
                if (comparer == null)
                {
                    comparer = Comparer <T> .Default;
                }

                IntrospectiveSort(keys, index, length, comparer.Compare);
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
            }
        }
示例#3
0
 // Token: 0x06003A1B RID: 14875 RVA: 0x000DC1BC File Offset: 0x000DA3BC
 public void Sort(T[] keys, int index, int length, IComparer <T> comparer)
 {
     try
     {
         if (comparer == null)
         {
             comparer = Comparer <T> .Default;
         }
         if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
         {
             ArraySortHelper <T> .IntrospectiveSort(keys, index, length, comparer);
         }
         else
         {
             ArraySortHelper <T> .DepthLimitedQuickSort(keys, index, length + index - 1, comparer, 32);
         }
     }
     catch (IndexOutOfRangeException)
     {
         IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
     }
     catch (Exception innerException)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException);
     }
 }
示例#4
0
 public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer <TKey> comparer)
 {
     try
     {
         if (comparer == null || comparer == Comparer <TKey> .Default)
         {
             if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
             {
                 GenericArraySortHelper <TKey, TValue> .IntrospectiveSort(keys, values, index, length);
             }
             else
             {
                 GenericArraySortHelper <TKey, TValue> .DepthLimitedQuickSort(keys, values, index, length + index - 1, 32);
             }
         }
         else if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
         {
             ArraySortHelper <TKey, TValue> .IntrospectiveSort(keys, values, index, length, comparer);
         }
         else
         {
             ArraySortHelper <TKey, TValue> .DepthLimitedQuickSort(keys, values, index, length + index - 1, comparer, 32);
         }
     }
     catch (IndexOutOfRangeException ex)
     {
         IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer((object)comparer);
     }
     catch (Exception ex)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), ex);
     }
 }
示例#5
0
 internal static void IntrospectiveSort(T[] keys, int left, int length)
 {
     if (length < 2)
     {
         return;
     }
     GenericArraySortHelper <T> .IntroSort(keys, left, length + left - 1, 2 *IntrospectiveSortUtilities.FloorLog2(keys.Length));
 }
示例#6
0
        internal static void IntrospectiveSort(Span <T> keys, Comparison <T> comparer)
        {
            Debug.Assert(comparer != null);

            if (keys.Length > 1)
            {
                IntroSort(keys, 2 * IntrospectiveSortUtilities.FloorLog2PlusOne(keys.Length), comparer);
            }
        }
示例#7
0
        internal static void IntrospectiveSort(T[] keys, int left, int length, IComparer <T> comparer)
        {
            if (length < 2)
            {
                return;
            }

            IntroSort(keys, left, length + left - 1, 2 * IntrospectiveSortUtilities.FloorLog2(keys.Length), comparer);
        }
示例#8
0
        internal static void IntrospectiveSort(T[] keys, int left, int length)
        {
            Debug.Assert(keys != null);
            Debug.Assert(left >= 0);
            Debug.Assert(length >= 0);
            Debug.Assert(length <= keys.Length);
            Debug.Assert(length + left <= keys.Length);

            if (length < 2)
            {
                return;
            }

            IntroSort(keys, left, length + left - 1, 2 * IntrospectiveSortUtilities.FloorLog2PlusOne(keys.Length));
        }
示例#9
0
        internal static void IntrospectiveSort(T[] keys, int left, int length)
        {
            Contract.Requires(keys != null);
            Contract.Requires(left >= 0);
            Contract.Requires(length >= 0);
            Contract.Requires(length <= keys.Length);
            Contract.Requires(length + left <= keys.Length);

            if (length < 2)
            {
                return;
            }

            IntroSort(keys, left, length + left - 1, 2 * IntrospectiveSortUtilities.FloorLog2(keys.Length));
        }
示例#10
0
        internal static void IntrospectiveSort(T[] keys, int left, int length, IComparer <T> comparer)
        {
            Debug.Assert(keys != null);
            Debug.Assert(comparer != null);
            Debug.Assert(left >= 0);
            Debug.Assert(length >= 0);
            Debug.Assert(length <= keys.Length);
            Debug.Assert(length + left <= keys.Length);

            if (length < 2)
            {
                return;
            }

            IntroSort(keys, left, length + left - 1, 2 * IntrospectiveSortUtilities.FloorLog2(keys.Length), comparer);
        }
示例#11
0
        internal static void IntrospectiveSort(IList <T> keys, int left, int length, Comparison <T> comparer)
        {
            Debug.Assert(keys != null);
            Debug.Assert(comparer != null);
            Debug.Assert(left >= 0);
            Debug.Assert(length >= 0);
            Debug.Assert(length <= keys.Count);
            Debug.Assert(length + left <= keys.Count);

            if (length < 2)
            {
                return;
            }

            IntroSort(keys, left, length + left - 1, 2 * IntrospectiveSortUtilities.FloorLog2PlusOne(length), comparer);
        }
示例#12
0
        internal static void Sort(Span <T> keys, Comparison <T> comparer)
        {
            Debug.Assert(comparer != null, "Check the arguments in the caller!");

            // Add a try block here to detect bogus comparisons
            try
            {
                IntrospectiveSort(keys, comparer);
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
            }
        }
示例#13
0
 public void Sort(Span <T> keys, IComparer <T>?comparer)
 {
     // Add a try block here to detect IComparers (or their
     // underlying IComparables, etc) that are bogus.
     try
     {
         comparer ??= Comparer <T> .Default;
         IntrospectiveSort(keys, comparer.Compare);
     }
     catch (IndexOutOfRangeException)
     {
         IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
     }
     catch (Exception e)
     {
         throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
     }
 }
示例#14
0
        internal static void Sort(IList <T> keys, int index, int length, Comparison <T> comparer)
        {
            Debug.Assert(keys != null, "Check the arguments in the caller!");
            Debug.Assert(index >= 0 && length >= 0 && (keys.Count - index >= length), "Check the arguments in the caller!");
            Debug.Assert(comparer != null, "Check the arguments in the caller!");

            // Add a try block here to detect bogus comparisons
            try
            {
                IntrospectiveSort(keys, index, length, comparer);
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(Resource.InvalidOperation_IComparerFailed, e);
            }
        }
示例#15
0
        internal static void Sort(T[] keys, int index, int length, Comparison <T> comparer)
        {
            Contract.Assert(keys != null, "Check the arguments in the caller!");
            Contract.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!");
            Contract.Assert(comparer != null, "Check the arguments in the caller!");

            // Add a try block here to detect bogus comparisons
            try
            {
                IntrospectiveSort(keys, index, length, comparer);
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
            }
        }
示例#16
0
 // Token: 0x06003A3C RID: 14908 RVA: 0x000DCF9B File Offset: 0x000DB19B
 internal static void IntrospectiveSort(TKey[] keys, TValue[] values, int left, int length, IComparer <TKey> comparer)
 {
     if (length < 2)
     {
         return;
     }
     ArraySortHelper <TKey, TValue> .IntroSort(keys, values, left, length + left - 1, 2 *IntrospectiveSortUtilities.FloorLog2(keys.Length), comparer);
 }