[Issue 14340] AssertError in std.algorithm.sorting: unstable sort fails to sort an array with a custom predicate

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jul 19 18:00:37 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14340

--- Comment #6 from Xinok <xinok at live.com> ---
Gah, sorry, I misunderstood the problem. >_<  For some reason, I thought your
predicate was dependent on the order of the elements. Ignore my last post...

I still feel that this is bad practice and should be discouraged in general.
The simpler solution would be to dup' the range and refer to that, in which
case you could have a strongly pure predicate instead. However, if you all feel
this is worth fixing, then I won't argue anymore.

I'll just add that this is an issue for the stable sort as well but that won't
be so easy to fix. The algorithm used is Timsort, which is a variant of merge
sort, meaning it allocates a buffer to store elements temporarily. The simplest
solution would be to move to an in-place algorithm like block sort [1] but then
you'll be losing the benefits of Timsort.

[1] https://en.wikipedia.org/wiki/Block_sort

--


More information about the Digitalmars-d-bugs mailing list