D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3946 - schwartzSort - SwapStrategy always unstable
Summary: schwartzSort - SwapStrategy always unstable
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: Lars T. Kyllingstad
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-13 00:41 UTC by Ilya Yaroshenko
Modified: 2014-02-15 02:43 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ilya Yaroshenko 2010-03-13 00:41:34 UTC
In the last line sort calling without "ss" (SwapStrategy) - it is looks like always unstable:

module std.algorithm;

void schwartzSort(alias transform, alias less = "a < b",
        SwapStrategy ss = SwapStrategy.unstable, Range)(Range r)
    if (isRandomAccessRange!(Range) && hasLength!(Range))
{
    alias typeof(transform(r.front)) XformType;
    auto xform = new XformType[r.length];
    foreach (i, e; r)
    {
        xform[i] = transform(e);
    }
    auto z = zip(xform, r);
    alias typeof(z.front()) ProxyType;
    bool myLess(ProxyType a, ProxyType b)
    {
        return binaryFun!(less)(a.at!(0), b.at!(0));
    }
    sort!(myLess)(z);                               /// <-------------
}
Comment 1 Andrei Alexandrescu 2010-03-13 07:00:46 UTC
Thanks!
Comment 2 Lars T. Kyllingstad 2010-08-13 03:56:53 UTC
http://www.dsource.org/projects/phobos/changeset/1845