[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 17:32:32 PDT 2015


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

--- Comment #5 from Ivan Kazmenko <gassa at mail.ru> ---
(In reply to Xinok from comment #3)
> ... The predicate is expected to define a total order [1]
> which your predicate does not.

But it does!  The order is "x < y if:
(1) number of xs in the array is greater than number of ys,
(2) if (1) is equal, just use ascending order".

Nothing wrong about that.

There's an even simpler example in the added unittest here involving only
count:

https://github.com/GassaFM/phobos/commit/fb6e4ddfcad656b8093aa51cf59726cf38e2cfbe

What's wrong is optimisticInsertionSort overwriting elements while hiding one
of them in a temporary variable, and calling the predicate all the way while
the array is in an invalid state.

--


More information about the Digitalmars-d-bugs mailing list