HaXe: Multitarget Dictionary class

Sometimes there are things so powerfull that thay have problems just for being powerfull, that’s what happens with HaXe sometimes.
There is not a Dictionary class officialy supported by HaXe, the TypedDictionary class only works on the Flash target.
The reason is because HaXe creates native code, and there is not a generic way in all the native platforms to get an identifier of an object.
But that doesn’t mean we can’t have a a Dictionary class so here it is my version of it, called ObjectHash.
Works good and fast like the flash class, at least on the targets I have tested it: flash, windows/C++ and html5 . If you tested it in another target let me know, I’ll update this.

Download ObjectHash from here.

How to use it:

It has the same syntax of  TypedDictionary. If you need to know how to use the class, learn TypedDitionary.

Differences with NME’s ObjectHash:

  • The NME’s class is more efficient with virtual memory.
  • This class supports more targets than NME’s one.
  • This class works like TypedDictionary or like Dictionary in AS3, when you make a loop you get the keys. NME’s ObjectHash behaves in consistency with HaXe’s Hash, when you make a loop you get values so you need to make a loop using objectHash.keys() to get the keys.

If you are targeting only the NME platforms I recommend you to use that class.

There are some small limitations:

String, Float, Int and Bool types can be set as values but not as keys. Example: myObjectHash.set(myInt, myMovieClip) doesn’t work and myObjectHash.set(myMovieClip, myInt) works. I think is not a big problem since using those basic data types as keys in a object hash is a rare case, I never needed to do that in my years of AS3 development. NME’s version of the class has the same limitation for the moment.

Advertisements

About fermmm

AS3 and Haxe developer from Argentina.

2 responses to “HaXe: Multitarget Dictionary class

  1. Thiên Hạ

    I also do another version before, not sure how it compared to yours, I’m checking out ! http://thienhaflash.wordpress.com/2012/01/24/hdictionary/

    • tanks for your reply, would be cool if you post your test results here. I think your class it’s a good alternative but it’s not so fast, because is based on iterations, the class I post here is a “low level” black magic thing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s