Associative array key order

monarch_dodra monarchdodra at gmail.com
Thu Aug 22 01:41:11 PDT 2013


On Thursday, 22 August 2013 at 07:59:05 UTC, Daniel Kozak wrote:
> On Wednesday, 31 July 2013 at 14:55:55 UTC, Dicebot wrote:
>> On Wednesday, 31 July 2013 at 14:43:21 UTC, Daniel Kozak wrote:
>>> is there a way for AA to behave same as PHP?
>>
>> I doubt it. This snippet suggests that AA's in PHP are not 
>> simply AA's and do additionally track insertion order (or use 
>> some similar trick). Data in associative arrays is organized 
>> in a way that allows fast key lookup and iterating in an 
>> original order requires tracking extra state. Contrary to PHP, 
>> D does care about performance so I see no way this can happen 
>> automatically.
>
> I implemented my own OrderedAA type, which is able to preserve 
> insert order and is a little faster and take less memory(30%) 
> then the builtin one :-).
>
> But definitly there will be some cases where my own 
> implementation doesn't beat the builtin one.

Nice to hear. Perhaps you could share the implementation with us? 
Even if its not perfect, I'm curious to know how you went at it.


More information about the Digitalmars-d-learn mailing list