[haxe] HDictionary

When trying to implement a new event system that support custom parameters in Haxe, I come across the need of AS3 Dictionary. After doing a quick search I found that there are no Haxe equivalent (yes, there is TypedDictionary but it’s only available if you are targeting Flash). To me, there is no point to write in Haxe if we can only target one platform, so I bring it up to create a HDictionary that works similar to AS3 Dictionary in pure Haxe hopefully this will be helpful to someone out there.

The basic idea is simple, as we do not has any kind of object signature (a unique string equivalent, usually its memory address) to use as the key, we need to store both key and value and then make a loop through all the items, doing comparison until we come across the correct one. You might think that this will cause much overhead (searching a lot) but remember that whatever type of script we used, this overhead can not be avoided.
Continue reading

Advertisements