Associative array key order

Dicebot public at dicebot.lv
Wed Jul 31 07:55:54 PDT 2013


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.

There is a good chance that if you rely on key order, you don't 
really need an AA but plain array of key-value tuples instead.


More information about the Digitalmars-d-learn mailing list