예제 #1
0
        public void SortContents(int sortColumn, bool sortAscending)
        {
            try {
                int num = fContentList.Count;
                for (int i = 0; i < num; i++)
                {
                    ValItem      valItem = fContentList[i];
                    GEDCOMRecord rec     = valItem.Record;

                    if (sortColumn == 0)
                    {
                        valItem.ColumnValue = rec.GetId();
                    }
                    else
                    {
                        Fetch(rec);
                        valItem.ColumnValue = GetColumnInternalValue(sortColumn);
                    }
                }

                fXSortFactor = (sortAscending ? 1 : -1);
                ListTimSort <ValItem> .Sort(fContentList, CompareItems);
            } catch (Exception ex) {
                Logger.LogWrite("ListManager.SortContents(): " + ex.Message);
            }
        }
예제 #2
0
 public void Sort(Comparison <T> comparer)
 {
     if (fDataList != null)
     {
         ListTimSort <T> .Sort(fDataList, comparer);
     }
 }
예제 #3
0
        public void Sort(Comparison <T> comparer)
        {
            if (fDataList == null)
            {
                return;
            }

            ListTimSort <T> .Sort(fDataList, comparer);
        }
예제 #4
0
 /// <summary>Sorts the specified array.</summary>
 /// <typeparam name="T">Type of item.</typeparam>
 /// <param name="array">The array.</param>
 /// <param name="comparer">The comparer.</param>
 public static void TimSort <T>(this IList <T> array, Comparer <T> comparer, bool buffered)
 {
     if (buffered)
     {
         BufferedListSort(array, 0, array.Count, comparer.Compare);
     }
     else
     {
         ListTimSort <T> .Sort(array, comparer.Compare);
     }
 }
예제 #5
0
        /// <summary>Sorts the specified array.</summary>
        /// <typeparam name="T">Type of item.</typeparam>
        /// <typeparam name="C">Type of compared expression</typeparam>
        /// <param name="array">The array.</param>
        /// <param name="expression">The compared expression.</param>
        /// <param name="buffered">Set it to <c>true</c> if you need buffered sorting.</param>
        public static void TimSort <T, C>(this IList <T> array, Func <T, C> expression, bool buffered)
        {
            Comparison <T> comparer = (a, b) => Comparer <C> .Default.Compare(expression(a), expression(b));

            if (buffered)
            {
                BufferedListSort(array, 0, array.Count, comparer);
            }
            else
            {
                ListTimSort <T> .Sort(array, comparer);
            }
        }
예제 #6
0
        /// <summary>Sorts the specified array.</summary>
        /// <typeparam name="T">Type of item.</typeparam>
        /// <param name="array">The array.</param>
        /// <param name="start">The start.</param>
        /// <param name="length">The length.</param>
        /// <param name="comparer">The comparer.</param>
        public static void TimSort <T>(this IList <T> array, int start, int length, Comparer <T> comparer, bool buffered)
        {
            length = Math.Min(length, array.Count - start);

            if (buffered)
            {
                BufferedListSort(array, start, length, comparer.Compare);
            }
            else
            {
                ListTimSort <T> .Sort(array, start, start + length, comparer.Compare);
            }
        }
예제 #7
0
        /// <summary>Sorts the specified array.</summary>
        /// <typeparam name="T">Type of item.</typeparam>
        /// <typeparam name="C">Type of compared expression.</typeparam>
        /// <param name="array">The array.</param>
        /// <param name="start">The start index.</param>
        /// <param name="length">The length.</param>
        /// <param name="expression">The compared expression.</param>
        /// <param name="buffered">Set it to <c>true</c> if you need buffered sorting.</param>
        public static void TimSort <T, C>(this IList <T> array, int start, int length, Func <T, C> expression, bool buffered)
        {
            length = Math.Min(length, array.Count - start);
            Comparison <T> comparer = (a, b) => Comparer <C> .Default.Compare(expression(a), expression(b));

            if (buffered)
            {
                BufferedListSort(array, start, length, comparer);
            }
            else
            {
                ListTimSort <T> .Sort(array, start, start + length, comparer);
            }
        }
예제 #8
0
        public void Sort_Tests()
        {
            Assert.Throws(typeof(ArgumentNullException), () => { SysUtils.QuickSort <ValItem>(null, null); });
            Assert.Throws(typeof(ArgumentNullException), () => { SysUtils.MergeSort <ValItem>(null, null); });
            Assert.Throws(typeof(ArgumentNullException), () => { ListTimSort <int> .Sort(null, null); });

            Random rnd = new Random();

            List <ValItem> listQS = new List <ValItem>();
            List <ValItem> listMS = new List <ValItem>();
            List <ValItem> listTS = new List <ValItem>();
            List <ValItem> listCS = new List <ValItem>();

            //const int MaxCount = 1000000; // for performance test
            const int MaxCount = 1000; // for common test

            for (int i = 0; i < MaxCount; i++)
            {
                double val = rnd.NextDouble();

                listTS.Add(new ValItem(val));
                listQS.Add(new ValItem(val));
                listMS.Add(new ValItem(val));
                listCS.Add(new ValItem(val));
            }

            listCS.Sort(CompareItems);

            SysUtils.QuickSort(listQS, CompareItems);

            SysUtils.MergeSort(listMS, CompareItems);

            ListTimSort <ValItem> .Sort(listTS, CompareItems);

            // test for sort valid
            //(only for numbers, because some methods is with the permutations, and part - no)
            for (int i = 0; i < MaxCount; i++)
            {
                Assert.AreEqual(listTS[i].Value, listQS[i].Value);
                Assert.AreEqual(listQS[i].Value, listMS[i].Value);
                Assert.AreEqual(listMS[i].Value, listCS[i].Value);
            }
        }