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)
             {
                 GenericArraySortHelper <T> .IntrospectiveSort(keys, index, length);
             }
             else
             {
                 GenericArraySortHelper <T> .DepthLimitedQuickSort(keys, index, length + index - 1, 32);
             }
         }
         else 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 ex)
     {
         IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer((object)comparer);
     }
     catch (Exception ex)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), ex);
     }
 }
Exemple #2
0
 // Token: 0x06003A38 RID: 14904 RVA: 0x000DCD3C File Offset: 0x000DAF3C
 public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer <TKey> comparer)
 {
     try
     {
         if (comparer == null || comparer == Comparer <TKey> .Default)
         {
             comparer = Comparer <TKey> .Default;
         }
         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)
     {
         IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
     }
     catch (Exception innerException)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException);
     }
 }
Exemple #3
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)
        {
            try
            {
                if (comparer == null || comparer == Comparer <T> .Default)
                {
                    DepthLimitedQuickSort(keys, index, length + index - 1, IntrospectiveSortUtilities.QuickSortDepthThreshold);
                }
                else
                {
                    ArraySortHelper <T> .DepthLimitedQuickSort(keys, index, length + index - 1, comparer, IntrospectiveSortUtilities.QuickSortDepthThreshold);
                }
            }
            catch (IndexOutOfRangeException)
            {
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("IComparerFailed");
            }
        }
Exemple #4
0
        // Token: 0x06003A3B RID: 14907 RVA: 0x000DCE80 File Offset: 0x000DB080
        internal static void DepthLimitedQuickSort(TKey[] keys, TValue[] values, int left, int right, IComparer <TKey> comparer, int depthLimit)
        {
            while (depthLimit != 0)
            {
                int num  = left;
                int num2 = right;
                int num3 = num + (num2 - num >> 1);
                ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, num, num3);

                ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, num, num2);

                ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, num3, num2);

                TKey tkey = keys[num3];
                for (;;)
                {
                    if (comparer.Compare(keys[num], tkey) >= 0)
                    {
                        while (comparer.Compare(tkey, keys[num2]) < 0)
                        {
                            num2--;
                        }
                        if (num > num2)
                        {
                            break;
                        }
                        if (num < num2)
                        {
                            TKey tkey2 = keys[num];
                            keys[num]  = keys[num2];
                            keys[num2] = tkey2;
                            if (values != null)
                            {
                                TValue tvalue = values[num];
                                values[num]  = values[num2];
                                values[num2] = tvalue;
                            }
                        }
                        num++;
                        num2--;
                        if (num > num2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        num++;
                    }
                }
                depthLimit--;
                if (num2 - left <= right - num)
                {
                    if (left < num2)
                    {
                        ArraySortHelper <TKey, TValue> .DepthLimitedQuickSort(keys, values, left, num2, comparer, depthLimit);
                    }
                    left = num;
                }
                else
                {
                    if (num < right)
                    {
                        ArraySortHelper <TKey, TValue> .DepthLimitedQuickSort(keys, values, num, right, comparer, depthLimit);
                    }
                    right = num2;
                }
                if (left >= right)
                {
                    return;
                }
            }
            ArraySortHelper <TKey, TValue> .Heapsort(keys, values, left, right, comparer);
        }
Exemple #5
0
        internal static void DepthLimitedQuickSort(TKey[] keys, TValue[] values, int left, int right, IComparer <TKey> comparer, int depthLimit)
        {
            while (depthLimit != 0)
            {
                int index1 = left;
                int index2 = right;
                int index3 = index1 + (index2 - index1 >> 1);
                ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, index1, index3);

                ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, index1, index2);

                ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, index3, index2);

                TKey key1 = keys[index3];
                do
                {
                    while (comparer.Compare(keys[index1], key1) < 0)
                    {
                        ++index1;
                    }
                    while (comparer.Compare(key1, keys[index2]) < 0)
                    {
                        --index2;
                    }
                    if (index1 <= index2)
                    {
                        if (index1 < index2)
                        {
                            TKey key2 = keys[index1];
                            keys[index1] = keys[index2];
                            keys[index2] = key2;
                            if (values != null)
                            {
                                TValue obj = values[index1];
                                values[index1] = values[index2];
                                values[index2] = obj;
                            }
                        }
                        ++index1;
                        --index2;
                    }
                    else
                    {
                        break;
                    }
                }while (index1 <= index2);
                --depthLimit;
                if (index2 - left <= right - index1)
                {
                    if (left < index2)
                    {
                        ArraySortHelper <TKey, TValue> .DepthLimitedQuickSort(keys, values, left, index2, comparer, depthLimit);
                    }
                    left = index1;
                }
                else
                {
                    if (index1 < right)
                    {
                        ArraySortHelper <TKey, TValue> .DepthLimitedQuickSort(keys, values, index1, right, comparer, depthLimit);
                    }
                    right = index2;
                }
                if (left >= right)
                {
                    return;
                }
            }
            ArraySortHelper <TKey, TValue> .Heapsort(keys, values, left, right, comparer);
        }
Exemple #6
0
        // Token: 0x06003A20 RID: 14880 RVA: 0x000DC340 File Offset: 0x000DA540
        internal static void DepthLimitedQuickSort(T[] keys, int left, int right, IComparer <T> comparer, int depthLimit)
        {
            while (depthLimit != 0)
            {
                int num  = left;
                int num2 = right;
                int num3 = num + (num2 - num >> 1);
                ArraySortHelper <T> .SwapIfGreater(keys, comparer, num, num3);

                ArraySortHelper <T> .SwapIfGreater(keys, comparer, num, num2);

                ArraySortHelper <T> .SwapIfGreater(keys, comparer, num3, num2);

                T t = keys[num3];
                for (;;)
                {
                    if (comparer.Compare(keys[num], t) >= 0)
                    {
                        while (comparer.Compare(t, keys[num2]) < 0)
                        {
                            num2--;
                        }
                        if (num > num2)
                        {
                            break;
                        }
                        if (num < num2)
                        {
                            T t2 = keys[num];
                            keys[num]  = keys[num2];
                            keys[num2] = t2;
                        }
                        num++;
                        num2--;
                        if (num > num2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        num++;
                    }
                }
                depthLimit--;
                if (num2 - left <= right - num)
                {
                    if (left < num2)
                    {
                        ArraySortHelper <T> .DepthLimitedQuickSort(keys, left, num2, comparer, depthLimit);
                    }
                    left = num;
                }
                else
                {
                    if (num < right)
                    {
                        ArraySortHelper <T> .DepthLimitedQuickSort(keys, num, right, comparer, depthLimit);
                    }
                    right = num2;
                }
                if (left >= right)
                {
                    return;
                }
            }
            ArraySortHelper <T> .Heapsort(keys, left, right, comparer);
        }
        internal static void DepthLimitedQuickSort(T[] keys, int left, int right, IComparer <T> comparer, int depthLimit)
        {
            while (depthLimit != 0)
            {
                int index1 = left;
                int index2 = right;
                int index3 = index1 + (index2 - index1 >> 1);
                ArraySortHelper <T> .SwapIfGreater(keys, comparer, index1, index3);

                ArraySortHelper <T> .SwapIfGreater(keys, comparer, index1, index2);

                ArraySortHelper <T> .SwapIfGreater(keys, comparer, index3, index2);

                T obj1 = keys[index3];
                do
                {
                    while (comparer.Compare(keys[index1], obj1) < 0)
                    {
                        ++index1;
                    }
                    while (comparer.Compare(obj1, keys[index2]) < 0)
                    {
                        --index2;
                    }
                    if (index1 <= index2)
                    {
                        if (index1 < index2)
                        {
                            T obj2 = keys[index1];
                            keys[index1] = keys[index2];
                            keys[index2] = obj2;
                        }
                        ++index1;
                        --index2;
                    }
                    else
                    {
                        break;
                    }
                }while (index1 <= index2);
                --depthLimit;
                if (index2 - left <= right - index1)
                {
                    if (left < index2)
                    {
                        ArraySortHelper <T> .DepthLimitedQuickSort(keys, left, index2, comparer, depthLimit);
                    }
                    left = index1;
                }
                else
                {
                    if (index1 < right)
                    {
                        ArraySortHelper <T> .DepthLimitedQuickSort(keys, index1, right, comparer, depthLimit);
                    }
                    right = index2;
                }
                if (left >= right)
                {
                    return;
                }
            }
            ArraySortHelper <T> .Heapsort(keys, left, right, comparer);
        }