D idom for removing array elements
cym13 via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jan 27 07:50:48 PST 2017
On Friday, 27 January 2017 at 15:39:57 UTC, cym13 wrote:
> On Friday, 27 January 2017 at 08:30:41 UTC, Dukc wrote:
>> [...]
>
> Note that if the set of values to be excluded isn't smaller
> than the haystack then using partition is way faster and your
> method is the slowest of all. If the order of the array matters
> stable partition can be used but is slower than the original
> method.
>
> [...]
I forgot to say that the main reason to use partition is that
it's easy to use it to remove the elements of the array in place:
auto r = a.partition!(v => !b.canFind(v));
a.length -= r.length;
It just puts the "bad" elements at the end and changes the length
of the array.
More information about the Digitalmars-d-learn
mailing list