Пример #1
0
        public virtual void TestSortIterator()
        {
            Random         random     = Random;
            BytesRefArray  list       = new BytesRefArray(Util.Counter.NewCounter());
            IList <string> stringList = new JCG.List <string>();

            for (int j = 0; j < 2; j++)
            {
                if (j > 0 && random.NextBoolean())
                {
                    list.Clear();
                    stringList.Clear();
                }
                int      entries  = AtLeast(500);
                BytesRef spare    = new BytesRef();
                int      initSize = list.Length;
                for (int i = 0; i < entries; i++)
                {
                    string randomRealisticUnicodeString = TestUtil.RandomRealisticUnicodeString(random);
                    spare.CopyChars(randomRealisticUnicodeString);
                    Assert.AreEqual(initSize + i, list.Append(spare));
                    stringList.Add(randomRealisticUnicodeString);
                }

                // LUCENENET NOTE: Must sort using ArrayUtil.GetNaturalComparator<T>()
                // to ensure culture isn't taken into consideration during the sort,
                // which will match the sort order of BytesRef.UTF8SortedAsUTF16Comparer.
                CollectionUtil.TimSort(stringList);
#pragma warning disable 612, 618
                IBytesRefIterator iter = list.GetIterator(BytesRef.UTF8SortedAsUTF16Comparer);
#pragma warning restore 612, 618
                int a = 0;
                while ((spare = iter.Next()) != null)
                {
                    Assert.AreEqual(stringList[a], spare.Utf8ToString(), "entry " + a + " doesn't match");
                    a++;
                }
                Assert.IsNull(iter.Next());
                Assert.AreEqual(a, stringList.Count);
            }
        }
Пример #2
0
 /// <summary>
 /// Sorts the given <see cref="IList{T}"/> using the <see cref="IComparer{T}"/>.
 /// This method uses the Tim sort
 /// algorithm, but falls back to binary 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 TimSort <T>(this IList <T> list, IComparer <T> comparer)
 {
     CollectionUtil.TimSort(list, comparer);
 }
Пример #3
0
 /// <summary>
 /// Sorts the given <see cref="IList{T}"/> using the <see cref="IComparer{T}"/>.
 /// This method uses the Tim sort
 /// algorithm, but falls back to binary sort for small lists.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="list">this <see cref="IList{T}"/></param>
 public static void TimSort <T>(this IList <T> list)
 {
     CollectionUtil.TimSort(list);
 }