www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5224] New: std.algorithm.remove!(SwapStrategy.unstable) doesn't work

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5224

           Summary: std.algorithm.remove!(SwapStrategy.unstable) doesn't
                    work
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: ruzicic.aleksandar gmail.com



2010-11-16 20:52:45 CET ---
Example code below shows that there is a bug in remove() using unstable
SwapStrategy - it removes wrong element from an array.
Using default swap strategy works as expected.
-----------------------------------------------------------
module test;

import std.algorithm;

import std.stdio, std.algorithm;

void main(string[] args) {

    auto a = [1, 2, 3, 4];

    print("initial", a);

    auto i = a.indexOf(3);

    writefln("indexOf(3) = %s", i);

    if (i > -1) {
        print("remove!(SwapStrategy.unstable)",
remove!(SwapStrategy.unstable)(a, i));
    }

    /*
        Tested with DMD v2.049 under Windows 7:
        > dmd -run test.d
        initial: 1 2 3 4 (length = 4)
        indexOf(3) = 2
        remove!(SwapStrategy.unstable): 4 2 3 (length = 3)

                it removed element at index 0 rather than element at index 2
     */
}

void print(string name, int[] array) {
    writef("%s: ", name);
    foreach (elem; array) {
        writef("%s ", elem);
    }
    writefln("(length = %s)", array.length);
}
-----------------------------------------------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5224




2010-11-16 21:02:22 CET ---
tested now also under DMD 2.050, same results.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5224


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5224


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|x86_64                      |x86



---
Mass migration of bugs marked as x86-64 to just x86.  The platform run on isn't
what's relevant, it's if the app is a 32 or 64 bit app.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5224


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear mailmetrash.com
           Platform|x86                         |All
         OS/Version|Windows                     |All



PDT ---
Although the unit tests pass, they seem insufficient.
This example actually comes from a comment in algorithm.d and yet it fails on
2.059:

int[] a = [ 0, 1, 2, 3 ];
assert(remove!(SwapStrategy.unstable)(a, 1) == [ 0, 3, 2 ]);

(returns [3, 1, 2])
Idem for SwapStrategy.semistable

Also, in one comment of algorithm.d, there is a typo. According to the
explanation under the example, line 5914 of algorithm.d should be:
int[] a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
assert(remove(a, 1, tuple(3, 5), 9) == [ 0, 2, 5, 6, 7, 8, 10 ]);
                                               ^-- forgotten

"The tuple passes in a range closed to the left and open to
the right"

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5224


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



PDT ---
*** Issue 6956 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5224




PST ---
https://github.com/D-Programming-Language/phobos/pull/1162

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 26 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5224




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/98b47ad5dd882e593b630dc345087914f88fa570
issue 5224

https://github.com/D-Programming-Language/phobos/commit/dcd065e2e56fc769e5a5b209910674229c6a0e17


Fix Issue 5224 - std.algorithm.remove!(SwapStrategy.unstable) doesn't work

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 30 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5224


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 30 2013