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); }
public IndexSorterKeyed(Func <TElement, TKey> keySelector, IComparer <TKey> comparer, IndexSorter <TElement> lower) : base(lower) { this.keySelector = keySelector; this.comparer = comparer; }
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)); } }
public IndexSorterChain(IndexSorter <TElement> lower) => this.lower = lower;
public abstract int[] Sort(TElement[] data, IndexSorter <TElement> sorter);