associative arrays: iteration is finally here

Denis Koroskin 2korden at gmail.com
Wed Oct 28 13:45:57 PDT 2009


On Wed, 28 Oct 2009 23:18:08 +0300, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

>> I'd also like you to add a few things in an AA interface.
>>  First, opIn should not return a pointer to Value, but a pointer to a  
>> pair of Key and Value, if possible (i.e. if this change won't sacrifice  
>> performance).
>
> I'm coy about adding that because it forces the implementation to hold  
> keys and values next to each other. I think that was a minor mistake of  
> STL - there's too much exposure of layout details.
>

It doesn't have to be the case: key and value are both properties (i.e.  
methods), and they doesn't have to be located next to each other.

>> Second, AA.remove method should accept result of opIn operation to  
>> avoid an additional lookup for removal:
>>  if (auto value = key in aa) {
>>     aa.remove(key); // an unnecessary lookup
>> }
>
> I'll make aa.remove(key) always work and return a bool that tells you  
> whether there was a mapping or not.
>

Err... How does it solve the double lookup problem?



More information about the Digitalmars-d mailing list