AA.remove in foreach && AA = new vs cleaning
Saaa
empty at needmail.com
Wed Oct 21 22:08:50 PDT 2009
Steven Schveighoffer wrote
>> But I've changed everything to `new` the array afterwards as I deleted
>> all the
>> keys anyways.
>
> Not sure what you mean here.
foreach (K k, ; aa)
{
..
//aa.remove(k);
}
aa = new int[char];
>
>>>
>>> I have gotten around this in dcollections by removing elements outside
>>> the
>>> loop body. See for example the keypurge function of HashMap
>>> (http://www.dsource.org/projects/dcollections/docs/current/dcollections.HashMap.html)
>> Do you add the ones to be deleted to a dynamic array or do you loop
>> over all elements afterwards? I expect the first :)
>
> I delete them as they are requested to be deleted. Since the deletion is
> done by the opApply function, it has knowledge of when it is ok to delete
> the element, and can save off any necessary structural information needed
> to get to the next element.
How is this `outside the loop body`?
Should I read it as `after the loop body`?
>
> It makes for an efficient method to traverse and remove in one pass.
>
> -Steve
More information about the Digitalmars-d-learn
mailing list