D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3638 - stable sort assertion failure for repeated key sequence
Summary: stable sort assertion failure for repeated key sequence
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-21 13:40 UTC by Andrew Talbot
Modified: 2014-02-14 20:35 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrew Talbot 2009-12-21 13:40:32 UTC
Performing a stable sort on a repeated pair of keys that are already in sorted order causes the following error message.

core.exception.AssertError@std.algorithm(3736): Assertion failure

However, doing so with repeated reverse-sorted keys works fine.

In other words, a stable sort of the array
[ "B", "A", "B", A" ] will succeed, but one of ["A", "B", "A", "B" ] will fail.

Illustrative code:

import std.algorithm;
import std.stdio;

void main()
{
    auto ar1 = [ "B", "A", "B", "A" ];
    sort!("a <  b", SwapStrategy.stable)(ar1); // ok
    writeln(ar1);

    auto ar2 = [ "A", "B", "A", "B" ];
    sort!("a <  b", SwapStrategy.stable)(ar2); // fails
    writeln(ar2);
}
Comment 1 Andrei Alexandrescu 2009-12-21 14:23:34 UTC
Thanks for the report.
Comment 2 Andrew Talbot 2011-07-16 07:59:37 UTC
Fixed in version dmd 2.054.