Example #1
0
            public int Compare(KeyIndex <T> x, KeyIndex <T> y)
            {
                int keyComparisonResult = mKeyComparer.Compare(x.Key, y.Key);

                if (keyComparisonResult == 0)
                {
                    return(x.Index - y.Index);
                }                                                             // # Values are equal. Index values are compared to achieve stable order.

                return(keyComparisonResult);
            }
        internal IEnumerator <TSource> DeferredSort()
        {
            Buffer <TSource> buffer = new Buffer <TSource>(mSource);

            if (!buffer.IsEmpty)
            {
                mData = new KeyIndex <TKey> [buffer.Count]; // # Sorting will be performed on KeyIndex values created, using index information to achieve stabile order

                for (int index = 0; index < mData.Length; index++)
                {
                    mData[index] = new KeyIndex <TKey>(mKeySelector(buffer[index]), index);
                }

                base.Sort();

                for (int index = 0; index < mData.Length; index++) // # Yielding buffered items in sorted index order
                {
                    yield return(buffer[mData[index].Index]);
                }
            }
        }
 internal StableQuickSorter(IEnumerable <TSource> source, IComparer <TKey> comparer, Func <TSource, TKey> keySelector)
 {
     mSource      = source;
     mKeySelector = keySelector;
     mComparer    = new KeyIndex <TKey> .Comparer(comparer);
 }