On Fri, 17 Feb 2012 08:44:42 -0500, Mars <-@-.-> wrote:

On Friday, 17 February 2012 at 13:33:25 UTC, James Miller wrote:
AAs don't keep the key order, so when you delete something out of it,
what ever system iterates to the next pointer gets confused. Its
generally a bad idea to modify an array as you loop through it.

--
James Miller

Too bad. So, what would be the correct way to do this? I mean... it's not that uncommon, to have this problem. Are creating a new array while iterating over it, or creating a list of elements to remove, and removing them afterwards, the only ways to do this?

If you are interested in an alternative implementation that does allow this, see here:

www.dsource.org/projects/dcollections

One of the features is "Removal while traversing."

In particular pay attention to the purge and keyPurge functions of the HashMap class and its usage.

The docs are woefully underdeveloped, but you can see how its used here:

http://www.dsource.org/projects/dcollections/browser/branches/d2/concepts.txt#L81

-Steve

Reply via email to