private static int PickPivotAndPartition(T[] keys, int lo, int hi) { int index = lo + (hi - lo) / 2; GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, index); GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, hi); GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, index, hi); T obj = keys[index]; GenericArraySortHelper <T> .Swap(keys, index, hi - 1); int i = lo; int j = hi - 1; while (i < j) { if ((object)obj == null) { do { ; }while (i < hi - 1 && (object)keys[++i] == null); while (j > lo && (object)keys[--j] != null) { ; } } else { do { ; }while (obj.CompareTo(keys[++i]) > 0); while (obj.CompareTo(keys[--j]) < 0) { ; } } if (i < j) { GenericArraySortHelper <T> .Swap(keys, i, j); } else { break; } } GenericArraySortHelper <T> .Swap(keys, i, hi - 1); return(i); }
// Token: 0x06003A30 RID: 14896 RVA: 0x000DCA48 File Offset: 0x000DAC48 private static int PickPivotAndPartition(T[] keys, int lo, int hi) { int num = lo + (hi - lo) / 2; GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, num); GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, hi); GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, num, hi); T t = keys[num]; GenericArraySortHelper <T> .Swap(keys, num, hi - 1); int i = lo; int j = hi - 1; while (i < j) { if (t == null) { while (i < hi - 1 && keys[++i] == null) { } while (j > lo) { if (keys[--j] == null) { break; } } } else { while (t.CompareTo(keys[++i]) > 0) { } while (t.CompareTo(keys[--j]) < 0) { } } if (i >= j) { break; } GenericArraySortHelper <T> .Swap(keys, i, j); } GenericArraySortHelper <T> .Swap(keys, i, hi - 1); return(i); }
// 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; } } }
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); } }
private static void QuickSort(TKey[] keys, TValue[] values, int left, int right) { int num; Label_0000: num = left; int b = right; int num3 = num + ((b - num) >> 1); GenericArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, num, num3); GenericArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, num, b); GenericArraySortHelper <TKey, TValue> .SwapIfGreaterWithItems(keys, values, num3, b); TKey local = keys[num3]; Label_002F: if (local != null) { while (local.CompareTo(keys[num]) > 0) { num++; } while (local.CompareTo(keys[b]) < 0) { b--; } } else { while (keys[b] != null) { b--; } } if (num <= b) { if (num < b) { TKey local2 = keys[num]; keys[num] = keys[b]; keys[b] = local2; if (values != null) { TValue local3 = values[num]; values[num] = values[b]; values[b] = local3; } } num++; b--; if (num <= b) { goto Label_002F; } } if ((b - left) <= (right - num)) { if (left < b) { GenericArraySortHelper <TKey, TValue> .QuickSort(keys, values, left, b); } left = num; } else { if (num < right) { GenericArraySortHelper <TKey, TValue> .QuickSort(keys, values, num, right); } right = b; } if (left >= right) { return; } goto Label_0000; }
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); }
// 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); }