Beispiel #1
0
 /// <summary>
 /// Sorts the given array slice in natural order. This method uses the intro sort
 /// algorithm, but falls back to insertion sort for small arrays. </summary>
 /// <param name="fromIndex"> Start index (inclusive) </param>
 /// <param name="toIndex"> End index (exclusive) </param>
 public static void IntroSort <T>(T[] a, int fromIndex, int toIndex) //where T : IComparable<T> // LUCENENET specific: removing constraint because in .NET, it is not needed
 {
     if (toIndex - fromIndex <= 1)
     {
         return;
     }
     IntroSort(a, fromIndex, toIndex, ArrayUtil.GetNaturalComparer <T>());
 }
Beispiel #2
0
        /// <summary>
        /// Sorts the given <see cref="IList{T}"/> in natural order.
        /// This method uses the Tim sort
        /// algorithm, but falls back to binary sort for small lists. </summary>
        /// <param name="list">This <see cref="IList{T}"/></param>
        public static void TimSort <T>(IList <T> list)
        //where T : IComparable<T> // LUCENENET specific: removing constraint because in .NET, it is not needed
        {
            int size = list.Count;

            if (size <= 1)
            {
                return;
            }
            TimSort(list, ArrayUtil.GetNaturalComparer <T>());
        }
Beispiel #3
0
 public override Sorter NewSorter(Entry[] arr)
 {
     return(new ArrayIntroSorter <Entry>(arr, ArrayUtil.GetNaturalComparer <Entry>()));
 }
Beispiel #4
0
 public override Sorter NewSorter(Entry[] arr)
 {
     return(new ArrayTimSorter <Entry>(arr, ArrayUtil.GetNaturalComparer <Entry>(), TestUtil.NextInt32(Random, 0, arr.Length)));
 }