std.partition is fucked

superdan super at dan.org
Wed May 13 07:55:41 PDT 2009


dis must be related to bug 2966 sayin' std.sort is fucked. problem must be with std.partition. i tested and unstable partition is 10 times slower than stable. should be faster akshully. so looked into tat and found in da loop for std.partition unstable and found da range r1 is fucked.

        for (;;)
        {
            for (;;)
            {
                if (r.empty) return r;
                if (!pred(r.front)) break;
                r.popFront;
            }
            // found the left bound
            assert(!r.empty);
            auto r1 = r;
            for (;;)
            {
                if (pred(r1.back)) break;
                r1.popBack;
                if (r1.empty) return r;
            }
            // found the right bound, swap & make progress
            swap(r.front, r1.back);
            r.popFront;
            r1.popBack;
        }

r1 is popbacked a few times but then all tat is forgotten the next time around da loop coz r1 is local to da loop. so da loop is quadratic methinks. what u need iz save r outside loop & then popfront & popback from da same range 'n' shit.



More information about the Digitalmars-d mailing list