コード例 #1
0
        // Token: 0x06003A2F RID: 14895 RVA: 0x000DC9C4 File Offset: 0x000DABC4
        private static void IntroSort(T[] keys, int lo, int hi, int depthLimit)
        {
            while (hi > lo)
            {
                int num = hi - lo + 1;
                if (num <= 16)
                {
                    if (num == 1)
                    {
                        return;
                    }
                    if (num == 2)
                    {
                        GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, hi);

                        return;
                    }
                    if (num == 3)
                    {
                        GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, hi - 1);

                        GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, hi);

                        GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, hi - 1, hi);

                        return;
                    }
                    GenericArraySortHelper <T> .InsertionSort(keys, lo, hi);

                    return;
                }
                else
                {
                    if (depthLimit == 0)
                    {
                        GenericArraySortHelper <T> .Heapsort(keys, lo, hi);

                        return;
                    }
                    depthLimit--;
                    int num2 = GenericArraySortHelper <T> .PickPivotAndPartition(keys, lo, hi);

                    GenericArraySortHelper <T> .IntroSort(keys, num2 + 1, hi, depthLimit);

                    hi = num2 - 1;
                }
            }
        }
コード例 #2
0
        private static void IntroSort(T[] keys, int lo, int hi, int depthLimit)
        {
            int num1;

            for (; hi > lo; hi = num1 - 1)
            {
                int num2 = hi - lo + 1;
                if (num2 <= 16)
                {
                    if (num2 == 1)
                    {
                        break;
                    }
                    if (num2 == 2)
                    {
                        GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, hi);

                        break;
                    }
                    if (num2 == 3)
                    {
                        GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, hi - 1);

                        GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, hi);

                        GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, hi - 1, hi);

                        break;
                    }
                    GenericArraySortHelper <T> .InsertionSort(keys, lo, hi);

                    break;
                }
                if (depthLimit == 0)
                {
                    GenericArraySortHelper <T> .Heapsort(keys, lo, hi);

                    break;
                }
                --depthLimit;
                num1 = GenericArraySortHelper <T> .PickPivotAndPartition(keys, lo, hi);

                GenericArraySortHelper <T> .IntroSort(keys, num1 + 1, hi, depthLimit);
            }
        }
コード例 #3
0
        private static void DepthLimitedQuickSort(T[] keys, int left, int right, int depthLimit)
        {
            while (depthLimit != 0)
            {
                int index1 = left;
                int index2 = right;
                int index3 = index1 + (index2 - index1 >> 1);
                GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, index1, index3);

                GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, index1, index2);

                GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, index3, index2);

                T obj1 = keys[index3];
                do
                {
                    if ((object)obj1 == null)
                    {
                        while ((object)keys[index2] != null)
                        {
                            --index2;
                        }
                    }
                    else
                    {
                        while (obj1.CompareTo(keys[index1]) > 0)
                        {
                            ++index1;
                        }
                        while (obj1.CompareTo(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)
                    {
                        GenericArraySortHelper <T> .DepthLimitedQuickSort(keys, left, index2, depthLimit);
                    }
                    left = index1;
                }
                else
                {
                    if (index1 < right)
                    {
                        GenericArraySortHelper <T> .DepthLimitedQuickSort(keys, index1, right, depthLimit);
                    }
                    right = index2;
                }
                if (left >= right)
                {
                    return;
                }
            }
            GenericArraySortHelper <T> .Heapsort(keys, left, right);
        }
コード例 #4
0
        // Token: 0x06003A2D RID: 14893 RVA: 0x000DC89C File Offset: 0x000DAA9C
        private static void DepthLimitedQuickSort(T[] keys, int left, int right, int depthLimit)
        {
            while (depthLimit != 0)
            {
                int num  = left;
                int num2 = right;
                int num3 = num + (num2 - num >> 1);
                GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, num, num3);

                GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, num, num2);

                GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, num3, num2);

                T t = keys[num3];
                do
                {
                    if (t == null)
                    {
                        while (keys[num2] != null)
                        {
                            num2--;
                        }
                    }
                    else
                    {
                        while (t.CompareTo(keys[num]) > 0)
                        {
                            num++;
                        }
                        while (t.CompareTo(keys[num2]) < 0)
                        {
                            num2--;
                        }
                    }
                    if (num > num2)
                    {
                        break;
                    }
                    if (num < num2)
                    {
                        T t2 = keys[num];
                        keys[num]  = keys[num2];
                        keys[num2] = t2;
                    }
                    num++;
                    num2--;
                }while (num <= num2);
                depthLimit--;
                if (num2 - left <= right - num)
                {
                    if (left < num2)
                    {
                        GenericArraySortHelper <T> .DepthLimitedQuickSort(keys, left, num2, depthLimit);
                    }
                    left = num;
                }
                else
                {
                    if (num < right)
                    {
                        GenericArraySortHelper <T> .DepthLimitedQuickSort(keys, num, right, depthLimit);
                    }
                    right = num2;
                }
                if (left >= right)
                {
                    return;
                }
            }
            GenericArraySortHelper <T> .Heapsort(keys, left, right);
        }