Пример #1
0
        // Token: 0x06003A3D RID: 14909 RVA: 0x000DCFBC File Offset: 0x000DB1BC
        private static void IntroSort(TKey[] keys, TValue[] values, int lo, int hi, int depthLimit, IComparer <TKey> comparer)
        {
            while (hi > lo)
            {
                int num = hi - lo + 1;
                if (num <= 16)
                {
                    if (num == 1)
                    {
                        return;
                    }
                    if (num == 2)
                    {
                        ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, lo, hi);

                        return;
                    }
                    if (num == 3)
                    {
                        ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, lo, hi - 1);

                        ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, lo, hi);

                        ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, hi - 1, hi);

                        return;
                    }
                    ArraySortHelper <TKey, TValue> .InsertionSort(keys, values, lo, hi, comparer);

                    return;
                }
                else
                {
                    if (depthLimit == 0)
                    {
                        ArraySortHelper <TKey, TValue> .Heapsort(keys, values, lo, hi, comparer);

                        return;
                    }
                    depthLimit--;
                    int num2 = ArraySortHelper <TKey, TValue> .PickPivotAndPartition(keys, values, lo, hi, comparer);

                    ArraySortHelper <TKey, TValue> .IntroSort(keys, values, num2 + 1, hi, depthLimit, comparer);

                    hi = num2 - 1;
                }
            }
        }
Пример #2
0
        private static void IntroSort(TKey[] keys, TValue[] values, int lo, int hi, int depthLimit, IComparer <TKey> comparer)
        {
            int num1;

            for (; hi > lo; hi = num1 - 1)
            {
                int num2 = hi - lo + 1;
                if (num2 <= 16)
                {
                    if (num2 == 1)
                    {
                        break;
                    }
                    if (num2 == 2)
                    {
                        ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, lo, hi);

                        break;
                    }
                    if (num2 == 3)
                    {
                        ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, lo, hi - 1);

                        ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, lo, hi);

                        ArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, comparer, hi - 1, hi);

                        break;
                    }
                    ArraySortHelper <TKey, TValue> .InsertionSort(keys, values, lo, hi, comparer);

                    break;
                }
                if (depthLimit == 0)
                {
                    ArraySortHelper <TKey, TValue> .Heapsort(keys, values, lo, hi, comparer);

                    break;
                }
                --depthLimit;
                num1 = ArraySortHelper <TKey, TValue> .PickPivotAndPartition(keys, values, lo, hi, comparer);

                ArraySortHelper <TKey, TValue> .IntroSort(keys, values, num1 + 1, hi, depthLimit, comparer);
            }
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
0
        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);
        }