示例#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>());
 }
示例#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>());
        }