HashMap // Random shuffle

34 views
Skip to first unread message

Thomas Pujolle

unread,
Mar 2, 2011, 4:37:06 AM3/2/11
to pixlib
Hi there!

First of all, thanks for this new framework.

I'm still using Palmer in its previous version, and this new one looks
just amazing!


So, while using this old version of palmer, I just discovered
something weird on the HashMap class.
As this class is the same in Pixlib3, I allow me to post this here.

I'm storing some ValueObjects in a HashMap. The problem is, my hash
map get shuffled randomly every time I add a Vo. Sometimes this is the
right order, and sometimes this is completely different.

For example, if I add A, then B, then C, the getValues() can possibly
get me this:
A,C,B
B,A,C
B,C,A

And so on ...

All the different possibilities!

I don't know where does that come from, and I'm sure it's not from my
code as I push the VO in the right order (and log the getValues()
before and after).

What do you think? Is it right to store VO in a HashMap? Have you ever
seen any bug like this before?

Thanks guys :)

Mike

unread,
Mar 2, 2011, 4:54:01 AM3/2/11
to pixlib
Hi Thomas,

No bug here. PXHashMap internally uses dictionaries to store / manage
keys and values.
As a consequence you cannot expect to retrieve your data ordered as if
you were using an Array or Vector.

Thomas Pujolle

unread,
Mar 2, 2011, 5:15:14 AM3/2/11
to pixlib
Ok!

So this component is not meant to keep the order.
If I want an orderer list it's just naive, isn't it?

Which component should I use to be able to push some keys into it, and
be able to get an orderer list? (orderer like in the way I pushed the
items)

Mike

unread,
Mar 2, 2011, 5:30:52 AM3/2/11
to pixlib
You will have to do it on your own.

As an idea of custom implementation you may use an array to store each
key (at time you put new key/value pair in PXHashMap) and later loop
through the array retrieving each value with PXHashMap.get(key)

Mike

unread,
Mar 2, 2011, 5:37:02 AM3/2/11
to pixlib
I was thinking...

You may also get back all keys as an array using PXHashMap.keys and if
those are numerics then, sorting the resulting array and cycle through
your values without using extra array to store indexes ;)

Thomas Pujolle

unread,
Mar 2, 2011, 5:57:42 AM3/2/11
to pixlib
I think I will go the extra array as my keys are not numeric.

Thanks for this :)

Can't wait to try this new PixLib!

It's not related to this post, but I got struggled with something
else, still with the "old" palmer, which is extremely similar to this
new one.

I need to get a plugin to listen to another one, using this code:
var _lp:LearningApplication = new LearningApplication(this);
var _scormPlugin:ScormPlugin = new ScormPlugin();
_lp.addListener(_scormPlugin);

The two plugin implement plugin listener.

Is this naive again? :D

I get an error in my logs: LearningApplication doesn't have public
dispatcher

And I didn't find the way to get this public dispatcher ... :(

Mike

unread,
Mar 2, 2011, 6:06:46 AM3/2/11
to pixlib
Please open another thread for new question, thanks.
Reply all
Reply to author
Forward
0 new messages