Esempio n. 1
0
        internal static double[] SortAndRevert(double[] array)
        {
            var indexes = IndexSorter.Sort(array);

            var result = new double[array.Length];

            for (var i = 0; i < result.Length; ++i)
            {
                result[indexes[result.Length - 1 - i]] = array[indexes[i]];
            }

            return(result);
        }
Esempio n. 2
0
 public IndexSorterKeyed(Func <TElement, TKey> keySelector, IComparer <TKey> comparer, IndexSorter <TElement> lower)
     : base(lower)
 {
     this.keySelector = keySelector;
     this.comparer    = comparer;
 }
Esempio n. 3
0
        public static int[] Sort <TElement, TKey>(TElement[] data, Func <TElement, TKey> keySelector, IComparer <TKey> comparer, bool descending, OrderBy <TElement> parent, IndexSorter <TElement> tail)
        {
            // Comparer<string>.Default creates a string comparer that will always get the threads current culture,
            // but as we're going to do a sort where we are not changing the culture until the operation is over
            // we can lock in the StringComparer.CurrentCulture up front.
            comparer =
                typeof(TKey) == typeof(string) && comparer == Comparer <string> .Default
                ? (IComparer <TKey>)StringComparer.CurrentCulture
                : comparer;

            if (descending && FastTypeInfo <TKey> .IsValueType() && comparer == Comparer <TKey> .Default)
            {
                DescendingWrapperForValueTypeWithDefaultComparer <TKey> keySelectorWrapper(TElement element) =>
                new DescendingWrapperForValueTypeWithDefaultComparer <TKey>(keySelector(element));

                var sorter =
                    new IndexSorterKeyed <TElement, DescendingWrapperForValueTypeWithDefaultComparer <TKey> >(keySelectorWrapper, Comparer <DescendingWrapperForValueTypeWithDefaultComparer <TKey> > .Default, tail);

                return(parent != null?parent.Sort(data, sorter) : sorter.StableSortedIndexes(data));
            }
            else
            {
                comparer =
                    descending
                    ? new DescendingComparer <TKey>(comparer) :
                    comparer;

                var sorter = new IndexSorterKeyed <TElement, TKey>(keySelector, comparer, tail);

                return(parent != null?parent.Sort(data, sorter) : sorter.StableSortedIndexes(data));
            }
        }
Esempio n. 4
0
 public IndexSorterChain(IndexSorter <TElement> lower) => this.lower = lower;
Esempio n. 5
0
 public abstract int[] Sort(TElement[] data, IndexSorter <TElement> sorter);