Revamping associative arrays

Moritz Warning moritzwarning at web.de
Sat Oct 17 12:08:20 PDT 2009


On Sat, 17 Oct 2009 19:06:36 +0000, Moritz Warning wrote:

> On Sat, 17 Oct 2009 18:58:08 +0000, BCS wrote:
> 
>> Hello Chris Nicholson-Sauls,
>> 
>>> Andrei Alexandrescu wrote:
>>> 
>>>> Associative arrays are today quite problematic because they don't
>>>> offer any true iteration. Furthermore, the .keys and .values
>>>> properties create new arrays, which is wasteful.
>>>> 
>>>> Another issue with associative arrays is that ++a[k] is hacked, which
>>>> reflects a grave language limitation. That needs to be replaced with
>>>> a true facility.
>>>> 
>>>> Any other issues with AAs that you want to see fixed, and ideas
>>>> guiding a redesign?
>>>> 
>>>> Thanks,
>>>> 
>>>> Andrei
>>>> 
>>> Idea: the .keys and .values properties, rather than creating arrays,
>>> could create iterable ranges with the smallest possible footprint,
>>> internally walking the tree structure.
>>> 
>>> 
>> what will this do?
>> 
>> foreach(key; aa.keys)
>>    if(Test(key))
>>       aa.remove(key);
> 
> It's undefined behavior.
> You shouldn't try to mutate the aa while iterating. I hope that will be
> fixed.
> It took me some time to find this out.

Uh, sorry.
You are iterating over an fresh allocated array of the keys.
That's ok.



More information about the Digitalmars-d mailing list