public void Sort(T[] keys, int index, int length, IComparer <T> comparer) { try { if (comparer == null || comparer == Comparer <T> .Default) { if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5) { GenericArraySortHelper <T> .IntrospectiveSort(keys, index, length); } else { GenericArraySortHelper <T> .DepthLimitedQuickSort(keys, index, length + index - 1, 32); } } else if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5) { ArraySortHelper <T> .IntrospectiveSort(keys, index, length, comparer); } else { ArraySortHelper <T> .DepthLimitedQuickSort(keys, index, length + index - 1, comparer, 32); } } catch (IndexOutOfRangeException ex) { IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer((object)comparer); } catch (Exception ex) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), ex); } }
// 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); }
public void Sort(T[] keys, int index, int length, IComparer <T> comparer) { try { if ((comparer == null) || (comparer == Comparer <T> .Default)) { GenericArraySortHelper <T> .QuickSort(keys, index, index + (length - 1)); } else { ArraySortHelper <T> .QuickSort(keys, index, index + (length - 1), comparer); } } catch (IndexOutOfRangeException) { object[] values = new object[3]; values[0] = default(T); values[1] = typeof(T).Name; throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", values)); } catch (Exception exception) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), exception); } }
// Token: 0x06003A23 RID: 14883 RVA: 0x000DC4E4 File Offset: 0x000DA6E4 private static int PickPivotAndPartition(T[] keys, int lo, int hi, IComparer <T> comparer) { int num = lo + (hi - lo) / 2; ArraySortHelper <T> .SwapIfGreater(keys, comparer, lo, num); ArraySortHelper <T> .SwapIfGreater(keys, comparer, lo, hi); ArraySortHelper <T> .SwapIfGreater(keys, comparer, num, hi); T t = keys[num]; ArraySortHelper <T> .Swap(keys, num, hi - 1); int i = lo; int num2 = hi - 1; while (i < num2) { while (comparer.Compare(keys[++i], t) < 0) { } while (comparer.Compare(t, keys[--num2]) < 0) { } if (i >= num2) { break; } ArraySortHelper <T> .Swap(keys, i, num2); } ArraySortHelper <T> .Swap(keys, i, hi - 1); return(i); }
// Token: 0x06003A38 RID: 14904 RVA: 0x000DCD3C File Offset: 0x000DAF3C public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer <TKey> comparer) { try { if (comparer == null || comparer == Comparer <TKey> .Default) { comparer = Comparer <TKey> .Default; } if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5) { ArraySortHelper <TKey, TValue> .IntrospectiveSort(keys, values, index, length, comparer); } else { ArraySortHelper <TKey, TValue> .DepthLimitedQuickSort(keys, values, index, length + index - 1, comparer, 32); } } catch (IndexOutOfRangeException) { IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer); } catch (Exception innerException) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException); } }
// Do not add a constructor to this class because ArraySortHelper<T>.CreateSortHelper will not execute it #region IArraySortHelper<T> Members public void Sort(T[] keys, int index, int length, IComparer <T> comparer) { Debug.Assert(keys != null, "Check the arguments in the caller!"); Debug.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!"); try { if (comparer == null || comparer == Comparer <T> .Default) { IntrospectiveSort(keys, index, length); } else { ArraySortHelper <T> .IntrospectiveSort(keys, index, length, comparer.Compare); } } catch (IndexOutOfRangeException) { IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer); } catch (Exception e) { throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e); } }
public int BinarySearch(T[] array, int index, int length, T value, IComparer <T> comparer) { Debug.Assert(array != null, "Check the arguments in the caller!"); Debug.Assert(index >= 0 && length >= 0 && (array.Length - index >= length), "Check the arguments in the caller!"); try { if (comparer == null || comparer == Comparer <T> .Default) { return(BinarySearch(array, index, length, value)); } else { return(ArraySortHelper <T> .InternalBinarySearch(array, index, length, value, comparer)); } } catch (ThreadAbortException) { throw; } catch (Exception e) { throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e); } }
// Token: 0x06003A3C RID: 14908 RVA: 0x000DCF9B File Offset: 0x000DB19B internal static void IntrospectiveSort(TKey[] keys, TValue[] values, int left, int length, IComparer <TKey> comparer) { if (length < 2) { return; } ArraySortHelper <TKey, TValue> .IntroSort(keys, values, left, length + left - 1, 2 *IntrospectiveSortUtilities.FloorLog2(keys.Length), comparer); }
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); }
private static ArraySortHelper <T> CreateArraySortHelper() { if (typeof(IComparable <T>).IsAssignableFrom(typeof(T))) { defaultArraySortHelper = (ArraySortHelper <T>)(typeof(GenericArraySortHelper <string>).TypeHandle.CreateInstanceForAnotherGenericParameter(typeof(T))); } else { defaultArraySortHelper = new ArraySortHelper <T>(); } return(defaultArraySortHelper); }
public void Sort(Comparison <T> comparison) { if (comparison == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } if (this._size <= 0) { return; } ArraySortHelper <T> .Sort(this._items, 0, this._size, comparison); }
public void Sort(Comparison <T> comparison) { if (comparison == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison); } if (this._size > 1) { ArraySortHelper <T> .Sort(this._items, 0, this._size, comparison); } ++this._version; }
public void Sort(Comparison <T> comparison) { if (comparison == null) { throw new ArgumentNullException(nameof(comparison)); } Contract.EndContractBlock(); if (_size > 0) { ArraySortHelper <T> .Sort(_items, 0, _size, comparison); } }
private static IArraySortHelper <T> CreateArraySortHelper() { IArraySortHelper <T> defaultArraySortHelper; if (RuntimeTypeHelpers.IsAssignableFrom <T, IComparable <T> >()) { defaultArraySortHelper = RuntimeTypeHelpers.AllocateLike <GenericArraySortHelper <string>, IArraySortHelper <T>, T>(); } else { defaultArraySortHelper = new ArraySortHelper <T>(); } return(defaultArraySortHelper); }
public void Sort(Comparison <T> comparison) { if (comparison == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison); } Contract.EndContractBlock(); if (_size > 1) { ArraySortHelper <T> .Sort(_items, 0, _size, comparison); } _version++; }
private static IArraySortHelper <T> CreateArraySortHelper() { IArraySortHelper <T> defaultArraySortHelper; if (typeof(IComparable <T>).IsAssignableFrom(typeof(T))) { defaultArraySortHelper = (IArraySortHelper <T>)RuntimeTypeHandle.Allocate(typeof(GenericArraySortHelper <string>).TypeHandle.Instantiate(new Type[] { typeof(T) })); } else { defaultArraySortHelper = new ArraySortHelper <T>(); } return(defaultArraySortHelper); }
private static IArraySortHelper <T> CreateArraySortHelper() { IArraySortHelper <T> defaultArraySortHelper; if (typeof(IComparable <T>).IsAssignableFrom(typeof(T))) { defaultArraySortHelper = (IArraySortHelper <T>)RuntimeType.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericArraySortHelper <>), (RuntimeType)typeof(T)); } else { defaultArraySortHelper = new ArraySortHelper <T>(); } return(defaultArraySortHelper); }
// Token: 0x06003A3F RID: 14911 RVA: 0x000DD100 File Offset: 0x000DB300 private static void Heapsort(TKey[] keys, TValue[] values, int lo, int hi, IComparer <TKey> comparer) { int num = hi - lo + 1; for (int i = num / 2; i >= 1; i--) { ArraySortHelper <TKey, TValue> .DownHeap(keys, values, i, num, lo, comparer); } for (int j = num; j > 1; j--) { ArraySortHelper <TKey, TValue> .Swap(keys, values, lo, lo + j - 1); ArraySortHelper <TKey, TValue> .DownHeap(keys, values, 1, j - 1, lo, comparer); } }
public int BinarySearch(T[] array, int index, int length, T value, IComparer <T> comparer) { try { if (comparer == null || comparer == Comparer <T> .Default) { return(GenericArraySortHelper <T> .BinarySearch(array, index, length, value)); } return(ArraySortHelper <T> .InternalBinarySearch(array, index, length, value, comparer)); } catch (Exception ex) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), ex); } }
// 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; } } }
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); } }
// Token: 0x06003A1C RID: 14876 RVA: 0x000DC234 File Offset: 0x000DA434 public int BinarySearch(T[] array, int index, int length, T value, IComparer <T> comparer) { int result; try { if (comparer == null) { comparer = Comparer <T> .Default; } result = ArraySortHelper <T> .InternalBinarySearch(array, index, length, value, comparer); } catch (Exception innerException) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException); } return(result); }
public void Sort(Comparison <T> comparison) { if (comparison == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } Contract.EndContractBlock(); if (_size > 0) { #if MONO ArraySortHelper <T> .Sort(_items, 0, _size, comparison); #else IComparer <T> comparer = new Array.FunctorComparer <T>(comparison); Array.Sort(_items, 0, _size, comparer); #endif } }
public int BinarySearch(T[] array, int index, int length, T value, IComparer <T> comparer) { try { if (comparer == null || comparer == Comparer <T> .Default) { return(BinarySearch(array, index, length, value)); } else { return(ArraySortHelper <T> .InternalBinarySearch(array, index, length, value, comparer)); } } catch (Exception e) { throw new InvalidOperationException("InvalidOperation_IComparerFailed"); } }
private static void Heapsort(T[] keys, int lo, int hi, IComparer <T> comparer) { int n = hi - lo + 1; for (int i = n / 2; i >= 1; --i) { ArraySortHelper <T> .DownHeap(keys, i, n, lo, comparer); } for (int index = n; index > 1; --index) { T[] a = keys; int i = lo; int num = index; int j = i + num - 1; ArraySortHelper <T> .Swap(a, i, j); ArraySortHelper <T> .DownHeap(keys, 1, index - 1, lo, comparer); } }
private static void Heapsort(TKey[] keys, TValue[] values, int lo, int hi, IComparer <TKey> comparer) { int n = hi - lo + 1; for (int i = n / 2; i >= 1; --i) { ArraySortHelper <TKey, TValue> .DownHeap(keys, values, i, n, lo, comparer); } for (int index = n; index > 1; --index) { TKey[] keys1 = keys; TValue[] values1 = values; int i = lo; int num = index; int j = i + num - 1; ArraySortHelper <TKey, TValue> .Swap(keys1, values1, i, j); ArraySortHelper <TKey, TValue> .DownHeap(keys, values, 1, index - 1, lo, comparer); } }
public int BinarySearch(T[] array, int index, int length, T value, IComparer <T> comparer) { Contract.Assert(array != null, "Check the arguments in the caller!"); Contract.Assert(index >= 0 && length >= 0 && (array.Length - index >= length), "Check the arguments in the caller!"); try { if (comparer == null || comparer == Comparer <T> .Default) { return(BinarySearch(array, index, length, value)); } else { return(ArraySortHelper <T> .InternalBinarySearch(array, index, length, value, comparer)); } } catch (Exception e) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e); } }
// Do not add a constructor to this class because ArraySortHelper<T>.CreateSortHelper will not execute it #region IArraySortHelper<T> Members public void Sort(T[] keys, int index, int length, IComparer <T> comparer) { try { if (comparer == null || comparer == Comparer <T> .Default) { DepthLimitedQuickSort(keys, index, length + index - 1, IntrospectiveSortUtilities.QuickSortDepthThreshold); } else { ArraySortHelper <T> .DepthLimitedQuickSort(keys, index, length + index - 1, comparer, IntrospectiveSortUtilities.QuickSortDepthThreshold); } } catch (IndexOutOfRangeException) { } catch (Exception e) { throw new InvalidOperationException("IComparerFailed"); } }
private static int PickPivotAndPartition(T[] keys, int lo, int hi, IComparer <T> comparer) { int index = lo + (hi - lo) / 2; ArraySortHelper <T> .SwapIfGreater(keys, comparer, lo, index); ArraySortHelper <T> .SwapIfGreater(keys, comparer, lo, hi); ArraySortHelper <T> .SwapIfGreater(keys, comparer, index, hi); T obj = keys[index]; ArraySortHelper <T> .Swap(keys, index, hi - 1); int i = lo; int j = hi - 1; while (i < j) { do { ; }while (comparer.Compare(keys[++i], obj) < 0); do { ; }while (comparer.Compare(obj, keys[--j]) < 0); if (i < j) { ArraySortHelper <T> .Swap(keys, i, j); } else { break; } } ArraySortHelper <T> .Swap(keys, i, hi - 1); return(i); }
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); }