Exemplo n.º 1
0
        // Token: 0x06003A3E RID: 14910 RVA: 0x000DD064 File Offset: 0x000DB264
        private static int PickPivotAndPartition(TKey[] keys, TValue[] values, int lo, int hi, IComparer <TKey> comparer)
        {
            int num = lo + (hi - lo) / 2;

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

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

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

            TKey tkey = keys[num];

            ArraySortHelper <TKey, TValue> .Swap(keys, values, num, hi - 1);

            int i    = lo;
            int num2 = hi - 1;

            while (i < num2)
            {
                while (comparer.Compare(keys[++i], tkey) < 0)
                {
                }
                while (comparer.Compare(tkey, keys[--num2]) < 0)
                {
                }
                if (i >= num2)
                {
                    break;
                }
                ArraySortHelper <TKey, TValue> .Swap(keys, values, i, num2);
            }
            ArraySortHelper <TKey, TValue> .Swap(keys, values, i, hi - 1);

            return(i);
        }
Exemplo n.º 2
0
        internal static void QuickSort(T[] keys, int left, int right, IComparer <T> comparer)
        {
            do
            {
                int a    = left;
                int b    = right;
                int num3 = a + ((b - a) >> 1);
                ArraySortHelper <T> .SwapIfGreaterWithItems(keys, comparer, a, num3);

                ArraySortHelper <T> .SwapIfGreaterWithItems(keys, comparer, a, b);

                ArraySortHelper <T> .SwapIfGreaterWithItems(keys, comparer, num3, b);

                T y = keys[num3];
                do
                {
                    while (comparer.Compare(keys[a], y) < 0)
                    {
                        a++;
                    }
                    while (comparer.Compare(y, keys[b]) < 0)
                    {
                        b--;
                    }
                    if (a > b)
                    {
                        break;
                    }
                    if (a < b)
                    {
                        T local2 = keys[a];
                        keys[a] = keys[b];
                        keys[b] = local2;
                    }
                    a++;
                    b--;
                }while (a <= b);
                if ((b - left) <= (right - a))
                {
                    if (left < b)
                    {
                        ArraySortHelper <T> .QuickSort(keys, left, b, comparer);
                    }
                    left = a;
                }
                else
                {
                    if (a < right)
                    {
                        ArraySortHelper <T> .QuickSort(keys, a, right, comparer);
                    }
                    right = b;
                }
            }while (left < right);
        }
Exemplo n.º 3
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.º 4
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);
            }
        }
Exemplo n.º 5
0
        private static int PickPivotAndPartition(TKey[] keys, TValue[] values, int lo, int hi, IComparer <TKey> comparer)
        {
            int index = lo + (hi - lo) / 2;

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

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

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

            TKey key = keys[index];

            ArraySortHelper <TKey, TValue> .Swap(keys, values, index, hi - 1);

            int i = lo;
            int j = hi - 1;

            while (i < j)
            {
                do
                {
                    ;
                }while (comparer.Compare(keys[++i], key) < 0);
                do
                {
                    ;
                }while (comparer.Compare(key, keys[--j]) < 0);
                if (i < j)
                {
                    ArraySortHelper <TKey, TValue> .Swap(keys, values, i, j);
                }
                else
                {
                    break;
                }
            }
            ArraySortHelper <TKey, TValue> .Swap(keys, values, i, hi - 1);

            return(i);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }