digitalmars.D - std.algorithm.remove using SwapStrategy.unstable doesn't works
- =?UTF-8?B?QWxla3NhbmRhciBSdcW+acSNacSH?= (22/22) Nov 16 2010 I'm trying to use remove() from std.algorithm to remove item from an
- Andrei Alexandrescu (4/26) Nov 16 2010 Looks like a bug. Could you please file it to bugzilla?
- =?UTF-8?B?QWxla3NhbmRhciBSdcW+acSNacSH?= (7/48) Nov 16 2010 No problem, just to isolate the code and to confirm it's not something
- =?UTF-8?B?QWxla3NhbmRhciBSdcW+acSNacSH?= (8/57) Nov 16 2010 filed as Issue #5224 - http://d.puremagic.com/issues/show_bug.cgi?id=3D5...
I'm trying to use remove() from std.algorithm to remove item from an array and when I tried to use SwapStrategy.unstable (as I don't need to maintain order of items in array and I want to optimize where ever I can) I came to surprising results. In the example below one would expect that item at index 2 (number 3 in example) will be removed but instead item at index 0 is removed from array. Is this a bug or I'm missing a point? ----------------------------------------------------- import std.stdio, std.algorithm; void main(string[] args) { auto a = [1,2,3,4]; foreach (e; a) writef("%s ", e); writefln("(%s)", a.length); // 1 2 3 4 (4) auto i = a.indexOf(3); writefln("%s", i); // 2 if (i > -1) { a = remove!(SwapStrategy.unstable)(a, i); } foreach (e; a) writef("%s ", e); writefln("(%s)", a.length); // 4 2 3 (3) !?! } ----------------------------------------------------- thx in advance, Aleksandar
Nov 16 2010
On 11/16/10 4:24 AM, Aleksandar Ružičić wrote:I'm trying to use remove() from std.algorithm to remove item from an array and when I tried to use SwapStrategy.unstable (as I don't need to maintain order of items in array and I want to optimize where ever I can) I came to surprising results. In the example below one would expect that item at index 2 (number 3 in example) will be removed but instead item at index 0 is removed from array. Is this a bug or I'm missing a point? ----------------------------------------------------- import std.stdio, std.algorithm; void main(string[] args) { auto a = [1,2,3,4]; foreach (e; a) writef("%s ", e); writefln("(%s)", a.length); // 1 2 3 4 (4) auto i = a.indexOf(3); writefln("%s", i); // 2 if (i> -1) { a = remove!(SwapStrategy.unstable)(a, i); } foreach (e; a) writef("%s ", e); writefln("(%s)", a.length); // 4 2 3 (3) !?! } ----------------------------------------------------- thx in advance, AleksandarLooks like a bug. Could you please file it to bugzilla? Thanks, Andrei
Nov 16 2010
No problem, just to isolate the code and to confirm it's not something to other parts of my code (but I'm pretty sure it's not). On Tue, Nov 16, 2010 at 7:03 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:On 11/16/10 4:24 AM, Aleksandar Ru=C5=BEi=C4=8Di=C4=87 wrote:s)", a.length); // 1 2I'm trying to use remove() from std.algorithm to remove item from an array and when I tried to use SwapStrategy.unstable (as I don't need to maintain order of items in array and I want to optimize where ever I can) I came to surprising results. In the example below one would expect that item at index 2 (number 3 in example) will be removed but instead item at index 0 is removed from array. Is this a bug or I'm missing a point? ----------------------------------------------------- import std.stdio, std.algorithm; void main(string[] args) { =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto a =3D [1,2,3,4]; =C2=A0 =C2=A0 =C2=A0 =C2=A0foreach (e; a) writef("%s ", e); writefln("(%=pStrategy.unstable)(a, i);3 4 (4) =C2=A0 =C2=A0 =C2=A0 =C2=A0auto i =3D a.indexOf(3); =C2=A0 =C2=A0 =C2=A0 =C2=A0writefln("%s", i); =C2=A0 =C2=A0 =C2=A0// 2 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (i> =C2=A0-1) { =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0a =3D remove!(Swa=s)", a.length); // 4 2=C2=A0 =C2=A0 =C2=A0 =C2=A0} =C2=A0 =C2=A0 =C2=A0 =C2=A0foreach (e; a) writef("%s ", e); writefln("(%=3 (3) !?! } ----------------------------------------------------- thx in advance, AleksandarLooks like a bug. Could you please file it to bugzilla? Thanks, Andrei
Nov 16 2010
regards, Aleksandar 2010/11/16 Aleksandar Ru=C5=BEi=C4=8Di=C4=87 <ruzicic.aleksandar gmail.com>= :No problem, just to isolate the code and to confirm it's not something to other parts of my code (but I'm pretty sure it's not). On Tue, Nov 16, 2010 at 7:03 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:%s)", a.length); // 1 2On 11/16/10 4:24 AM, Aleksandar Ru=C5=BEi=C4=8Di=C4=87 wrote:I'm trying to use remove() from std.algorithm to remove item from an array and when I tried to use SwapStrategy.unstable (as I don't need to maintain order of items in array and I want to optimize where ever I can) I came to surprising results. In the example below one would expect that item at index 2 (number 3 in example) will be removed but instead item at index 0 is removed from array. Is this a bug or I'm missing a point? ----------------------------------------------------- import std.stdio, std.algorithm; void main(string[] args) { =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto a =3D [1,2,3,4]; =C2=A0 =C2=A0 =C2=A0 =C2=A0foreach (e; a) writef("%s ", e); writefln("(=apStrategy.unstable)(a, i);3 4 (4) =C2=A0 =C2=A0 =C2=A0 =C2=A0auto i =3D a.indexOf(3); =C2=A0 =C2=A0 =C2=A0 =C2=A0writefln("%s", i); =C2=A0 =C2=A0 =C2=A0// 2 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (i> =C2=A0-1) { =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0a =3D remove!(Sw=%s)", a.length); // 4 2=C2=A0 =C2=A0 =C2=A0 =C2=A0} =C2=A0 =C2=A0 =C2=A0 =C2=A0foreach (e; a) writef("%s ", e); writefln("(=3 (3) !?! } ----------------------------------------------------- thx in advance, AleksandarLooks like a bug. Could you please file it to bugzilla? Thanks, Andrei
Nov 16 2010