EamonNerbonne / anoprsst

Sorts Span<T> and arrays more quickly than Array.Sort
23 stars 4 forks source link

QuickSort_Inclusive_ParallelArgs.Impl fails to pass ordering as child param #8

Closed BillSobel closed 5 years ago

BillSobel commented 5 years ago

By not passing ordering, a default(TOrder) is used and any context in the structure that implements IOrdering<> needed for comparison is lost.

As an example, in the below refDictionary is null at the point that LessThan is called.

internal readonly struct SubDictionaryOrder<K,V> : IOrdering<int>
        where K : struct, IReputationKey, IRefEquatable<K>
        where V : struct, IReputationValuePointer
    {
        private readonly RefDictionary<K, V> refDictionary;
        internal SubDictionaryOrder(in RefDictionary<K, V> items)
        {
            System.Diagnostics.Debug.Assert(items != null);
            this.refDictionary = items;
        }
        bool IOrdering<int>.LessThan(int a, int b)
        {
            return refDictionary.CompareIndexValues(a, b) < 0;
        }
    }
EamonNerbonne commented 5 years ago

good catch; originally this code did not allow state to be passed; I'll look into it as soon as I can. (PRs always welcome of course!)

EamonNerbonne commented 5 years ago

To reproduce this in the bench+test project, it would be reasonable to use the same code you are - where's RefDictionary<K, V> from?

EamonNerbonne commented 5 years ago

I can reproduce the issue with the following (absurd, but who cares) ordering:

https://github.com/EamonNerbonne/anoprsst/blob/bfd270d4718b8333e1b131974d37fb73a8a87840/src/AnoprsstBench/SortAlgoBenchProgram.cs#L296

EamonNerbonne commented 5 years ago

Fixed in https://www.nuget.org/packages/Anoprsst/1.1.2

BillSobel commented 5 years ago

Thank you!