Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 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);
            }
        }