Re: [Flashcoders] dictionary vs array
There's also a performance issue there, since some array operations(ie. splice) are more expensive than in dictionaries and some dictionaries operations(ie. for in) are more expensive than array ones. Leandro Ferreira On 3/11/08, Hans Wichman [EMAIL PROTECTED] wrote: On a sidenote, it's pretty easy to implement for as2 too btw, although the performance is probably not uber. I gotta admit once you get used to object-to-object mapping ... ;) On Tue, Mar 11, 2008 at 9:07 PM, Claus Wahlers [EMAIL PROTECTED] wrote: Claus Wahlers wrote: An associative Array behaves similar to a Dictionary. (if you are using string keys) Cheers, Claus. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] dictionary vs array
If you want the best performance you can get: http://lab.polygonal.de/2007/11/26/data-structures-more-on-linked-lists/ His doubly linked list is insanely fast. What I mean is, I had some code that moved non-sequential items around a list. Using an Array, I could easily cause Flash to timeout from code taking too long with 25,000 items. Using a DLinkedList, I could do the same operation with 200,000 items in about 300ms. 25,000 items was 10ms on average. Obviously, YMMV, but these classes are fantastic. Leandro Ferreira wrote: There's also a performance issue there, since some array operations(ie. splice) are more expensive than in dictionaries and some dictionaries operations(ie. for in) are more expensive than array ones. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] dictionary vs array
An Array is a linear collection. A Hash is a random access collection (lookup table) of name-value pairs. Dictionary is a fancy Hash that can take an Object as a key, instead of a String, and uses strict (===) equality for its lookups. hash = new Object(); hash.foo = bar; array = new Array(); array.push(hello); array.push(world); dictionary = new Dictionary(); dictionary[hash] = array; trace(hash.foo); -- bar trace(array) -- hello, world trace(dictionary[hash]); -- hello, world ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] dictionary vs array
I was just wondering since tthe PV3d guys use it all the time.. and i am having some trouble interacting with planes consistently ( see http://www.dnecklesportfolio.com/pv3d/ click on interactive and then experiements ).. so i thought that it might be an issue as far off as it seems Date: Tue, 11 Mar 2008 19:48:45 +0100 From: [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] dictionary vs array CC: [EMAIL PROTECTED]; [EMAIL PROTECTED] Hi, its a conceptual difference, array maps indices to objects, while a dictionary maps objects to objects. There is no such thing as better, it depends on what you need. greetz JC On Tue, Mar 11, 2008 at 7:02 PM, Dwayne Neckles [EMAIL PROTECTED] wrote: can anyone say why dictionary is better than array.. Im seeing it used in alot of papervision examples and i dont get why? I will research this on my own as well.. _ Need to know the score, the latest news, or you need your Hotmail(R)-get your fix. http://www.msnmobilefix.com/Default.aspx___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _ Helping your favorite cause is as easy as instant messaging. You IM, we give. http://im.live.com/Messenger/IM/Home/?source=text_hotmail_join___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] dictionary vs array
You got it! :) You can mix and match with a Dictionary, as well. You can use strings as keys or objects. Patrick Matte | BLITZ wrote: Thanks Steven, I never really understood what a dictionary was myself, so dictionary would be useful for something like this ? dictionary = new Dictionary(); button1 = new Button() dictionary[button1] = http://www.google.com;; button2 = new Button() dictionary[button2] = http://www.yahoo.com;; function onButtonClick(event:MouseEvent){ trace(dictionary[event.target]); } BLITZ | Patrick Matte - 310-551-0200 x214 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] dictionary vs array
Dwayne Neckles wrote: can anyone say why dictionary is better than array.. Im seeing it used in alot of papervision examples and i dont get why? I will research this on my own as well.. Keys in an Array can be numeric, strings, or both: var a:Array = []; a[0] = something; a[hello] = something; // associative Array Keys in a Dictionary can theoretically be of any type: var d:Dictionary = new Dictionary(); d[0] = something; d[hello] = something; var c:SomeClass = new SomeClass(); d[c] = something; An associative Array behaves similar to a Dictionary. I might be wrong but i remember seeing that if you want to store data with string keys, Dictionary is performing slightly better. A word of caution if you plan to use E4X XML nodes or function references as Dictionary keys: this appears to be buggy. Cheers, Claus. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] dictionary vs array
That's a pretty good use, as long as you call your variable something more meaningful than dictionary. :) On 3/11/08, Patrick Matte | BLITZ [EMAIL PROTECTED] wrote: Thanks Steven, I never really understood what a dictionary was myself, so dictionary would be useful for something like this ? dictionary = new Dictionary(); button1 = new Button() dictionary[button1] = http://www.google.com;; button2 = new Button() dictionary[button2] = http://www.yahoo.com;; function onButtonClick(event:MouseEvent){ trace(dictionary[event.target]); } BLITZ | Patrick Matte - 310-551-0200 x214 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steven Sacks Sent: Tuesday, March 11, 2008 12:14 PM To: Flash Coders List Subject: Re: [Flashcoders] dictionary vs array An Array is a linear collection. A Hash is a random access collection (lookup table) of name-value pairs. Dictionary is a fancy Hash that can take an Object as a key, instead of a String, and uses strict (===) equality for its lookups. hash = new Object(); hash.foo = bar; array = new Array(); array.push(hello); array.push(world); dictionary = new Dictionary(); dictionary[hash] = array; trace(hash.foo); -- bar trace(array) -- hello, world trace(dictionary[hash]); -- hello, world ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- Cory Petosky : Lead Developer : PUNY 1618 Central Ave NE Suite 130 Minneapolis, MN 55413 Office: 612.216.3924 Mobile: 240.422.9652 Fax: 612.605.9216 http://www.punyentertainment.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] dictionary vs array
The best use for them is to be able to find something you've stored by its key - as opposed to having to loop through an entire array to find it. Pretty damn handy, but sorting them can be complicated. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Patrick Matte | BLITZ Sent: Wednesday, 12 March 2008 8:42 a.m. To: Flash Coders List Subject: RE: [Flashcoders] dictionary vs array Thanks Steven, I never really understood what a dictionary was myself, so dictionary would be useful for something like this ? dictionary = new Dictionary(); button1 = new Button() dictionary[button1] = http://www.google.com;; button2 = new Button() dictionary[button2] = http://www.yahoo.com;; function onButtonClick(event:MouseEvent){ trace(dictionary[event.target]); } BLITZ | Patrick Matte - 310-551-0200 x214 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steven Sacks Sent: Tuesday, March 11, 2008 12:14 PM To: Flash Coders List Subject: Re: [Flashcoders] dictionary vs array An Array is a linear collection. A Hash is a random access collection (lookup table) of name-value pairs. Dictionary is a fancy Hash that can take an Object as a key, instead of a String, and uses strict (===) equality for its lookups. hash = new Object(); hash.foo = bar; array = new Array(); array.push(hello); array.push(world); dictionary = new Dictionary(); dictionary[hash] = array; trace(hash.foo); -- bar trace(array) -- hello, world trace(dictionary[hash]); -- hello, world ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Scanned by Bizo Email Filter ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] dictionary vs array
On a sidenote, it's pretty easy to implement for as2 too btw, although the performance is probably not uber. I gotta admit once you get used to object-to-object mapping ... ;) On Tue, Mar 11, 2008 at 9:07 PM, Claus Wahlers [EMAIL PROTECTED] wrote: Claus Wahlers wrote: An associative Array behaves similar to a Dictionary. (if you are using string keys) Cheers, Claus. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders