Пример #1
0
        public virtual void TestIntroSort()
        {
            // LUCENENET: Use array for comparison rather than list for better performance
            for (int i = 0, c = AtLeast(500); i < c; i++)
            {
                IList <int> list1 = CreateRandomList(2000);
                int[]       list2 = new int[list1.Count];
                list1.CopyTo(list2, 0);
                CollectionUtil.IntroSort(list1);
                Array.Sort(list2);
                assertEquals(list2, list1, aggressive: false);

                list1 = CreateRandomList(2000);
                list2 = new int[list1.Count];
                list1.CopyTo(list2, 0);

                CollectionUtil.IntroSort(list1, Collections.ReverseOrder <int>());
                Array.Sort(list2, Collections.ReverseOrder <int>());
                assertEquals(list2, list1, aggressive: false);
                // reverse back, so we can test that completely backwards sorted array (worst case) is working:
                CollectionUtil.IntroSort(list1);
                Array.Sort(list2);
                assertEquals(list2, list1, aggressive: false);
            }
        }
Пример #2
0
        public virtual void TestOneElementListSort()
        {
            // check that one-element non-random access lists pass sorting without ex (as sorting is not needed)
            IList <int> list = new JCG.List <int>();

            list.Add(1);
            CollectionUtil.IntroSort(list);
            CollectionUtil.TimSort(list);
            CollectionUtil.IntroSort(list, Collections.ReverseOrder <int>());
            CollectionUtil.TimSort(list, Collections.ReverseOrder <int>());
        }
Пример #3
0
        public virtual void TestEmptyListSort()
        {
            // should produce no exceptions
            IList <int> list = new int[0]; // LUCENE-2989

            CollectionUtil.IntroSort(list);
            CollectionUtil.TimSort(list);
            CollectionUtil.IntroSort(list, Collections.ReverseOrder <int>());
            CollectionUtil.TimSort(list, Collections.ReverseOrder <int>());

            // check that empty non-random access lists pass sorting without ex (as sorting is not needed)
            list = new JCG.List <int>();
            CollectionUtil.IntroSort(list);
            CollectionUtil.TimSort(list);
            CollectionUtil.IntroSort(list, Collections.ReverseOrder <int>());
            CollectionUtil.TimSort(list, Collections.ReverseOrder <int>());
        }
Пример #4
0
        public virtual void TestIntroSort()
        {
            for (int i = 0, c = AtLeast(500); i < c; i++)
            {
                List <int> list1 = CreateRandomList(2000), list2 = new List <int>(list1);
                CollectionUtil.IntroSort(list1);
                list2.Sort();
                Assert.AreEqual(list2, list1);

                list1 = CreateRandomList(2000);
                list2 = new List <int>(list1);
                CollectionUtil.IntroSort(list1, Collections.ReverseOrder <int>());
                list2.Sort(Collections.ReverseOrder <int>());
                Assert.AreEqual(list2, list1);
                // reverse back, so we can test that completely backwards sorted array (worst case) is working:
                CollectionUtil.IntroSort(list1);
                list2.Sort();
                Assert.AreEqual(list2, list1);
            }
        }
Пример #5
0
 /// <summary>
 /// Sorts the given <see cref="IList{T}"/> using the <see cref="IComparer{T}"/>.
 /// This method uses the intro sort
 /// algorithm, but falls back to insertion sort for small lists.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="list">this <see cref="IList{T}"/></param>
 /// <param name="comparer">The <see cref="IComparer{T}"/> to use for the sort.</param>
 public static void IntroSort <T>(this IList <T> list, IComparer <T> comparer)
 {
     CollectionUtil.IntroSort(list, comparer);
 }
Пример #6
0
 /// <summary>
 /// Sorts the given <see cref="IList{T}"/> using the <see cref="IComparer{T}"/>.
 /// This method uses the intro sort
 /// algorithm, but falls back to insertion sort for small lists.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="list">this <see cref="IList{T}"/></param>
 public static void IntroSort <T>(this IList <T> list)
 {
     CollectionUtil.IntroSort(list);
 }