Daniel Kozak:

 is there a way for AA to behave same as PHP?

D associative arrays are based on hashing, so they do not keep the order of the items. This is true in Python too. The Python standard library has a hash-based ordered dict that keeps the insertion order of the keys. There is no such data structure in Phobos.

You could write one yourself (wrapping an associative array and using a linked list. I remember there is a trick to find the address of a D associative array key given its value address, but I don't remember it and it's not portable).

An alternative solution is to use the Phobos AVL-based tree as an associative array, but it's less convenient and the search complexity is logarithmic instead of constant in the average case.

Bye,
bearophile

Reply via email to