[Issue 4179] Deleting items from an associative array iterated over

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 29 10:01:38 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=4179



--- Comment #8 from Vladimir <thecybershadow at gmail.com> 2011-03-29 09:58:07 PDT ---
There are more possible ways to make it safe than this.

One way is to have a list of current iterations associated with each AA. Any
time an item is removed, any current iterations are also updated. The nodes of
the list can be stored on the stack of aaApply or whatever function does the
"foreach" for AAs. It can be as simple as one pointer in the AA structure, and
a structure with two fields ("current iteration item" / "next list node") on
the stack - this should allow everything to "just work" and have a small impact
on performance.

Alternatively, when items are removed from an AA they can be left for the GC to
collect rather than deleted explicitly, and their "next" pointer can be set to
a magic value indicating that they were deleted (e.g. cast(void*)1).

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


More information about the Digitalmars-d-bugs mailing list