ordered Associative array

solidstate1991 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 13 17:51:09 PDT 2017


On Friday, 14 April 2017 at 00:29:34 UTC, Jethro wrote:
> Is there a way to retain the ordering of an associative array? 
> When the elements are added then looped over using a foreach, 
> the order is different.

Use a separate array to store the keys, order them all time when 
you add a new one, etc. This was the only workaround I could come 
up with for my engine (see it here: 
https://github.com/ZILtoid1991/pixelperfectengine/blob/master/source/PixelPerfectEngine/graphics/layers.d at Classes SpriteLayer and SpriteLayer32Bit), maybe in the future I'll come up with a better solution. I call this technique as "prioritized hash table" as the keys give them a certain priority, so there's no issue which sprite where supposed to show up.


More information about the Digitalmars-d-learn mailing list