/// <summary> /// Sorts the given array slice in natural order. this method uses the Tim sort /// algorithm, but falls back to binary sort for small arrays. </summary> /// <param name="fromIndex"> start index (inclusive) </param> /// <param name="toIndex"> end index (exclusive) </param> public static void TimSort <T>(T[] a, int fromIndex, int toIndex) where T : IComparable <T> { if (toIndex - fromIndex <= 1) { return; } TimSort(a, fromIndex, toIndex, ArrayUtil.naturalComparator <T>()); }
/// <summary> /// Sorts the given random access <seealso cref="List"/> in natural order. /// The list must implement <seealso cref="RandomAccess"/>. this method uses the Tim sort /// algorithm, but falls back to binary sort for small lists. </summary> /// <exception cref="IllegalArgumentException"> if list is e.g. a linked list without random access. </exception> public static void TimSort <T>(IList <T> list) where T : IComparable <T> { int size = list.Count; if (size <= 1) { return; } TimSort(list, ArrayUtil.naturalComparator <T>()); }
public override Sorter NewSorter(Entry[] arr) { return(new ArrayIntroSorter <Entry>(arr, ArrayUtil.naturalComparator <Entry>())); }
public override Sorter NewSorter(Entry[] arr) { return(new ArrayTimSorter <Entry>(arr, ArrayUtil.naturalComparator <Entry>(), TestUtil.NextInt(Random(), 0, arr.Length))); }