Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>it acts as a hashmap. in fact, every ActionScript object that is an instance of a dynamic class, acts as hashmap. of course keys can always collide with properties. this behaviour comes from JavaScript. I consider it a design failure.</p> <p>Array is different in that it will perform some tricks on integer keys, and Dictionary is different in that it doesn't convert keys to strings, but uses any object value as key. Please note that Number and Boolean are both converted to String.</p> <p>now why whould you care how it is implemented? if it is well implemented, you probably don't wanna know. You can benchmark it. It has O(1) for all operations and is reasonably fast (inserting costs a about twice as much time as an empty method call, deleting costs less). Any alternative implementation will be slower.</p> <p>here a simple benchmark (be sure to compile it for release and run it in the right player):</p> <pre><code>package { import flash.display.Sprite; import flash.text.TextField; import flash.utils.*; public class Benchmark extends Sprite { public function Benchmark() { var txt:TextField = new TextField(); this.addChild(txt); txt.text = "waiting ..."; txt.width = 600; const repeat:int = 20; const count:int = 100000; var d:Dictionary = new Dictionary(); var j:int, i:int; var keys:Array = []; for (j = 0; j &lt; repeat * count; j++) { keys[j] = { k:j }; } setTimeout(function ():void { var idx:int = 0; var out:Array = []; for (j = 0; j &lt; repeat; j++) { var start:int = getTimer(); for (i = 0; i &lt; count; i++) { d[keys[idx++]] = i; } out.push(getTimer() - start); } txt.appendText("\n" + out); start = getTimer(); for (var k:int = 0; k &lt; i; k++) { test(); } txt.appendText("\ncall:"+(getTimer() - start)); idx = 0; out = []; for (j = 0; j &lt; repeat; j++) { start = getTimer(); i = 0; for (i = 0; i &lt; count; i++) { delete d[keys[idx++]]; } out.push(getTimer() - start); } txt.appendText("\n" + out); },3000);//wait for player to warm up a little } private function test():void {} } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload