Exemple #1
0
 public void Sort(Comparison <T> comparison)
 {
     if (_RealLength > 0)
     {
         IComparer <T> comparer = new FunctorComparer <T>(comparison);
         Array.Sort(_List, 0, _RealLength, comparer);
     }
 }
Exemple #2
0
 public void Sort(Comparison <T> comparison)
 {
     if (this.Count > 0)
     {
         IComparer <T> comparer = new FunctorComparer <T>(comparison);
         Array.Sort <T>(this.Elements, 0, this.Count, comparer);
     }
 }
Exemple #3
0
 private static FunctorComparer <T, K> single(Func <T, K> functor, int sign)
 {
     if (_single == null)
     {
         _single = new FunctorComparer <T, K>();
     }
     _single._functor = functor;
     _single._sign    = sign;
     return(_single);
 }
Exemple #4
0
        /// <summary>
        /// Returns a new Query where the elements have been ordered using a selector function
        /// to select the values to order by.
        /// </summary>
        public static Query <T> OrderByDescending <T, K>(this Query <T> query, Func <T, K> selector) where K : IComparable <K>
        {
            T[] array;
            int count;

            query.Deconstruct(out array, out count);

            var comparer = FunctorComparer <T, K> .Descending(selector);

            Array.Sort(array, 0, count, comparer);
            comparer.Clear();

            return(new Query <T>(array, count));
        }
Exemple #5
0
 public void Sort(Comparison <T> comparison)
 {
     if (comparison == null)
     {
         throw new ArgumentNullException("comparison");
     }
     if (this.count > 0)
     {
         using (FunctorComparer <T> comparer = FunctorComparer <T> .Obtain(comparison))
         {
             Array.Sort <T>(this.items, 0, this.count, comparer);
         }
     }
 }
Exemple #6
0
        public static void Sort <T>(T[] array, Comparison <T> comparison)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (comparison == null)
            {
                throw new ArgumentNullException("comparison");
            }
            IComparer <T> comparer = new FunctorComparer <T>(comparison);

            Sort <T>(array, comparer);
        }
Exemple #7
0
 public void Sort(Comparison <T> comparison)
 {
     if (comparison == null)
     {
         throw new ArgumentNullException("comparison");
     }
     if (_size > 0)
     {
         IComparer <T> comparer = new FunctorComparer(comparison);
         Array.Sort(_items, 0, _size, new NodeComparer(comparer));
         UpdatePriority(0, _size);
         _version++;
         onModify?.Invoke(this, -1);
     }
 }
        public static List <T> Sort35 <T>(this System.Collections.Generic.List <T> list, Comparison <T> comparison)
        {
            if (comparison == null)
            {
                throw new ArgumentNullException("Comparison");
            }
            int length = list.Count;

            if (length > 0)
            {
                IComparer <T> comparer = new FunctorComparer <T>(comparison);

                int index = 0;

                if (list == null)
                {
                    throw new ArgumentNullException("array");
                }
                if (index < 0 || length < 0)
                {
                    throw new ArgumentOutOfRangeException((length < 0 ? "length" : "index") + "ArgumentOutOfRange_NeedNonNegNum");
                }

                //if (length > 1 && ((comparer != null && comparer != Comparer<T>.Default) || !TrySZSort(list.ToArray(), null, index, (index + length) - 1)))
                if (length > 1)
                {
                    try
                    {
                        if (comparer == null)
                        {
                            comparer = Comparer <T> .Default;
                        }
                        T[] keys = list.ToArray <T>();
                        QuickSort(keys, index, index + (length - 1), comparer);
                        return(keys.ToList());
                    }
                    catch (IndexOutOfRangeException)
                    {
                        object[] values = new object[3];
                        values[1] = typeof(T).Name;
                        values[2] = comparer;
                        throw new ArgumentException("Arg_BogusIComparer" + values);
                    }
                }
            }
            return(list);
        }
Exemple #9
0
        /// <summary>
        /// Initializes the <see cref="Grid"/> type.
        /// </summary>
        static Grid()
        {
            cmpByPreferredDesiredDimension = new FunctorComparer <DefinitionBase>((def1, def2) =>
            {
                return(def1.PreferredDesiredDimension.CompareTo(def2.PreferredDesiredDimension));
            });

            cmpByMaxDimension = new FunctorComparer <DefinitionBase>((def1, def2) =>
            {
                return(def1.MaxDimension.CompareTo(def2.MaxDimension));
            });

            cmpByMeasuredContentDimension = new FunctorComparer <DefinitionBase>((def1, def2) =>
            {
                return(def1.MeasuredContentDimension.CompareTo(def2.MeasuredContentDimension));
            });

            cmpByMinArrangedSize = new FunctorComparer <DefinitionBase>((def1, def2) =>
            {
                var def1Min = Math.Max(def1.MinDimension, def1.MeasuredContentDimension);
                var def2Min = Math.Max(def2.MinDimension, def2.MeasuredContentDimension);
                return(def2Min.CompareTo(def1Min));
            });
        }
Exemple #10
0
        /// <summary>
        /// If the underlying type is <see cref="List{T}"/>,
        /// calls <see cref="List{T}.Sort(IComparer{T})"/>. If not,
        /// uses <see cref="Util.CollectionUtil.TimSort{T}(IList{T}, IComparer{T})"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list">this <see cref="IList{T}"/></param>
        /// <param name="comparison">the comparison function to use for the sort</param>
        public static void Sort <T>(this IList <T> list, Comparison <T> comparison)
        {
            IComparer <T> comparer = new FunctorComparer <T>(comparison);

            Sort(list, comparer);
        }