<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Russischer Bär Project Blog</title>
	<atom:link href="http://sibirjak.com/blog/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://sibirjak.com/blog</link>
	<description>Neat Sophistication in Web Application Development</description>
	<lastBuildDate>Mon, 17 May 2010 14:41:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Collections framework performance comparision</title>
		<link>http://sibirjak.com/blog/index.php/collections/collections-framework-performance-comparision/</link>
		<comments>http://sibirjak.com/blog/index.php/collections/collections-framework-performance-comparision/#comments</comments>
		<pubDate>Tue, 04 May 2010 13:07:33 +0000</pubDate>
		<dc:creator>Jens Struwe</dc:creator>
				<category><![CDATA[Collections]]></category>

		<guid isPermaLink="false">http://sibirjak.com/blog/?p=801</guid>
		<description><![CDATA[In I have shown how custom collections handle specific programmig problems more efficiently than the built-in data containers Array and Dictionary. I have named a number of common collections which are part of almost every collections library. In this post I am going to compare the performance of such collections from 3 different libraries. AS3Commons [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://sibirjak.com/blog/index.php/collections/array-dictionary-collections-performace-functionality-reliability/">the last article</a> I have shown how custom collections handle specific programmig problems more efficiently than the built-in data containers Array and Dictionary. I have named a number of common collections which are part of almost every collections library. In this post I am going to compare the performance of such collections from 3 different libraries.</p>
<p><span id="more-801"></span></p>
<ul>
<li><a href="http://code.google.com/p/as3-commons/downloads/list">AS3Commons Collections</a> Version 1.0.0</li>
<li><a href="http://www.dpdk.nl/opensource/source-code">Dpdk open source</a> Revision 272</li>
<li><a href="http://lab.polygonal.de/ds/">Polygonal datastructures</a> Version 1.04<br />
The ActionScript version of the polygonal data structures is not further developed and has been ported to the haXe language with the claim to be faster. However, some of the haXe structures did not support primitive values (Heap, BST), so I test here the last ActionScript version.
</li>
</ul>
<h4 id="note">Note to the performance tests in this article</h4>
<p>This article contains a number of performance test results. The tests have been executed using a small testing harness which can be found at the <a href="http://code.google.com/p/sibirjak/source/browse/#svn/trunk/asperform/com/sibirjak/asperform">sibirjak google code page</a>. The column header of the tables showing those results use the following abbreviations. The measured time is displayed in milliseconds.</p>
<table class='simple_table'>
<tr>
<td>+</td>
<td>add</td>
</tr>
<tr>
<td>+A</td>
<td>addFirst</td>
</tr>
<tr>
<td>Z+</td>
<td>addLast</td>
</tr>
<tr>
<td>-</td>
<td>remove</td>
</tr>
<tr>
<td>-A</td>
<td>removeFirst</td>
</tr>
<tr>
<td>Z-</td>
<td>removeLast</td>
</tr>
<tr>
<td>?</td>
<td>has</td>
</tr>
<tr>
<td>?k</td>
<td>hasKey</td>
</tr>
<tr>
<td>-k</td>
<td>removeKey</td>
</tr>
</table>
<h4>Linked list</h4>
<p>The performance of the A3Commons and Dpdk lists is nearly equal. Adding to the polygonal list takes twice the time than to the others.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+A </th>
<th>Z+ </th>
<th>-A </th>
<th>Z- </th>
</tr>
<tr class='heading'>
<td colspan='5'>5000 Items</td>
</tr>
<tr>
<td>AS3Commons LinkedList</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Dpdk LinkedList</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Polygonal DLinkedList</td>
<td>5</td>
<td>3</td>
<td>0</td>
<td>0</td>
</tr>
<tr class='heading'>
<td colspan='5'>10000 Items</td>
</tr>
<tr>
<td>AS3Commons LinkedList</td>
<td>4</td>
<td>2</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Dpdk LinkedList</td>
<td>2</td>
<td>2</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Polygonal DLinkedList</td>
<td>6</td>
<td>8</td>
<td>0</td>
<td>0</td>
</tr>
<tr class='heading'>
<td colspan='5'>50000 Items</td>
</tr>
<tr>
<td>AS3Commons LinkedList</td>
<td>16</td>
<td>16</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>Dpdk LinkedList</td>
<td>17</td>
<td>17</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>Polygonal DLinkedList</td>
<td>34</td>
<td>34</td>
<td>1</td>
<td>1</td>
</tr>
<tr class='heading'>
<td colspan='5'>100000 Items</td>
</tr>
<tr>
<td>AS3Commons LinkedList</td>
<td>28</td>
<td>28</td>
<td>3</td>
<td>3</td>
</tr>
<tr>
<td>Dpdk LinkedList</td>
<td>27</td>
<td>26</td>
<td>3</td>
<td>3</td>
</tr>
<tr>
<td>Polygonal DLinkedList</td>
<td>69</td>
<td>81</td>
<td>3</td>
<td>3</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsLinkedListTest.as">AS3Commons LinkedList tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/dpdk/DpdkLinkedListTest.as">Dpdk LinkedList tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/polygonal/PolygonalLinkedListTest.as">Polygonal DLinkedList tests source code</a></p>
<h4>Map</h4>
<p>The AS3Commons and polygonal maps use an internal Dictionary. The dpdk map instead implements a custom hash table (which is of course slower). The dpdk map only allows literal keys. The AS3Commons map consideres mixed typed primitive keys (1 != &#8220;1&#8243;) which the polygonal map treats as equal. The polygonal map stores its items additionally in a linked list to create an iterator in constant time. The other maps populate an array and return then an iterator over that array (linear time).</p>
<p>The Dictionary key type issue is described in the <a href="http://sibirjak.com/blog/index.php/collections/array-dictionary-collections-performace-functionality-reliability/">Dictionary discussion</a>.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?k </th>
<th>-k </th>
</tr>
<tr class='heading'>
<td colspan='4'>5000 Items</td>
</tr>
<tr>
<td>AS3Commons Map</td>
<td>2</td>
<td>0</td>
<td>3</td>
</tr>
<tr>
<td>Dpdk HashMap</td>
<td>15</td>
<td>6</td>
<td>6</td>
</tr>
<tr>
<td>Polygonal HashMap</td>
<td>3</td>
<td>1</td>
<td>3</td>
</tr>
<tr class='heading'>
<td colspan='4'>10000 Items</td>
</tr>
<tr>
<td>AS3Commons Map</td>
<td>3</td>
<td>2</td>
<td>7</td>
</tr>
<tr>
<td>Dpdk HashMap</td>
<td>28</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>Polygonal HashMap</td>
<td>7</td>
<td>1</td>
<td>6</td>
</tr>
<tr class='heading'>
<td colspan='4'>50000 Items</td>
</tr>
<tr>
<td>AS3Commons Map</td>
<td>20</td>
<td>8</td>
<td>54</td>
</tr>
<tr>
<td>Dpdk HashMap</td>
<td>186</td>
<td>70</td>
<td>91</td>
</tr>
<tr>
<td>Polygonal HashMap</td>
<td>36</td>
<td>4</td>
<td>69</td>
</tr>
<tr class='heading'>
<td colspan='4'>100000 Items</td>
</tr>
<tr>
<td>AS3Commons Map</td>
<td>48</td>
<td>16</td>
<td>166</td>
</tr>
<tr>
<td>Dpdk HashMap</td>
<td>432</td>
<td>201</td>
<td>232</td>
</tr>
<tr>
<td>Polygonal HashMap</td>
<td>87</td>
<td>10</td>
<td>171</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsMapTest.as">AS3Commons Map tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/dpdk/DpdklMapTest.as">Dpdk HashMap tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/polygonal/PolygonalMapTest.as">Polygonal HashMap tests source code</a></p>
<h4>Set</h4>
<p>All sets are backed by a Dictionary instance. In difference to the others, the AS3Commons set distinguishes between numeric and literal keys of the same value (1 != &#8220;1&#8243;) wich makes it slightly slower.</p>
<p>The Dictionary key type issue is described in the <a href="http://sibirjak.com/blog/index.php/collections/array-dictionary-collections-performace-functionality-reliability/">Dictionary discussion</a>.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?  </th>
<th>-  </th>
</tr>
<tr class='heading'>
<td colspan='4'>5000 Items</td>
</tr>
<tr>
<td>AS3Commons Set</td>
<td>1</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>Dpdk Set</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>Polygonal Set</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr class='heading'>
<td colspan='4'>10000 Items</td>
</tr>
<tr>
<td>AS3Commons Set</td>
<td>3</td>
<td>2</td>
<td>5</td>
</tr>
<tr>
<td>Dpdk Set</td>
<td>2</td>
<td>0</td>
<td>3</td>
</tr>
<tr>
<td>Polygonal Set</td>
<td>2</td>
<td>1</td>
<td>3</td>
</tr>
<tr class='heading'>
<td colspan='4'>50000 Items</td>
</tr>
<tr>
<td>AS3Commons Set</td>
<td>16</td>
<td>7</td>
<td>28</td>
</tr>
<tr>
<td>Dpdk Set</td>
<td>10</td>
<td>2</td>
<td>30</td>
</tr>
<tr>
<td>Polygonal Set</td>
<td>13</td>
<td>4</td>
<td>30</td>
</tr>
<tr class='heading'>
<td colspan='4'>100000 Items</td>
</tr>
<tr>
<td>AS3Commons Set</td>
<td>29</td>
<td>16</td>
<td>138</td>
</tr>
<tr>
<td>Dpdk Set</td>
<td>25</td>
<td>4</td>
<td>85</td>
</tr>
<tr>
<td>Polygonal Set</td>
<td>27</td>
<td>9</td>
<td>90</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsSetTest.as">AS3Commons Set tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/dpdk/DpdkSetTest.as">Dpdk Set tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/polygonal/PolygonalSetTest.as">Polygonal Set tests source code</a></p>
<h4>Binary search tree</h4>
<p>The polygonal tree did throw errors when trying to remove items. The performance of removals could therefore not be tested.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?  </th>
<th>-  </th>
</tr>
<tr class='heading'>
<td colspan='4'>1000 Items</td>
</tr>
<tr>
<td>AS3Commons Treap</td>
<td>11</td>
<td>9</td>
<td>13</td>
</tr>
<tr>
<td>Dpdk BST</td>
<td>14</td>
<td>14</td>
<td>12</td>
</tr>
<tr>
<td>Polygonal BST</td>
<td>11</td>
<td>21</td>
<td>-</td>
</tr>
<tr class='heading'>
<td colspan='4'>5000 Items</td>
</tr>
<tr>
<td>AS3Commons Treap</td>
<td>67</td>
<td>59</td>
<td>101</td>
</tr>
<tr>
<td>Dpdk BST</td>
<td>86</td>
<td>84</td>
<td>76</td>
</tr>
<tr>
<td>Polygonal BST</td>
<td>72</td>
<td>127</td>
<td>-</td>
</tr>
<tr class='heading'>
<td colspan='4'>10000 Items</td>
</tr>
<tr>
<td>AS3Commons Treap</td>
<td>149</td>
<td>131</td>
<td>239</td>
</tr>
<tr>
<td>Dpdk BST</td>
<td>216</td>
<td>215</td>
<td>194</td>
</tr>
<tr>
<td>Polygonal BST</td>
<td>171</td>
<td>320</td>
<td>-</td>
</tr>
</table>
<p>The AS3Commons Treap is a randomised tree with a weak addiction to degenerate. Both other trees are neither randomised nor balanced. Adding already sorted data causes here the tree to make up a sequence where each node has only one child.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?  </th>
<th>-  </th>
</tr>
<tr class='heading'>
<td colspan='4'>1000 Items sorted</td>
</tr>
<tr>
<td>AS3Commons Treap</td>
<td>7</td>
<td>8</td>
<td>15</td>
</tr>
<tr>
<td>Dpdk BST</td>
<td>602</td>
<td>592</td>
<td>285</td>
</tr>
<tr>
<td>Polygonal BST</td>
<td>477</td>
<td>468</td>
<td>-</td>
</tr>
<tr class='heading'>
<td colspan='4'>5000 Items sorted</td>
</tr>
<tr>
<td>AS3Commons Treap</td>
<td>37</td>
<td>60</td>
<td>104</td>
</tr>
<tr class='heading'>
<td colspan='4'>10000 Items sorted</td>
</tr>
<tr>
<td>AS3Commons Treap</td>
<td>84</td>
<td>131</td>
<td>259</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsTreapTest.as">AS3Commons Treap tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/dpdk/DpdkBinarySearchTreeTest.as">Dpdk BST tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/polygonal/PolygonalBinarySearchTreeTest.as">Polygonal BST tests source code</a></p>
<h4>Priority queue</h4>
<p>A priority queue provides fast access to the lowest (or highest) item. Dpdk and polygonal contain a arrayed heap implementation. A heap is probably the fastest way to solve the problem. Using an arrayed heap has to consider the time to shift all succeeding array elements when removing the first. The AS3Commons Treap is expensive in adding items but fast in removing (and has a better cumulative performance).</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>-A </th>
</tr>
<tr class='heading'>
<td colspan='3'>5000 Items</td>
</tr>
<tr>
<td>AS3Commons Treap</td>
<td>65</td>
<td>3</td>
</tr>
<tr>
<td>Dpdk PriorityQueue</td>
<td>14</td>
<td>116</td>
</tr>
<tr>
<td>Polygonal Heap</td>
<td>12</td>
<td>99</td>
</tr>
<tr class='heading'>
<td colspan='3'>10000 Items</td>
</tr>
<tr>
<td>AS3Commons Treap</td>
<td>142</td>
<td>7</td>
</tr>
<tr>
<td>Dpdk PriorityQueue</td>
<td>30</td>
<td>262</td>
</tr>
<tr>
<td>Polygonal Heap</td>
<td>24</td>
<td>221</td>
</tr>
<tr class='heading'>
<td colspan='3'>50000 Items</td>
</tr>
<tr>
<td>AS3Commons Treap</td>
<td>896</td>
<td>38</td>
</tr>
<tr>
<td>Dpdk PriorityQueue</td>
<td>157</td>
<td>1658</td>
</tr>
<tr>
<td>Polygonal Heap</td>
<td>132</td>
<td>1351</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsTreapTest.as">AS3Commons Treap tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/dpdk/DpdkPriorityQueueTest.as">Dpdk PriorityQueue tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/polygonal/PolygonalHeapTest.as">Polygonal Heap tests source code</a></p>
<h4>Sorted list</h4>
<p>Both tested lists use an array with a binary search algorithm. However, the dpdk list applies a full sort after each insertion operation which is exeptional slow.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?  </th>
<th>-  </th>
<th>-A </th>
<th>Z- </th>
</tr>
<tr class='heading'>
<td colspan='6'>500 Items</td>
</tr>
<tr>
<td>AS3Commons SortedList</td>
<td>3</td>
<td>4</td>
<td>4</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Dpdk OrderedList</td>
<td>195</td>
<td>4</td>
<td>3</td>
<td>0</td>
<td>0</td>
</tr>
<tr class='heading'>
<td colspan='6'>1000 Items</td>
</tr>
<tr>
<td>AS3Commons SortedList</td>
<td>8</td>
<td>8</td>
<td>8</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Dpdk OrderedList</td>
<td>783</td>
<td>8</td>
<td>8</td>
<td>1</td>
<td>1</td>
</tr>
<tr class='heading'>
<td colspan='6'>2000 Items</td>
</tr>
<tr>
<td>AS3Commons SortedList</td>
<td>19</td>
<td>16</td>
<td>17</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>Dpdk OrderedList</td>
<td>3174</td>
<td>19</td>
<td>19</td>
<td>3</td>
<td>2</td>
</tr>
<tr class='heading'>
<td colspan='6'>10000 Items</td>
</tr>
<tr>
<td>AS3Commons SortedList</td>
<td>123</td>
<td>104</td>
<td>114</td>
<td>25</td>
<td>0</td>
</tr>
<tr class='heading'>
<td colspan='6'>50000 Items</td>
</tr>
<tr>
<td>AS3Commons SortedList</td>
<td>1015</td>
<td>620</td>
<td>998</td>
<td>777</td>
<td>1</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsTreapTest.as">AS3Commons SortedList tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/dpdk/DpdkOrderedListTest.as">Dpdk OrderedList tests source code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sibirjak.com/blog/index.php/collections/collections-framework-performance-comparision/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Array, Dictionary, Collections &#8211; Performance, Functionality, Reliability</title>
		<link>http://sibirjak.com/blog/index.php/collections/array-dictionary-collections-performace-functionality-reliability/</link>
		<comments>http://sibirjak.com/blog/index.php/collections/array-dictionary-collections-performace-functionality-reliability/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 13:10:44 +0000</pubDate>
		<dc:creator>Jens Struwe</dc:creator>
				<category><![CDATA[Collections]]></category>

		<guid isPermaLink="false">http://sibirjak.com/blog/?p=606</guid>
		<description><![CDATA[This post is the continuation of the basic knowledge article and introduces you to the benefits of collections more from a technical perspective. Table of contents Note to the performance tests in this article Definitions and overview Aspects of using data containers Array and Dictionary &#8211; features and weaknesses Common collections and their implementation ArrayList, [...]]]></description>
			<content:encoded><![CDATA[<p>This post is the continuation of the basic knowledge article <a href="http://sibirjak.com/blog/index.php/collections/why-we-need-a-collection-framework-in-actionscript/">Why we need a collection framework in ActionScript</a> and introduces you to the benefits of collections more from a technical perspective.</p>
<p><span id="more-606"></span></p>
<h4>Table of contents</h4>
<ul>
<li><a href="#note">Note to the performance tests in this article</a></li>
<li><a href="#overview">Definitions and overview</a></li>
<li><a href="#aspects">Aspects of using data containers</a></li>
<li><a href="#array_dictionary">Array and Dictionary &#8211; features and weaknesses</a></li>
<li><a href="#collections">Common collections and their implementation</a>
<ul>
<li>ArrayList, SortedList</li>
<li>Map, OrderedMap, SortedMap</li>
<li>Set, OrderedSet, SortedSet</li>
<li>LinkedList, Tree</li>
</ul>
</li>
<li><a href="#summary">Summary</a>
</ul>
<h4 id="note">Note to the performance tests in this article</h4>
<p>This article contains a number of performance test results. The tests have been executed using a small testing harness which can be found at the <a href="http://code.google.com/p/sibirjak/source/browse/#svn/trunk/asperform/com/sibirjak/asperform">sibirjak google code page</a>. The column header of the tables showing those results use the following abbreviations. The measured time is displayed in milliseconds.</p>
<table class='simple_table'>
<tr>
<td>+</td>
<td>add</td>
</tr>
<tr>
<td>+A</td>
<td>addFirst</td>
</tr>
<tr>
<td>Z+</td>
<td>addLast</td>
</tr>
<tr>
<td>-</td>
<td>remove</td>
</tr>
<tr>
<td>-A</td>
<td>removeFirst</td>
</tr>
<tr>
<td>Z-</td>
<td>removeLast</td>
</tr>
<tr>
<td>?</td>
<td>has</td>
</tr>
<tr>
<td>?k</td>
<td>hasKey</td>
</tr>
<tr>
<td>-k</td>
<td>removeKey</td>
</tr>
</table>
<h4 id="overview">Definitions and overview</h4>
<p><strong>Definitions</strong></p>
<p>First of all a small definition of the term collection used in this article. A data container is meant any data structure that holds a number of distinctive objects in order to return at a later time. The built-in data containers in Flash are Array, Vector, Object and Dictionary. A collection is then furthermore a data container &#8230;</p>
<ul>
<li>with a generalised API that fully abstracts from the actual implementation</li>
<li>and a high degree of reusablility (not narrowed to a special operation purpose).</li>
</ul>
<p>Collections do not try to replace the built-in containers but aim to extend those with functionality and common algorithms. Many programming languages carry a collections framework in its core libraries. In ActionScript we unfortunately need to implement collections individually. This situation has brought us already a lot of approaches to establish an ActionScript collections framework.</p>
<p><strong>Common reasons to use collections</strong></p>
<p>Besides the availability of a convenient API, collections are preferred to add specific functionality, to gain reliability or to increase the performance of certain operations. Especially the latter might be confusing at the first glance. Indeed, all built-in containers have their specific implementation and therefore distinctive benefits and disadvantages.</p>
<p>This article shows how the choice of an appropiate collection may improve the runtime performance of ActionScript applications by providing interesting examples and performance test results. The article starts with a description of situations where we typically use containers to collect data and what the different requirements to such containers are. The second part examines the built-in Array and Dictionary and how they can fit the indentified requirements. The third (and last) part discusses several collections and common approaches to implement them.</p>
<h4 id="aspects">Aspects of using data containers</h4>
<p>Software applications may need to collect data for various reasons. Each of those reasons implies a preferred way how elements are stored, retrieved or removed from the data container. Different problem situations may be solved best using an adequate container or vice versa, there is no multipurpose container that fits all kinds of requirements. This chapter shows a random list of situations where we typically use data containers.</p>
<p><strong>Embedded inventory</strong></p>
<p>The most obvious use case of collecting data is to make up a (hard coded) inventory which serves as a data base in the class or even in the entire application. The data in the inventory should have a stable order and provide at least fast sequential access (from the first to the last item).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> users <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span>
    <span style="color: #0033ff; font-weight: bold;">new</span> User<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Mike&quot;</span>, <span style="color: #990000;">&quot;Donner&quot;</span><span style="color: #000000;">&#41;</span>,
    <span style="color: #0033ff; font-weight: bold;">new</span> User<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Susi&quot;</span>, <span style="color: #990000;">&quot;Sonnenschein&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#93;</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> user <span style="color: #000000; font-weight: bold;">:</span> User <span style="color: #0033ff; font-weight: bold;">in</span> users<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #009900;">// do something</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Proxy</strong></p>
<p>A proxy is an internal representation (or a cache) of data stored elsewhere, e.g. on a remote server. The proxy should use the same ordering as the orginal repository. Since data between client and server is exchanged and identified using an object ID, we like to address (find, add, remove) items in the proxy by using IDs.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> users <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = UserService.getUsers<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> user <span style="color: #000000; font-weight: bold;">:</span> User;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> id <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #0033ff; font-weight: bold;">in</span> users<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    user = UserService.getUser<span style="color: #000000;">&#40;</span>id<span style="color: #000000;">&#41;</span>;
    <span style="color: #009900;">// do something</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Relations between objects</strong></p>
<p>One-to-many relations can be expressed using a link table. The table do not need to have an order but should allow fast look up a relation by a given object.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> friends <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
...
friends<span style="color: #000000;">&#91;</span>user1<span style="color: #000000;">&#93;</span> = <span style="color: #000000;">&#91;</span>user2, user4<span style="color: #000000;">&#93;</span>;
friends<span style="color: #000000;">&#91;</span>user2<span style="color: #000000;">&#93;</span> = <span style="color: #000000;">&#91;</span>user1, user3<span style="color: #000000;">&#93;</span>;
...
<span style="color: #6699cc; font-weight: bold;">var</span> friends <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = friends<span style="color: #000000;">&#91;</span>user3<span style="color: #000000;">&#93;</span>;</pre></td></tr></table></div>

<p><strong>Wrapper</strong></p>
<p>Encapsulated components often store data in its own fashion by adding specific information to the given data objects using composition. To enable the user to operate the component with the orginal data, the component hosts an internal look-up table which maps objects to its wrappers.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">loader</span>.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;data.xml&quot;</span><span style="color: #000000;">&#41;</span>;
...
<span style="color: #009900;">// decide not to load the data</span>
<span style="color: #004993;">loader</span>.remove<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;data.xml&quot;</span><span style="color: #000000;">&#41;</span>;</pre></td></tr></table></div>

<p><strong>Grouping objects</strong></p>
<p>To return a group of objects from a method (or to pass to) we use a container. In the most of the cases the order of items returned is important.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> getVisits<span style="color: #000000;">&#40;</span>session <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> session <span style="color: #000000; font-weight: bold;">:</span> Session = AuthService.getSession<span style="color: #000000;">&#40;</span>session<span style="color: #000000;">&#41;</span>;
    <span style="color: #6699cc; font-weight: bold;">var</span> user <span style="color: #000000; font-weight: bold;">:</span> User = UserService.getUser<span style="color: #000000;">&#40;</span>session.userId<span style="color: #000000;">&#41;</span>;
    ...
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#91;</span>user.<span style="color: #004993;">name</span>, session.visitCount<span style="color: #000000;">&#93;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Temporary containers</strong></p>
<p>Often we set up local containers temporarily to find duplicates, to count instances, to store items matching a certain criterion or to prepare a data structure before further processing it. Sometimes a plain array does the work, sometimes a look-up container such as Object or Dictionary. In a number of cases we need a combination of both to preserve the original order while achieving fast look-up.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> array <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">3</span>, <span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">3</span>, <span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#93;</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">map</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Object</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Object</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> unique <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> array.<span style="color: #004993;">length</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>array<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span> === <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        unique.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>array<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>array<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>unique<span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 1,3,2,4</span></pre></td></tr></table></div>

<p><strong>More specific software problems</strong></p>
<p>A queue is an ordered container where we want to add at end and to remove at start. In a stack we add and remove always &#8220;at end&#8221;. A searchable index maintains a sort order, and items shall be addressed instantly by instance. And so on.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">queue.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;users.xml&quot;</span><span style="color: #000000;">&#41;</span>;
queue.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;products.xml&quot;</span><span style="color: #000000;">&#41;</span>;
queue.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;prices.xml&quot;</span><span style="color: #000000;">&#41;</span>;
...
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">url</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = queue.poll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// users.xml</span>
<span style="color: #009900;">// load</span>
...
<span style="color: #004993;">url</span> = queue.poll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// products.xml</span>
<span style="color: #009900;">// load</span></pre></td></tr></table></div>

<p><strong>Binding data to user interfaces</strong></p>
<p>Data driven user interface controls (List, SelectBox, DataGrid) often shall be updated automatically if the assigned data source changed. The data container then needs to dispatch change notifications.</p>
<p><strong>Summary</strong></p>
<p>The illustrated situations above show different and often mutually exclusive requirements to the desired data structure solution:</p>
<ul>
<li>The kind of order of the items (no order necessary, order by insertion, sort order).</li>
<li>Sequential (for-loop, iterator) or random access (index, key, item by instance) to the items.</li>
<li>High performance of adding and removing in front (or in between or at end) of a sequence of items.</li>
<li>High performance of finding an element.</li>
<li>Fast access to the lowest or highest element in a collection.</li>
<li>Permission of multiple instances of an element (or not).</li>
<li>Mapping of items by preserving a particular order of the entries.</li>
<li>Enabling data binding by dispatching change notifications.</li>
</ul>
<p>In the most of the situations we especially count only on a specific feature of a data container. This leads to the question if there are containers that fit the particular requirements better than others. The next chapter discusses how the Flash built-in data containers Array, Object and Dictionary might be used (or not) to solve common data handling problems.</p>
<h4 id="array_dictionary">Array and Dictionary &#8211; Features and Weaknesses</h4>
<h5>The Array</h5>
<p>The Array is apparently the fastest possibility of storing elements sequentially. However, adding to (or removing from) an array requires the array to internally shift the position of all succeeding items by the number of elements added. This shifting is the more expensive the more the insertion occurred in front of the array and the longer the array is. Michael Baczynski (polygonal.de) has visulalised this behaviour in <a href="http://lab.polygonal.de/2007/08/13/data-structures-example-linked-lists/">its linked list example</a>.</p>
<p>Another consideration (and common trap) is the time required to find (or remove) an element within an array. Since the array is not a look-up container, the array needs to test each item for equality which is the more expensive the more longer the array is.</p>
<p>The table below shows the runtime of adding or removing at start or at end as well as the performance of the look-up operations has and remove.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>Z+ </th>
<th>Z- </th>
<th>+A </th>
<th>-A </th>
<th>?  </th>
<th>-  </th>
</tr>
<tr class='heading'>
<td colspan='7'>5000 Items</td>
</tr>
<tr>
<td>Array</td>
<td>0</td>
<td>0</td>
<td>5</td>
<td>6</td>
<td>157</td>
<td>64</td>
</tr>
<tr class='heading'>
<td colspan='7'>10000 Items</td>
</tr>
<tr>
<td>Array</td>
<td>0</td>
<td>0</td>
<td>23</td>
<td>25</td>
<td>441</td>
<td>252</td>
</tr>
<tr class='heading'>
<td colspan='7'>50000 Items</td>
</tr>
<tr>
<td>Array</td>
<td>2</td>
<td>1</td>
<td>738</td>
<td>770</td>
<td>11238</td>
<td>6070</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/flash/ArrayTest.as">Array tests source code</a></p>
<h5>Keeping an array sorted</h5>
<p>In many cases a container that maintains a sort order is desired. Such a container stores and returns its items always based on a sort critlerion. Applications could be a phone book, a high score list, a performant searchable index or a priority queue. A simple implementation would be to sort an array after each insertion operation. However, this approach does not scale as the following table shows.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+</th>
</tr>
<tr class='heading'>
<td colspan='2'>100 Items</td>
</tr>
<tr>
<td>Array</td>
<td>17</td>
</tr>
<tr class='heading'>
<td colspan='2'>500 Items</td>
</tr>
<tr>
<td>Array</td>
<td>630</td>
</tr>
<tr class='heading'>
<td colspan='2'>1000 Items</td>
</tr>
<tr>
<td>Array</td>
<td>2746</td>
</tr>
<tr class='heading'>
<td colspan='2'>2000 Items</td>
</tr>
<tr>
<td>Array</td>
<td>12459</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/flash/ArrayTest.as">Array tests source code</a></p>
<p>Another consideration regarding the sorted array. The built-in sort method does not preserve the formerly order of equal items. If it is important to sort equal items in the order they were inserted, the Array.sort() method cannot be used.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> array <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">3</span>, <span style="color: #000000; font-weight:bold;">4</span>, <span style="color: #000000; font-weight:bold;">5</span>, <span style="color: #000000; font-weight:bold;">6</span>, <span style="color: #000000; font-weight:bold;">7</span>, <span style="color: #000000; font-weight:bold;">8</span>, <span style="color: #000000; font-weight:bold;">9</span><span style="color: #000000;">&#93;</span>;
array.<span style="color: #004993;">sort</span><span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>item1 <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span>, item2 <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000; font-weight:bold;">0</span>; <span style="color: #009900;">// all items are equal</span>
<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>array<span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 5,2,3,4,1,6,7,8,9</span></pre></td></tr></table></div>

<h5>The Dictionary</h5>
<p>The Dictionary is a look-up container where elements can be accessed instantly using a unique key. The Dictionary maintains no order of items and does not provide information about the number of elements contained. Operations based on keys perform in nearly constant time. Finding (or removing) of items is significantly slower than done with an array.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?k </th>
<th>-k </th>
<th>?  </th>
<th>-  </th>
</tr>
<tr class='heading'>
<td colspan='6'>5000 Items</td>
</tr>
<tr>
<td>Dictionary</td>
<td>1</td>
<td>1</td>
<td>4</td>
<td>481</td>
<td>437</td>
</tr>
<tr class='heading'>
<td colspan='6'>10000 Items</td>
</tr>
<tr>
<td>Dictionary</td>
<td>1</td>
<td>1</td>
<td>3</td>
<td>1900</td>
<td>1732</td>
</tr>
<tr class='heading'>
<td colspan='6'>50000 Items</td>
</tr>
<tr>
<td>Dictionary</td>
<td>10</td>
<td>4</td>
<td>72</td>
<td>49073</td>
<td>42916</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/flash/DictionaryTest.as">Dictionary tests source code</a></p>
<p>Another consideration of the Dictionary is its missing type safety. While everything is going well with complex keys, a primitive key is stored by its string representation rather than its original value as the following code example shows.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> dict <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
dict<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;one_int&quot;</span>;
dict<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;one_string&quot;</span>;
dict<span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;true_boolean&quot;</span>;
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;true&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true (!)</span>
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>getSize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 3 (!)</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">delete</span> dict<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span>;
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// false</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// false (!)</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;true&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true (!)</span>
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>getSize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 1 (!)</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> getSize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">size</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span>;
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> key <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #0033ff; font-weight: bold;">in</span> dict<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #004993;">size</span><span style="color: #000000; font-weight: bold;">++</span>;
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">size</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The missing type safety may cause serious errors or at least confusion. For example the <a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/actionscript/org/as3commons/collections/utils/ArrayUtils.as#51">algorithm to test if two arrays contain the same elements</a> would not work reliably with an unmodified Dictionary. This algorithm populates a map with the number of occurrences of each element contained by both given arrays.</p>
<h5>Dictionary used as a set</h5>
<p>As shown, Array and Dictionary are basically slow in finding or removing items. Nevertheless, it is possible to assign the actual item (which we want to access instantly) in the key property of a Dictionary entry. All items then have to be unique.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> dict <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
dict<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
dict<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
dict<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;2&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true (!)</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">delete</span> dict<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span>;
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// false</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>dict<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// false (!)</span></pre></td></tr></table></div>

<p>The features of such a set are the same as of the Dictionary: No order, no size information, no type safety &#8230; but a striking performance in locating objects :-).</p>
<h5>Summary</h5>
<p>The Flash containers are sufficiently for the most operations. Nevertheless, there are certain situations where performance, functionality and reliability leave something to be desired.</p>
<p><strong>Performance</strong></p>
<p>Adding or removing items in front of an array is a comparatively slow process. Thus, using an array as a queue is not the optimal solution, and a linked list performs much better (as we will see later in this article).</p>
<p>Finding items in an array or in a Dictionary instance requires linear time (the more elements the more time). As shown in the snippets above, we often want to find an item instantly. Fast item look-up can be achieved by using a Dictionary as a set.</p>
<p>Keeping an Array instance sorted calling its built-in sort after each insertion operation is a serious performance leak.</p>
<p><strong>Functionality</strong></p>
<p>The Dictionary does not reveal how many items it contains. Calculating such a size value can be done only with a loop over the entire contents which requires linear time.</p>
<p>The Dictionary does not provide any order of items. Fast key or item look-up (when used as a set) while maintaining a particular order is natively not possible. To anyhow obtain an ordered or sorted map (or set) we need to combine the Dictionary with an additional container that stores the item order.</p>
<p>Neither Array nor Dictionary support data binding. It is possible to wrap both containers to control all insertion or removal operations and dispatch reliable change notifications.</p>
<p><strong>Reliability</strong></p>
<p>The Array sort method is not stable which may cause confusion or even problems.</p>
<p>The Dictionary stores a primitive key always in its string representation. Different keys that have the same string representation are considered as identical (1 = &#8220;1&#8243;, true = &#8220;true&#8221;). Algorithms that rely on the Dictionary may fail if not considered.</p>
<h4 id="collections">Common collections and their implementation</h4>
<h5>Array wrapper (ArrayList)</h5>
<p>An array wrapper is the most often encountered collection implementation. The most famous array wrapper is the Flex ArrayCollection. There are many reasons to create an ArrayList.</p>
<p>One goal is to control the way how items are added or removed. For example, it is possible to only permit inseration and removal at the end of an array which results then in a stack realisation.<br />
Another goal is the simplification of the Array interface. For example arrayList.addAt(10, item) is fare more intuitive than array.splice(10, 0, item). By the way, who knows the difference between slice and splice without have an eye at the docs?<br />
Often the array wrapper offers additional methods that easify the array handling (count, removeAll, lastIndexOf). The ArrayList might implement a stable sort that is used instead of the not stable built-in array sort.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> arrayList <span style="color: #000000; font-weight: bold;">:</span> ArrayListRaw = <span style="color: #0033ff; font-weight: bold;">new</span> ArrayListRaw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
arrayList.array = <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">3</span>, <span style="color: #000000; font-weight:bold;">4</span>, <span style="color: #000000; font-weight:bold;">5</span>, <span style="color: #000000; font-weight:bold;">6</span>, <span style="color: #000000; font-weight:bold;">7</span>, <span style="color: #000000; font-weight:bold;">8</span>, <span style="color: #000000; font-weight:bold;">9</span><span style="color: #000000;">&#93;</span>;
arrayList.<span style="color: #004993;">sort</span><span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>item1 <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span>, item2 <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000; font-weight:bold;">0</span>; <span style="color: #009900;">// all items are equal</span>
<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>arrayList.array<span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 1,2,3,4,5,6,7,8,9</span></pre></td></tr></table></div>

<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/arraylist/ArrayListRaw.as">Basic array wrapper implementation in ActionScript</a><br />
<a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/examples/ArrayListExample.as">AS3Commons ArrayList usage example</a></p>
<p><strong>Performance</strong></p>
<p>The basic array wrapper has nearly the same runtime as an unwrapped array.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>Z+ </th>
<th>Z- </th>
<th>+A </th>
<th>-A </th>
</tr>
<tr class='heading'>
<td colspan='5'>5000 Items</td>
</tr>
<tr>
<td>ArrayList</td>
<td>0</td>
<td>0</td>
<td>6</td>
<td>6</td>
</tr>
<tr>
<td>Array</td>
<td>1</td>
<td>0</td>
<td>5</td>
<td>5</td>
</tr>
<tr class='heading'>
<td colspan='5'>10000 Items</td>
</tr>
<tr>
<td>ArrayList</td>
<td>1</td>
<td>0</td>
<td>23</td>
<td>25</td>
</tr>
<tr>
<td>Array</td>
<td>0</td>
<td>0</td>
<td>22</td>
<td>25</td>
</tr>
<tr class='heading'>
<td colspan='5'>50000 Items</td>
</tr>
<tr>
<td>ArrayList</td>
<td>2</td>
<td>1</td>
<td>746</td>
<td>773</td>
</tr>
<tr>
<td>Array</td>
<td>2</td>
<td>0</td>
<td>734</td>
<td>777</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/arraylist/ArrayListRawTest.as">Basic array wrapper tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/flash/ArrayTest.as">Array tests source code</a></p>
<h5>Linked list</h5>
<p>A linked list is the most important alternative to an array to achieve a succession of elements. The list is made up of mutually linking nodes where a single node is a plain data object holding a reference to its successor, predecessor and the actual data added.</p>
<p><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/5/5e/Doubly-linked-list.svg/610px-Doubly-linked-list.svg.png" alt="null" width="500" /></p>
<p>Adding or removing of items costs always the same (constant) time because only the links between two or three nodes have to be updated. However, the linked list does not support index access (addAt, getAt, removeAt). Finding elements in a linked list is as expensive as in an array (has, remove).</p>
<p>A linked list is the preferred solution to realise a queue interface. Several data structures utilise a linked list (rather than an array) to maintain element succession.</p>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/linkedlist/LinkedListRaw.as">Basic linked list implementation in ActionScript</a><br />
<a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/examples/LinkedListExample.as">AS3Commons LinkedList usage example</a><br />
<a href="http://en.wikipedia.org/wiki/Linked_list">Linked list at Wikipedia</a></p>
<p><strong>Performance</strong></p>
<p>As the table shows, the average performance of insertion or removal operations of a linked list is significantly better than of an array.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>Z+ </th>
<th>Z- </th>
<th>+A </th>
<th>-A </th>
</tr>
<tr class='heading'>
<td colspan='5'>5000 Items</td>
</tr>
<tr>
<td>LinkedList</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>Array</td>
<td>0</td>
<td>0</td>
<td>5</td>
<td>5</td>
</tr>
<tr class='heading'>
<td colspan='5'>10000 Items</td>
</tr>
<tr>
<td>LinkedList</td>
<td>2</td>
<td>0</td>
<td>2</td>
<td>0</td>
</tr>
<tr>
<td>Array</td>
<td>0</td>
<td>0</td>
<td>22</td>
<td>25</td>
</tr>
<tr class='heading'>
<td colspan='5'>50000 Items</td>
</tr>
<tr>
<td>LinkedList</td>
<td>15</td>
<td>1</td>
<td>13</td>
<td>2</td>
</tr>
<tr>
<td>Array</td>
<td>6</td>
<td>0</td>
<td>736</td>
<td>780</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/linkedlist/LinkedListRawTest.as">Basic linked list tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/flash/ArrayTest.as">Array tests source code</a></p>
<h5>Map</h5>
<p>The (basic) map is an unordered container enabling fast key look-ups. A typical map implementation uses an array to host the values and a hashing function to calculate from a given key the index position where the value should be added (or can be found). This is actually not trivial, and fortunately we have in ActionScript the Dictionary that hides all the implementation details and can be used to create a map collection.</p>
<p>The map extends the Dictionary to add an instant size information and to fix the problem of type unsafety (shown in the Dictionary example above). String typed keys are separately stored in an Object instance which lets decide if a given primitive key really exists.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">map</span> <span style="color: #000000; font-weight: bold;">:</span> MapRaw = <span style="color: #0033ff; font-weight: bold;">new</span> MapRaw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">map</span>.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #990000;">&quot;one_int&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">map</span>.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;1&quot;</span>, <span style="color: #990000;">&quot;one_string&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">map</span>.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span>, <span style="color: #990000;">&quot;true_boolean&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span>.hasKey<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span>.hasKey<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span>.hasKey<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span>.hasKey<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;true&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// false (!)</span>
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span>.<span style="color: #004993;">size</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 3 (!)</span>
&nbsp;
<span style="color: #004993;">map</span>.removeKey<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span>.hasKey<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// false</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span>.hasKey<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true (!)</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span>.hasKey<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span>.hasKey<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;true&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// false (!)</span>
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span>.<span style="color: #004993;">size</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 2 (!)</span></pre></td></tr></table></div>

<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/map/MapRaw.as">Basic map implementation in ActionScript</a><br />
<a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/examples/MapExample.as">AS3Commons Map usage example</a></p>
<p><strong>Performance</strong></p>
<p>The performance of the basic map is comparable to that of the Dictionary.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?k </th>
<th>-k </th>
</tr>
<tr class='heading'>
<td colspan='4'>5000 Items</td>
</tr>
<tr>
<td>Map</td>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>Dictionary</td>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr class='heading'>
<td colspan='4'>10000 Items</td>
</tr>
<tr>
<td>Map</td>
<td>1</td>
<td>2</td>
<td>4</td>
</tr>
<tr>
<td>Dictionary</td>
<td>1</td>
<td>1</td>
<td>2</td>
</tr>
<tr class='heading'>
<td colspan='4'>50000 Items</td>
</tr>
<tr>
<td>Map</td>
<td>9</td>
<td>7</td>
<td>27</td>
</tr>
<tr>
<td>Dictionary</td>
<td>4</td>
<td>3</td>
<td>27</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/map/MapRawTest.as">Basic map tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/flash/DictionaryTest.as">Dictionary tests source code</a></p>
<h5>Set</h5>
<p>The set is in fact a map where only the keys are from interest. The set implementatin follows the same principles as the of the map: An Object is used to store the string typed keys, an instant size informatin is available.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> theSet <span style="color: #000000; font-weight: bold;">:</span> SetRaw = <span style="color: #0033ff; font-weight: bold;">new</span> SetRaw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
theSet.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
theSet.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000000;">&#41;</span>;
theSet.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>theSet.has<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>theSet.has<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>theSet.has<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>theSet.has<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;true&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// false</span>
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>theSet.<span style="color: #004993;">size</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 3</span>
&nbsp;
theSet.remove<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>theSet.has<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// false</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>theSet.has<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>theSet.has<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>theSet.has<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;true&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// false</span>
&nbsp;
<span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>theSet.<span style="color: #004993;">size</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 2</span></pre></td></tr></table></div>

<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/set/SetRaw.as">Basic set implementation in ActionScript</a><br />
<a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/examples/SetExample.as">AS3Commons Set usage example</a></p>
<p><strong>Performance</strong></p>
<p>The look-up operations has and remove operate in nearly constant time.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?  </th>
<th>-  </th>
</tr>
<tr class='heading'>
<td colspan='4'>5000 Items</td>
</tr>
<tr>
<td>Set</td>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>Array</td>
<td>0</td>
<td>109</td>
<td>61</td>
</tr>
<tr class='heading'>
<td colspan='4'>10000 Items</td>
</tr>
<tr>
<td>Set</td>
<td>4</td>
<td>2</td>
<td>4</td>
</tr>
<tr>
<td>Array</td>
<td>0</td>
<td>440</td>
<td>237</td>
</tr>
<tr class='heading'>
<td colspan='4'>50000 Items</td>
</tr>
<tr>
<td>Set</td>
<td>10</td>
<td>7</td>
<td>36</td>
</tr>
<tr>
<td>Array</td>
<td>4</td>
<td>11068</td>
<td>5861</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/set/SetRawTest.as">Basic set tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/flash/ArrayTest.as">Array tests source code</a></p>
<h5>Sorted array</h5>
<p>To get an array to keep a certain sort order it is the most performant solution to add items using the binary search algorithm. The search returns the index position where a given item should be added. Finding an element within the sorted array also uses a binary search.</p>
<p><a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/actionscript/org/as3commons/collections/SortedList.as">AS3Commons SortedList implementation</a><br />
<a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/examples/SortedListExample.as">AS3Commons SortedList usage example</a><br />
<a href="http://en.wikipedia.org/wiki/Binary_search">Binary search algorithm at Wikipedia</a></p>
<p><strong>Performance</strong></p>
<p>The AS3Commons SortedList is an application of a sorted array and used here in the performance tests. Adding items to an array using the binary search algorithm (as the SortedList does) is significantly faster than adding items combined with a subsequent sort.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
</tr>
<tr class='heading'>
<td colspan='2'>100 Items</td>
</tr>
<tr>
<td>SortedList</td>
<td>1</td>
</tr>
<tr>
<td>Array (add+sort)</td>
<td>18</td>
</tr>
<tr class='heading'>
<td colspan='2'>500 Items</td>
</tr>
<tr>
<td>SortedList</td>
<td>9</td>
</tr>
<tr>
<td>Array (add+sort)</td>
<td>609</td>
</tr>
<tr class='heading'>
<td colspan='2'>1000 Items</td>
</tr>
<tr>
<td>SortedList</td>
<td>8</td>
</tr>
<tr>
<td>Array (add+sort)</td>
<td>2770</td>
</tr>
<tr class='heading'>
<td colspan='2'>2000 Items</td>
</tr>
<tr>
<td>SortedList</td>
<td>21</td>
</tr>
<tr>
<td>Array (add+sort)</td>
<td>12529</td>
</tr>
</table>
<p>Adding items to a sorted array is slower than appending items to an unsorted array. Finding or removing elements is faster done with a sorted array.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?  </th>
<th>-  </th>
</tr>
<tr class='heading'>
<td colspan='4'>5000 Items</td>
</tr>
<tr>
<td>SortedList</td>
<td>54</td>
<td>50</td>
<td>52</td>
</tr>
<tr>
<td>Array</td>
<td>0</td>
<td>109</td>
<td>62</td>
</tr>
<tr class='heading'>
<td colspan='4'>10000 Items</td>
</tr>
<tr>
<td>SortedList</td>
<td>139</td>
<td>106</td>
<td>120</td>
</tr>
<tr>
<td>Array</td>
<td>0</td>
<td>439</td>
<td>239</td>
</tr>
<tr class='heading'>
<td colspan='4'>50000 Items</td>
</tr>
<tr>
<td>SortedList</td>
<td>1023</td>
<td>646</td>
<td>1027</td>
</tr>
<tr>
<td>Array</td>
<td>2</td>
<td>11056</td>
<td>6065</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsSortedListTest.as">AS3Commons SortedList tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/flash/ArrayTest.as">Array tests source code</a></p>
<h5>Binary search tree</h5>
<p>A binary search tree is the composite counterpart to a sorted array. The tree is made up of nodes where a single node is a plain data object holding a reference to its parent node, its left and right child and the actual data added. The value of the left child is always lesser, the value of the right child always greater than the value of a parent node.</p>
<p><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/d/da/Binary_search_tree.svg/200px-Binary_search_tree.svg.png" alt="Binary search tree" /></p>
<p>Finding an element in a tree starts with the root node and continues with the left child node if the given value is lesser and with the right node if the given value is greater than the value of the parent node.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> findNode<span style="color: #000000;">&#40;</span>item <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> Node <span style="color: #000000;">&#123;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> node <span style="color: #000000; font-weight: bold;">:</span> Node = _root;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>node<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>item <span style="color: #000000; font-weight: bold;">&lt;</span> node.item<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            node = node.<span style="color: #004993;">left</span>;
        <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>item <span style="color: #000000; font-weight: bold;">&gt;</span> node.item<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            node = node.<span style="color: #004993;">right</span>;
        <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span> node;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>A binary search tree is used (like a sorted array) to achieve a persistant sort order in that finding of elements is comparable fast. The tree might be used as a priority queue where items are stored and returned depending on a given priority. The tree also may be used in combination with other structures to realise a sorted collection such as a sorted map or a sorted set. </p>
<p>The weakness of a binary search tree is its addiction to degenerate. In the worst case the tree consists of only left nodes or only right nodes. Finding elements in a degenerated tree may cost linear time since each node has to be compared. There are several tree implementations that deal with the problem. A treap is one of them.</p>
<p><a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/actionscript/org/as3commons/collections/Treap.as">AS3Commons Treap implementation</a><br />
<a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/examples/TreapExample.as">AS3Commons Treap usage example</a><br />
<a href="http://en.wikipedia.org/wiki/Binary_search_tree">Binary search tree at Wikipedia</a></p>
<p><strong>Performance</strong></p>
<p>The performance test uses the AS3Commons Treap and SortedList collections. It reveals, the binary search tree is not actually faster than a sorted array. However the sorted array suffers from the bad performance of (adding and) removing items in front of an array in general where the tree operations take the same time at all positions.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?  </th>
<th>-  </th>
<th>-A </th>
<th>Z- </th>
</tr>
<tr class='heading'>
<td colspan='6'>5000 Items</td>
</tr>
<tr>
<td>Treap</td>
<td>67</td>
<td>57</td>
<td>109</td>
<td>4</td>
<td>4</td>
</tr>
<tr>
<td>SortedList</td>
<td>53</td>
<td>49</td>
<td>50</td>
<td>6</td>
<td>1</td>
</tr>
<tr class='heading'>
<td colspan='6'>10000 Items</td>
</tr>
<tr>
<td>Treap</td>
<td>146</td>
<td>125</td>
<td>236</td>
<td>7</td>
<td>7</td>
</tr>
<tr>
<td>SortedList</td>
<td>122</td>
<td>106</td>
<td>118</td>
<td>25</td>
<td>0</td>
</tr>
<tr class='heading'>
<td colspan='6'>50000 Items</td>
</tr>
<tr>
<td>Treap</td>
<td>894</td>
<td>809</td>
<td>1613</td>
<td>37</td>
<td>38</td>
</tr>
<tr>
<td>SortedList</td>
<td>1038</td>
<td>630</td>
<td>1022</td>
<td>773</td>
<td>1</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsTreapTest.as">AS3Commons Treap tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsSortedListTest.as">AS3Commons SortedList tests source code</a></p>
<h5>Ordered map</h5>
<p>A basic map does not have any succession order but this order may be realised by combining a map with a linked list where the map internally links a given key with a linked list node.</p>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/map/OrderedMapRaw.as">Basic ordered map implementation in ActionScript</a><br />
<a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/examples/LinkedMapExample.as">AS3Commons LinkedMap usage example</a></p>
<p><strong>Performance</strong></p>
<p>For order related operations, the ordered map requires about the addition of time of a basic map and a linked list. For example removing at start takes 39ms which is the time needed to remove at start from a linked list (2ms) plus the time needed to remove a key from the map (37ms).</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+A </th>
<th>Z+ </th>
<th>-A </th>
<th>Z- </th>
<th>+  </th>
<th>?k </th>
<th>-k </th>
</tr>
<tr class='heading'>
<td colspan='8'>5000 Items</td>
</tr>
<tr>
<td>OrderedMap</td>
<td>2</td>
<td>2</td>
<td>3</td>
<td>2</td>
<td>-</td>
<td>1</td>
<td>3</td>
</tr>
<tr>
<td>Map</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>LinkedList</td>
<td>1</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr class='heading'>
<td colspan='8'>10000 Items</td>
</tr>
<tr>
<td>OrderedMap</td>
<td>8</td>
<td>5</td>
<td>5</td>
<td>5</td>
<td>-</td>
<td>1</td>
<td>5</td>
</tr>
<tr>
<td>Map</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>1</td>
<td>2</td>
<td>5</td>
</tr>
<tr>
<td>LinkedList</td>
<td>4</td>
<td>2</td>
<td>1</td>
<td>0</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr class='heading'>
<td colspan='8'>50000 Items</td>
</tr>
<tr>
<td>OrderedMap</td>
<td>29</td>
<td>27</td>
<td>39</td>
<td>34</td>
<td>-</td>
<td>8</td>
<td>41</td>
</tr>
<tr>
<td>Map</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>8</td>
<td>8</td>
<td>37</td>
</tr>
<tr>
<td>LinkedList</td>
<td>16</td>
<td>12</td>
<td>2</td>
<td>1</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/map/OrderedMapRawTest.as">Basic ordered map tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/map/MapRawTest.as">Basic map tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/linkedlist/LinkedListRawTest.as">Basic linked list tests source code</a></p>
<h5>Ordered set</h5>
<p>A basic set does not have any succession order but this order may be realised by combining a set with a linked list where the set internally links a given item with a linked list node.</p>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/set/OrderedSetRaw.as">Basic ordered set implementation in ActionScript</a><br />
<a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/examples/LinkedSetExample.as">AS3Commons LinkedSet usage example</a></p>
<p><strong>Performance</strong></p>
<p>For order related operations, the ordered set requires about the addition of time of a basic set and a linked list. For example removing at start takes 39ms which is the time needed to remove at start from a linked list (1ms) plus the time needed to remove an item from the set (37ms).</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+A </th>
<th>Z+ </th>
<th>-A </th>
<th>Z- </th>
<th>+  </th>
<th>?  </th>
<th>-  </th>
</tr>
<tr class='heading'>
<td colspan='8'>5000 Items</td>
</tr>
<tr>
<td>OrderedSet</td>
<td>2</td>
<td>2</td>
<td>3</td>
<td>3</td>
<td>-</td>
<td>1</td>
<td>3</td>
</tr>
<tr>
<td>Set</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>LinkedList</td>
<td>2</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr class='heading'>
<td colspan='8'>10000 Items</td>
</tr>
<tr>
<td>OrderedSet</td>
<td>9</td>
<td>8</td>
<td>5</td>
<td>4</td>
<td>-</td>
<td>1</td>
<td>4</td>
</tr>
<tr>
<td>Set</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>1</td>
<td>2</td>
<td>5</td>
</tr>
<tr>
<td>LinkedList</td>
<td>2</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr class='heading'>
<td colspan='8'>50000 Items</td>
</tr>
<tr>
<td>OrderedSet</td>
<td>28</td>
<td>28</td>
<td>39</td>
<td>31</td>
<td>-</td>
<td>8</td>
<td>42</td>
</tr>
<tr>
<td>Set</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>7</td>
<td>8</td>
<td>37</td>
</tr>
<tr>
<td>LinkedList</td>
<td>16</td>
<td>14</td>
<td>1</td>
<td>1</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</table>
<p>While the Array slows down, finding or removing of items is done as fast it can be with an ordered set.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>Z+ </th>
<th>?  </th>
<th>-  </th>
</tr>
<tr class='heading'>
<td colspan='4'>5000 Items</td>
</tr>
<tr>
<td>OrderedSet</td>
<td>3</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>Array</td>
<td>0</td>
<td>110</td>
<td>62</td>
</tr>
<tr class='heading'>
<td colspan='4'>10000 Items</td>
</tr>
<tr>
<td>OrderedSet</td>
<td>7</td>
<td>2</td>
<td>5</td>
</tr>
<tr>
<td>Array</td>
<td>2</td>
<td>440</td>
<td>237</td>
</tr>
<tr class='heading'>
<td colspan='4'>50000 Items</td>
</tr>
<tr>
<td>OrderedSet</td>
<td>34</td>
<td>8</td>
<td>47</td>
</tr>
<tr>
<td>Array</td>
<td>2</td>
<td>10999</td>
<td>5851</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/set/OrderedSetRawTest.as">Basic ordered set tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/set/SetRawTest.as">Basic set tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/examples/linkedlist/LinkedListRawTest.as">Basic linked list tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/flash/ArrayTest.as">Array tests source code</a></p>
<h5>Sorted map</h5>
<p>A basic map does not have any succession order. A sort order may be realised by combining a map with a binary search tree where the map internally links a given key with a tree node.</p>
<p><a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/actionscript/org/as3commons/collections/SortedMap.as">AS3Commons SortedMap implementation</a><br />
<a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/examples/SortedMapExample.as">AS3Commons SortedMap usage example</a></p>
<p><strong>Performance</strong></p>
<p>The performance test uses the AS3Commons SortedMap, Map and Treap implementations. For order related operations, the sorted map requires about the addition of time of a basic map and a treap.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?  </th>
<th>-  </th>
<th>-A </th>
<th>Z- </th>
<th>?k </th>
<th>-k </th>
</tr>
<tr class='heading'>
<td colspan='8'>5000 Items</td>
</tr>
<tr>
<td>SortedMap</td>
<td>71</td>
<td>65</td>
<td>98</td>
<td>6</td>
<td>6</td>
<td>1</td>
<td>10</td>
</tr>
<tr>
<td>Map</td>
<td>3</td>
<td>409</td>
<td>410</td>
<td>-</td>
<td>-</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>Treap</td>
<td>66</td>
<td>58</td>
<td>108</td>
<td>3</td>
<td>3</td>
<td>-</td>
<td>-</td>
</tr>
<tr class='heading'>
<td colspan='8'>10000 Items</td>
</tr>
<tr>
<td>SortedMap</td>
<td>163</td>
<td>141</td>
<td>232</td>
<td>13</td>
<td>12</td>
<td>1</td>
<td>23</td>
</tr>
<tr>
<td>Map</td>
<td>3</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>1</td>
<td>7</td>
</tr>
<tr>
<td>Treap</td>
<td>144</td>
<td>130</td>
<td>249</td>
<td>7</td>
<td>8</td>
<td>-</td>
<td>-</td>
</tr>
<tr class='heading'>
<td colspan='8'>50000 Items</td>
</tr>
<tr>
<td>SortedMap</td>
<td>947</td>
<td>817</td>
<td>2135</td>
<td>101</td>
<td>88</td>
<td>7</td>
<td>181</td>
</tr>
<tr>
<td>Map</td>
<td>22</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>8</td>
<td>55</td>
</tr>
<tr>
<td>Treap</td>
<td>890</td>
<td>786</td>
<td>1855</td>
<td>38</td>
<td>39</td>
<td>-</td>
<td>-</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsSortedMapTest.as">AS3Commons SortedMap tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsMapTest.as">AS3Commons Map tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsTreapTest.as">AS3Commons Treap tests source code</a></p>
<h5>Sorted set</h5>
<p>A basic set does not have any succession order. A sort order may be realised by combining a set with a binary search tree where the set internally links a given item with a tree node.</p>
<p>The difference between a sorted set and a binary search tree is the performance of item based operations. While the tree needs to find a related node within its structure, the sorted set uses an internal Dictionary to instantly access this node.</p>
<p><a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/actionscript/org/as3commons/collections/SortedSet.as">AS3Commons SortedSet implementation</a><br />
<a href="http://code.google.com/p/as3-commons/source/browse/trunk/as3-commons-collections/src/main/examples/SortedSetExample.as">AS3Commons SortedSet usage example</a></p>
<p><strong>Performance</strong></p>
<p>The performance test uses the AS3Commons SortedSet, Set, Treap and SortedList implementations. For item based operations the set is significantly faster than the treap. For all other operations, the sorted set requires about the addition of time of a basic set and a treap.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?  </th>
<th>-  </th>
<th>-A </th>
<th>Z- </th>
</tr>
<tr class='heading'>
<td colspan='6'>5000 Items</td>
</tr>
<tr>
<td>SortedSet</td>
<td>75</td>
<td>0</td>
<td>7</td>
<td>4</td>
<td>4</td>
</tr>
<tr>
<td>Set</td>
<td>1</td>
<td>1</td>
<td>2</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>Treap</td>
<td>70</td>
<td>58</td>
<td>110</td>
<td>3</td>
<td>4</td>
</tr>
<tr class='heading'>
<td colspan='6'>10000 Items</td>
</tr>
<tr>
<td>SortedSet</td>
<td>153</td>
<td>1</td>
<td>15</td>
<td>10</td>
<td>9</td>
</tr>
<tr>
<td>Set</td>
<td>3</td>
<td>1</td>
<td>4</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>Treap</td>
<td>149</td>
<td>132</td>
<td>246</td>
<td>7</td>
<td>8</td>
</tr>
<tr class='heading'>
<td colspan='6'>50000 Items</td>
</tr>
<tr>
<td>SortedSet</td>
<td>916</td>
<td>7</td>
<td>133</td>
<td>68</td>
<td>71</td>
</tr>
<tr>
<td>Set</td>
<td>15</td>
<td>7</td>
<td>33</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>Treap</td>
<td>892</td>
<td>813</td>
<td>1635</td>
<td>38</td>
<td>38</td>
</tr>
</table>
<p>Item based look-up operations (has, remove) are faster in a sorted set than in a sorted array. Removing of items from the sorted array has to take in account the time to shift the internal array indices. Here the sorted set has a far better average performance.</p>
<table class='simple_table'>
<tr>
<th>TestCase</th>
<th>+  </th>
<th>?  </th>
<th>-  </th>
<th>-A </th>
<th>Z- </th>
</tr>
<tr class='heading'>
<td colspan='6'>5000 Items</td>
</tr>
<tr>
<td>SortedSet</td>
<td>69</td>
<td>1</td>
<td>7</td>
<td>4</td>
<td>4</td>
</tr>
<tr>
<td>SortedArray</td>
<td>53</td>
<td>47</td>
<td>51</td>
<td>6</td>
<td>0</td>
</tr>
<tr class='heading'>
<td colspan='6'>10000 Items</td>
</tr>
<tr>
<td>SortedSet</td>
<td>149</td>
<td>1</td>
<td>17</td>
<td>10</td>
<td>9</td>
</tr>
<tr>
<td>SortedArray</td>
<td>122</td>
<td>105</td>
<td>116</td>
<td>25</td>
<td>0</td>
</tr>
<tr class='heading'>
<td colspan='6'>50000 Items</td>
</tr>
<tr>
<td>SortedSet</td>
<td>908</td>
<td>7</td>
<td>118</td>
<td>56</td>
<td>50</td>
</tr>
<tr>
<td>SortedArray</td>
<td>1015</td>
<td>628</td>
<td>1000</td>
<td>782</td>
<td>1</td>
</tr>
</table>
<p><a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsSortedSetTest.as">AS3Commons SortedSet tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsSetTest.as">AS3Commons Set tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsTreapTest.as">AS3Commons Treap tests source code</a><br />
<a href="http://code.google.com/p/sibirjak/source/browse/trunk/asperform/com/sibirjak/asperform/collectiontests/as3commons/AS3CommonsSortedListTest.as">AS3Commons SortedList tests source code</a></p>
<h4 id="summary">Summary</h4>
<p><strong>There is more than just arrays</strong></p>
<p>Array and Dictionary are not the only possibilities to realise data containers in ActionScript. Choosing an alternative to Array and Dictionary is often valuable for the reasons of performance, functionality and reliability.</p>
<p>This article has shown several examples where the the built-in containers do not suffice and what implementations can better solve specific problems. An array wrapper might be used to control the array access and to add functionality, the linked list has a better performance of insertion and removal operations than an array, sorted list or binary search tree are very fast containers to maintain a persistent sort order, a custom map can fix an unsatisfying behaviour of the Dictionary and add introspection, the different set implementations provide fast access by instance, the ordered map saves the insertion order while elements containted by a sorted map are kept in a sort order.</p>
<p><strong>Decide reasonable</strong></p>
<p>All introduced collections have specific benefits and disadvantages. It depends on the special software problem what data container fits the best. Usually we need only a small and specific subset of the entire functionality of a data container. It is worthy to spend some time to analyse the problem and depending on that to choose an appropriate container. The following list suggest a few questions that may be asked.</p>
<ul>
<li>Is any succession of elements required?
<ul>
<li>Could a sorted structure be more performant?</li>
</ul>
</li>
<li>Is random access required (index, key, item by instance)?
<ul>
<li>Yes: What access type could be the best?</li>
<li>No: Are there lot of reads and writes in between a sequential container?</li>
</ul>
</li>
<li>Are duplicates permitted?</li>
</ul>
<p><strong>AS3Commons collaboration project</strong></p>
<p>While in other languages the use of collections is highly popular, it isn&#8217;t in ActionScript. The reason might be a missing standard library. However, the algorithms used to implement collections are general, and the different ActionScript solutions we can find in the web are pretty similiar. Leads to the question, why we still do not have a unified collections framework in ActionScript :-)</p>
<p>The AS3Commons project is a (yes, again another!) community approach to create a repository of reusable ActionScript components. I have contributed to the collections library there. If you have any feedback, you are welcome. Thank you.</p>
<p><a href="http://www.as3commons.org/">AS3Commons collaboration project</a><br />
<a href="http://sibirjak.com/blog/index.php/lite-collections/">AS3Commons Collections homepage</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sibirjak.com/blog/index.php/collections/array-dictionary-collections-performace-functionality-reliability/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AS3Commons Collections</title>
		<link>http://sibirjak.com/blog/index.php/collections/as3commons-collections/</link>
		<comments>http://sibirjak.com/blog/index.php/collections/as3commons-collections/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 16:59:53 +0000</pubDate>
		<dc:creator>Jens Struwe</dc:creator>
				<category><![CDATA[Collections]]></category>

		<guid isPermaLink="false">http://sibirjak.com/blog/?p=560</guid>
		<description><![CDATA[Welcome to the AS3Commons Collections framework &#8211; the successor of the Lite Collections Fx project. Table of contents Quick overview Examples Differences to the Lite Collections Fx Getting started Resources Quick Overview The framework currently contains 10 collections of wich 8 are available as well in a bindable (event dispatching) version. A bindable collection broadcasts [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the AS3Commons Collections framework &#8211; the successor of the Lite Collections Fx project.</p>
<p><span id="more-560"></span></p>
<h4>Table of contents</h4>
<ul>
<li><a href="#overview">Quick overview</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#differences">Differences to the Lite Collections Fx</a></li>
<li><a href="#getting_started">Getting started</a></li>
<li><a href="#resources">Resources</a></li>
</ul>
<h4 id="overview">Quick Overview</h4>
<p>The framework currently contains 10 collections of wich 8 are available as well in a bindable (event dispatching) version. A bindable collection broadcasts change notifications after any modification of its content (add, remove, reorder, empty).</p>
<p>The collections can be classified by their access type (list = index, set = instance, map = key), by their order (unorderd, insertion order, sort order), by their permission of multiple entries of a single instance or by their realisation.</p>
<table class="simple_table">
<tr>
<th>Collection</th>
<th colspan="3">Characteristics</th>
<th>Realisation</th>
</tr>
<tr>
<td></td>
<td>Access</td>
<td>Order</td>
<td>Multiplicity</td>
<td></td>
</tr>
<tr class="st_border_top">
<td>ArrayList</td>
<td>index,<br />sequential</td>
<td>insertion order</td>
<td>multiple items</td>
<td>Array</td>
</tr>
<tr>
<td>SortedList</td>
<td>index,<br />sequential</td>
<td>sort order</td>
<td>multiple items</td>
<td>Array</td>
</tr>
<tr class="st_border_top">
<td>Set</td>
<td>instance,<br />sequential</td>
<td>unordered</td>
<td>unique items</td>
<td>Dictionary</td>
</tr>
<tr>
<td>LinkedSet</td>
<td>instance,<br />sequential</td>
<td>insertion order</td>
<td>unique items</td>
<td>Dictionary + LinkedList</td>
</tr>
<tr>
<td>SortedSet</td>
<td>instance,<br />sequential</td>
<td>sort order</td>
<td>unique items,<br />multiple equal items</td>
<td>Dictionary + Tree</td>
</tr>
<tr class="st_border_top">
<td>Map</td>
<td>key,<br />sequential</td>
<td>unordered</td>
<td>unique keys,<br />multiple items</td>
<td>Dictionary</td>
</tr>
<tr>
<td>LinkedMap</td>
<td>key,<br />sequential</td>
<td>insertion order</td>
<td>unique keys,<br />multiple items</td>
<td>Dictionary + LinkedList</td>
</tr>
<tr>
<td>SortedMap</td>
<td>key,<br />sequential</td>
<td>sort order</td>
<td>unique keys,<br />multiple items</td>
<td>Dictionary + Tree</td>
</tr>
<tr class="st_border_top">
<td>LinkedList</td>
<td>sequential</td>
<td>insertion order</td>
<td>multiple items</td>
<td>LinkedList</td>
</tr>
<tr>
<td>Treap</td>
<td>instance,<br />sequential</td>
<td>sort order</td>
<td>unique items</td>
<td>Tree</td>
</tr>
</table>
<p>Each collection is equipped with a feature rich iterator that enables bidirectional navigation and insertion, replacement or removal within the iteration loop. The library further includes 5 special iterators:</p>
<ul>
<li>ArrayIterator</li>
<li>CollectionFilterIterator</li>
<li>FilterIterator</li>
<li>RecursiveIterator</li>
<li>RecursiveFilterIterator</li>
</ul>
<p>Note, all collections, iterators and interfaces are detailed described in the <a href="http://sibirjak.com/blog/index.php/lite-collections/">APIDoc</a>.</p>
<h4 id="examples">Examples</h4>
<p>The <a href="http://sibirjak.com/blog/index.php/lite-collections/">APIDoc</a> consists of a large number of examples of all collections (bindable or not bindable). All those examples are also committed to the SVN repository and can be found here: <a href="http://code.google.com/p/as3-commons/source/browse/trunk/#trunk/as3-commons-collections/src/main/examples">Browse examples</a>.</p>
<p><strong>SortedList example</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.SortedList;
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.framework.ICollectionIterator;
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.framework.IIterator;
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.framework.IListIterator;
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.utils.StringComparator;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SortedListExample extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SortedListExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> list <span style="color: #000000; font-weight: bold;">:</span> SortedList = <span style="color: #0033ff; font-weight: bold;">new</span> SortedList<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> StringComparator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #009900;">// Add</span>
&nbsp;
            list.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;d&quot;</span><span style="color: #000000;">&#41;</span>;
            list.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;a&quot;</span><span style="color: #000000;">&#41;</span>;
            list.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;a&quot;</span><span style="color: #000000;">&#41;</span>;
            list.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;f&quot;</span><span style="color: #000000;">&#41;</span>;
            list.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;c&quot;</span><span style="color: #000000;">&#41;</span>;
            list.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;b&quot;</span><span style="color: #000000;">&#41;</span>;
            list.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;a&quot;</span><span style="color: #000000;">&#41;</span>;
            list.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;c&quot;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.toArray<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// a,a,a,b,c,c,d,f</span>
&nbsp;
            list.array = <span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;d&quot;</span>, <span style="color: #990000;">&quot;a&quot;</span>, <span style="color: #990000;">&quot;a&quot;</span>, <span style="color: #990000;">&quot;f&quot;</span>, <span style="color: #990000;">&quot;c&quot;</span>, <span style="color: #990000;">&quot;b&quot;</span>, <span style="color: #990000;">&quot;a&quot;</span>, <span style="color: #990000;">&quot;c&quot;</span><span style="color: #000000;">&#93;</span>;
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.toArray<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// a,a,a,b,c,c,d,f</span>
&nbsp;
            <span style="color: #009900;">// Inspection</span>
&nbsp;
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.first<span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// a</span>
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.last<span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// f</span>
&nbsp;
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.hasEqual<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;a&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.hasEqual<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;e&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// false</span>
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.equalIndices<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;a&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 0,1,2</span>
&nbsp;
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.lesserIndex<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;a&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// -1</span>
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.lesserIndex<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;c&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 3</span>
&nbsp;
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.higherIndex<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;c&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 6</span>
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.higherIndex<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;f&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// -1</span>
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>list.higherIndex<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;x&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// -1</span>
&nbsp;
            <span style="color: #009900;">// Iterator</span>
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> iterator <span style="color: #000000; font-weight: bold;">:</span> IIterator = list.iterator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>iterator <span style="color: #0033ff; font-weight: bold;">is</span> IIterator<span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>iterator <span style="color: #0033ff; font-weight: bold;">is</span> ICollectionIterator<span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>iterator <span style="color: #0033ff; font-weight: bold;">is</span> IListIterator<span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// true</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>iterator.hasNext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>iterator.next<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// a,a,a,b,c,c,d,f</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Filter iterator example</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.ArrayList;
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.framework.IIterator;
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.iterators.FilterIterator;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> FilterIteratorExample extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> FilterIteratorExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> list <span style="color: #000000; font-weight: bold;">:</span> ArrayList = <span style="color: #0033ff; font-weight: bold;">new</span> ArrayList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #6699cc; font-weight: bold;">var</span> iterator <span style="color: #000000; font-weight: bold;">:</span> IIterator;
&nbsp;
            list.array = <span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">3</span>, <span style="color: #000000; font-weight:bold;">4</span>, <span style="color: #000000; font-weight:bold;">5</span>, <span style="color: #000000; font-weight:bold;">6</span><span style="color: #000000;">&#93;</span>;
            iterator = <span style="color: #0033ff; font-weight: bold;">new</span> FilterIterator<span style="color: #000000;">&#40;</span>list, evenFilter<span style="color: #000000;">&#41;</span>;
            <span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>iterator.hasNext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>iterator.next<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// 2, 4, 6</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> evenFilter<span style="color: #000000;">&#40;</span>item <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #009900;">// lets pass only even numbers</span>
            <span style="color: #0033ff; font-weight: bold;">return</span> item <span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight:bold;">2</span> == <span style="color: #000000; font-weight:bold;">0</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Bindable LinkedSet example</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.framework.ISetIterator;
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.fx.LinkedSetFx;
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.fx.events.CollectionEvent;
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.fx.events.SetEvent;
    <span style="color: #0033ff; font-weight: bold;">import</span> org.as3commons.collections.utils.NumericComparator;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LinkedSetFxExample extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LinkedSetFxExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> theSet <span style="color: #000000; font-weight: bold;">:</span> LinkedSetFx = <span style="color: #0033ff; font-weight: bold;">new</span> LinkedSetFx<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            theSet.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>CollectionEvent.COLLECTION_CHANGED, changedHandler<span style="color: #000000;">&#41;</span>;
&nbsp;
            theSet.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
            theSet.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>;
            theSet.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
            theSet.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// no event (2 already contained)</span>
&nbsp;
            theSet.addFirst<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#41;</span>;
            theSet.addLast<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            theSet.addBefore<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">6</span><span style="color: #000000;">&#41;</span>;
            theSet.addAfter<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">7</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            theSet.<span style="color: #004993;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">3</span>, <span style="color: #000000; font-weight:bold;">8</span><span style="color: #000000;">&#41;</span>;
            theSet.<span style="color: #004993;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">9</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            theSet.removeFirst<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            theSet.removeLast<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            theSet.remove<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000000;">&#41;</span>;
            theSet.remove<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">6</span><span style="color: #000000;">&#41;</span>;
            theSet.remove<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// no event (10 not contained)</span>
&nbsp;
            theSet.<span style="color: #004993;">reverse</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            theSet.<span style="color: #004993;">sort</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> NumericComparator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            theSet.<span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #009900;">// [1] added                         [1]</span>
            <span style="color: #009900;">// [3] added after 1                 [1 3]</span>
            <span style="color: #009900;">// [2] added after 3                 [1 3 2]</span>
            <span style="color: #009900;">// [4] added before 1                [4 1 3 2]</span>
            <span style="color: #009900;">// [5] added after 2                 [4 1 3 2 5]</span>
            <span style="color: #009900;">// [6] added after 3 before 2        [4 1 3 6 2 5]</span>
            <span style="color: #009900;">// [7] added after 2 before 5        [4 1 3 6 2 7 5]</span>
            <span style="color: #009900;">// [8] replaced after 1 before 6     [4 1 8 6 2 7 5]</span>
            <span style="color: #009900;">// [9] replaced after 4 before 8     [4 9 8 6 2 7 5]</span>
            <span style="color: #009900;">// [4] removed before 9              [9 8 6 2 7 5]</span>
            <span style="color: #009900;">// [5] removed after 7               [9 8 6 2 7]</span>
            <span style="color: #009900;">// [8] removed after 9 before 6      [9 6 2 7]</span>
            <span style="color: #009900;">// [6] removed after 9 before 2      [9 2 7]</span>
            <span style="color: #009900;">// Reset                             [7 2 9]</span>
            <span style="color: #009900;">// Reset                             [2 7 9]</span>
            <span style="color: #009900;">// Reset                             []</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> changedHandler<span style="color: #000000;">&#40;</span>e <span style="color: #000000; font-weight: bold;">:</span> SetEvent<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&quot;</span>;
            <span style="color: #6699cc; font-weight: bold;">var</span> iterator <span style="color: #000000; font-weight: bold;">:</span> ISetIterator;
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>e.kind<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">case</span> CollectionEvent.ITEM_ADDED<span style="color: #000000; font-weight: bold;">:</span>
                    <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;[&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> e.item <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;] added&quot;</span>;
&nbsp;
                    iterator = e.iterator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> ISetIterator;
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>iterator.previousItem <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot; after &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> iterator.previousItem;
                    iterator.next<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>iterator.nextItem <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot; before &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> iterator.nextItem;
                    <span style="color: #0033ff; font-weight: bold;">break</span>;
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">case</span> CollectionEvent.ITEM_REMOVED<span style="color: #000000; font-weight: bold;">:</span>
                    <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;[&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> e.item <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;] removed&quot;</span>;
&nbsp;
                    iterator = e.iterator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> ISetIterator;
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>iterator.previousItem <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot; after &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> iterator.previousItem;
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>iterator.nextItem <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot; before &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> iterator.nextItem;
                    <span style="color: #0033ff; font-weight: bold;">break</span>;
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">case</span> CollectionEvent.ITEM_REPLACED<span style="color: #000000; font-weight: bold;">:</span>
                    <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;[&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> e.item <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;] replaced&quot;</span>;
&nbsp;
                    iterator = e.iterator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> ISetIterator;
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>iterator.previousItem <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot; after &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> iterator.previousItem;
                    iterator.next<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>iterator.nextItem <span style="color: #000000; font-weight: bold;">!</span>== <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot; before &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> iterator.nextItem;
                    <span style="color: #0033ff; font-weight: bold;">break</span>;
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">case</span> CollectionEvent.RESET<span style="color: #000000; font-weight: bold;">:</span>
                    <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Reset&quot;</span><span style="color: #000000;">&#41;</span>;
                    <span style="color: #0033ff; font-weight: bold;">break</span>;
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = <span style="color: #004993;">info</span>.<span style="color: #004993;">length</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">34</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot; &quot;</span>;
            <span style="color: #004993;">info</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;[&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> e.<span style="color: #0033ff; font-weight: bold;">set</span>.toArray<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">join</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot; &quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;]&quot;</span>;
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">info</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h4 id="differences">Differences to the Lite Collections Fx</h4>
<p><strong>Architectural changes</strong></p>
<p>A list is now considered as a collection that provides (constant time) index access to its items. Therefore the LinkedList does not implement the IList interface any longer.</p>
<p>List, sets and maps are now considered as &#8220;random access collections&#8221; &#8211; providing a unique accessor to their items (index, item by instance, key). Therefore all lists, sets and maps have now a bindable version.</p>
<p><strong>Performance increasement</strong></p>
<p>The performance has been increased by a factor of 2 to 4 (partially even up to 20). A performance testing harness and all testing results will be released in the next time.</p>
<p><strong>Iterator concept improvements</strong></p>
<p>The iterators now have the ability to add or remove items during the iteration. The pointers (special iterators for linked collections) of the Lite Collections have been removed.</p>
<p><strong>More concisely method names</strong></p>
<p>All xxxItem() methods have lost their &#8220;item&#8221;. getItemAt() is now itemAt(), getFirstItem() is now simply first and so on.</p>
<p><strong>Documentation</strong></p>
<p>The APIDoc has been largely extended and contains all information that is necessary to work with the collections.</p>
<h4 id="getting_started">Getting started</h4>
<p>There is not much to get the collections running.</p>
<ol>
<li><a href="http://sibirjak.com/blog/index.php/lite-collections/">Download SWC, ZIP</a> or <a href="http://sibirjak.com/blog/index.php/lite-collections/">checkout the SVN</a> branch.</li>
<li>Link or copy the sources into your project.</li>
<li>Import the collection classes and write code.</li>
<li><a href="http://code.google.com/p/as3-commons/source/browse/trunk/#trunk/as3-commons-collections/src/main/examples">Examples</a>.</li>
</ol>
<h4 id="resources">Resources</h4>
<ul>
<li><a href="http://sibirjak.com/blog/index.php/lite-collections/">Project homepage</a></li>
<li><a href="http://code.google.com/p/as3-commons/source/browse/trunk/#trunk/as3-commons-collections/src/main/examples">Examples</a></li>
<li><a href="http://sibirjak.com/blog/index.php/lite-collections/">APIDoc</a></li>
<li><a href="http://sibirjak.com/blog/index.php/lite-collections/">Download</a> and <a href="http://sibirjak.com/blog/index.php/lite-collections/">SVN repository</a></li>
<li><a href="http://sibirjak.com/blog/index.php/lite-collections/">Bug tracker</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sibirjak.com/blog/index.php/collections/as3commons-collections/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASDPC &#8211; TreeView</title>
		<link>http://sibirjak.com/blog/index.php/asdpc/asdpc-treeview/</link>
		<comments>http://sibirjak.com/blog/index.php/asdpc/asdpc-treeview/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 17:01:29 +0000</pubDate>
		<dc:creator>Jens Struwe</dc:creator>
				<category><![CDATA[ASDPC]]></category>

		<guid isPermaLink="false">http://sibirjak.com/blog/?p=408</guid>
		<description><![CDATA[The TreeView is an extended ListView control with the ability to accept and display hierachical or complex data. The TreeView is equipped with an internal lineariser, which maps the given complex data structure to a linear list by maintaining expanded and collapsed items. The TreeView can be customised in several ways. This document describes all [...]]]></description>
			<content:encoded><![CDATA[<p>The TreeView is an extended ListView control with the ability to accept and display hierachical or complex data. The TreeView is equipped with an internal lineariser, which maps the given complex data structure to a linear list by maintaining expanded and collapsed items. The TreeView can be customised in several ways. This document describes all the possibilities to configure a TreeView control.</p>
<p><span id="more-408"></span></p>
<ul>
<li><a href="#demo">TreeView demo application</a></li>
<li><a href="#data">Setting up the data</a></li>
<li><a href="#label">Creating a label function</a></li>
<li><a href="#interface">Using the public interface</a></li>
<li><a href="#styles">Styling the TreeView</a></li>
<li><a href="#icons">Setting custom icons</a></li>
</ul>
<h4 id="demo">TreeView demo application</h4>
<p>Click the image below for an interactive interface demo of the TreeView control. The demo lets you change data, styles and functionality of the component and provides information about the events dispatched and styles set.</p>
<p><a href="#" onClick='popup( "http://sibirjak.com/projects/asdpc/examples/TreeViewInterfaceDemo.html", 800, 600 ); return false;'><img src="http://sibirjak.com/blog/wp-content/uploads/2010/02/treeviewdemo.png" alt="" title="treeviewdemo" width="400" height="298" class="sibirjak_image" /></a></p>
<p>If the popup does not do well, <a href="http://sibirjak.com/projects/asdpc/examples/TreeViewInterfaceDemoFullSize.html">click here</a>.</p>
<h4 id="data">Setting up the data</h4>
<p>The TreeView can work with any kind of hierachical data. There is no restriction in the type of the particular data source items. Its also possible to mix different types in one data source. The TreeView only needs to know for each item, how many children it contains (numItems) and how to get a child item at a specific index (getItemAt). There are three ways to provide this information.</p>
<ol>
<li>Using a supported data source type without any preperation.</li>
<li>Implementing the IDataProvider interface in all item classes, if you are free in designing the data source.</li>
<li>Setting up a data source adapter, if you want to use a given (closed) object as the data source of the tree.</li>
</ol>
<h5>Using a supported data source</h5>
<p>The TreeView already comes with support for a few types, from that it automatically extracts the numItems and getItemAt information.</p>
<ul>
<li>XML</li>
<li>Array</li>
<li>All maps, sets and the ArrayList from the AS3Commons Collections package</li>
</ul>
<p>Look at the <a href="http://code.google.com/p/as-dataprovider-controls/source/browse/trunk/src/com/sibirjak/asdpc/core/dataprovider/DataSourceAdapterFactory.as">DataSourceAdapterFactory.as</a> and see, how the TreeView handles the different item types. The example below shows an XML acting as the data source of the TreeView.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.treeview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> TreeViewExample extends Example <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TreeViewExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> treeView <span style="color: #000000; font-weight: bold;">:</span> TreeView = <span style="color: #0033ff; font-weight: bold;">new</span> TreeView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            treeView.dataSource = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span>
                <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Root&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1_1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1_2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;/</span>item<span style="color: #000000; font-weight: bold;">&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;/</span>item<span style="color: #000000; font-weight: bold;">&gt;</span>
            <span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>treeView<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="320" height="120">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/TreeViewExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/TreeViewExample.swf" width="320" height="120">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h5>Implementing the data provider interface</h5>
<p>The two requirements above are modelled in a very small IDataProvider interface.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.core.dataprovider <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> interface IDataProvider <span style="color: #000000;">&#123;</span>
        <span style="color: #339966; font-weight: bold;">function</span> getItemAt<span style="color: #000000;">&#40;</span><span style="color: #004993;">index</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span>;
        <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> numItems<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Building a complex data source by implementing this interface is easy and may look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.treeview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SimpleDataProviderExample extends Example <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SimpleDataProviderExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> dataSource <span style="color: #000000; font-weight: bold;">:</span> Node = <span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Root&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> node_1 <span style="color: #000000; font-weight: bold;">:</span> Node = <span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_1&quot;</span><span style="color: #000000;">&#41;</span>;
            node_1.addNode<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_1_1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
            node_1.addNode<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_1_2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
            dataSource.addNode<span style="color: #000000;">&#40;</span>node_1<span style="color: #000000;">&#41;</span>;
&nbsp;
            dataSource.addNode<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> treeView <span style="color: #000000; font-weight: bold;">:</span> TreeView = <span style="color: #0033ff; font-weight: bold;">new</span> TreeView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            treeView.dataSource = dataSource;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>treeView<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.core.dataprovider.IDataProvider;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #9900cc; font-weight: bold;">class</span> Node implements IDataProvider <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _name <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span>;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _childNodes <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Node<span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        _name = <span style="color: #004993;">name</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> addNode<span style="color: #000000;">&#40;</span>node <span style="color: #000000; font-weight: bold;">:</span> Node<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
        _childNodes.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>node<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> getItemAt<span style="color: #000000;">&#40;</span><span style="color: #004993;">index</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> _childNodes<span style="color: #000000;">&#91;</span><span style="color: #004993;">index</span><span style="color: #000000;">&#93;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> numItems<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> _childNodes.<span style="color: #004993;">length</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> _name;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="320" height="120">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/SimpleDataProviderExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/SimpleDataProviderExample.swf" width="320" height="120">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h5>Creating a data source adapter</h5>
<p>If the data source cannot implement the IDataProvider interace, it is necessary to write a custom data source adapter by implementing the IDataSourceAdapter interface. The adapter accepts an item from the original data source and knows how to retrieve numItems and getItemAt information from this item.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.core.dataprovider <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> interface IDataSourceAdapter extends IDataProvider <span style="color: #000000;">&#123;</span>
        <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> dataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span>;
        <span style="color: #339966; font-weight: bold;">function</span> cleanUp<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Creating a custom data source adapter is a two-step procedure.</p>
<ol>
<li>Creating the adapter</li>
<li>Creating a data source adapter factory function</li>
</ol>
<p>Creating an adapter is as simple as it could be. Let&#8217;s assume our data source item is a Node object.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #9900cc; font-weight: bold;">class</span> Node <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _name <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span>;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _childNodes <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Node<span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        _name = <span style="color: #004993;">name</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> addNode<span style="color: #000000;">&#40;</span>node <span style="color: #000000; font-weight: bold;">:</span> Node<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
        _childNodes.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>node<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> _name;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">childNodes</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> _childNodes;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The data source adapter then will look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.core.dataprovider.IDataSourceAdapter;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #9900cc; font-weight: bold;">class</span> NodeAdapter implements IDataSourceAdapter <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _node <span style="color: #000000; font-weight: bold;">:</span> Node;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> NodeAdapter<span style="color: #000000;">&#40;</span>node <span style="color: #000000; font-weight: bold;">:</span> Node<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        _node = node;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> dataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> _node;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> getItemAt<span style="color: #000000;">&#40;</span><span style="color: #004993;">index</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> _node.<span style="color: #004993;">childNodes</span><span style="color: #000000;">&#91;</span><span style="color: #004993;">index</span><span style="color: #000000;">&#93;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> numItems<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> _node.<span style="color: #004993;">childNodes</span>.<span style="color: #004993;">length</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> cleanUp<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #009900;">// empty</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>We now have to tell the TreeView that it should use the NodeAdapter if it encounters a Node object. To do so, we write da data source adapter function.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> getAdapter<span style="color: #000000;">&#40;</span>item <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> IDataProvider <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>item <span style="color: #0033ff; font-weight: bold;">is</span> Node<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> NodeAdapter<span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span>;
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Finally, we assign this function to the appropriate TreeView property.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.treeview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.core.dataprovider.IDataProvider;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SimpleDataSourceAdapterExample extends Example <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SimpleDataSourceAdapterExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> dataSource <span style="color: #000000; font-weight: bold;">:</span> Node = <span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Root&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> node_1 <span style="color: #000000; font-weight: bold;">:</span> Node = <span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_1&quot;</span><span style="color: #000000;">&#41;</span>;
            node_1.addNode<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_1_1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
            node_1.addNode<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_1_2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
            dataSource.addNode<span style="color: #000000;">&#40;</span>node_1<span style="color: #000000;">&#41;</span>;
&nbsp;
            dataSource.addNode<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> treeView <span style="color: #000000; font-weight: bold;">:</span> TreeView = <span style="color: #0033ff; font-weight: bold;">new</span> TreeView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            treeView.dataSource = dataSource;
            treeView.dataSourceAdapterFunction = getAdapter;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>treeView<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> getAdapter<span style="color: #000000;">&#40;</span>item <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> IDataProvider <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>item <span style="color: #0033ff; font-weight: bold;">is</span> Node<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> NodeAdapter<span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span>;
            <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_2" width="320" height="120">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/SimpleDataSourceAdapterExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/SimpleDataSourceAdapterExample.swf" width="320" height="120">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p><strong>Example: Visualising the display List</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.treeview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.core.dataprovider.IDataProvider;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">DisplayObjectContainer</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> DisplayListExample extends Example <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> DisplayListExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> treeView <span style="color: #000000; font-weight: bold;">:</span> TreeView = <span style="color: #0033ff; font-weight: bold;">new</span> TreeView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            treeView.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">440</span>, <span style="color: #000000; font-weight:bold;">360</span><span style="color: #000000;">&#41;</span>;
            treeView.dataSource = <span style="color: #004993;">stage</span>;
            treeView.dataSourceAdapterFunction = getAdapter;
            treeView.expandNodeAt<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>treeView<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> getAdapter<span style="color: #000000;">&#40;</span>item <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> IDataProvider <span style="color: #000000;">&#123;</span>
             <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>item <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                 <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> DOCAdapter<span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span>;
             <span style="color: #000000;">&#125;</span>
             <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.core.dataprovider.IDataSourceAdapter;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">DisplayObjectContainer</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #9900cc; font-weight: bold;">class</span> DOCAdapter implements IDataSourceAdapter <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _view <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">DisplayObjectContainer</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> DOCAdapter<span style="color: #000000;">&#40;</span>view <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        _view = view;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> dataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> _view;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> getItemAt<span style="color: #000000;">&#40;</span><span style="color: #004993;">index</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> _view.<span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">index</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> numItems<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> _view.<span style="color: #004993;">numChildren</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> cleanUp<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #009900;">// empty</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_3" width="460" height="380">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/DisplayListExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/DisplayListExample.swf" width="460" height="380">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h4 id="label">Creating a label function</h4>
<p>By default, the TreeView looks for the public properties &#8220;label&#8221; or &#8220;name&#8221; to extract a suitable label text, that can be displayed. Look at the <a href="http://code.google.com/p/as-dataprovider-controls/source/browse/trunk/src/com/sibirjak/asdpc/core/dataprovider/genericToStringFunction.as">genericToStringFunction.as</a> and see, how the TreeView extracts the label text from an item. However, in some cases such a property does not exist or a different than the default value should be displayed. Here it is possible to assign a label function, wich is used instead of the generic toString function.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.treeview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.listview.renderer.ListItemContent;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LabelFunctionExample extends Example <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LabelFunctionExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> dataSource <span style="color: #000000; font-weight: bold;">:</span> Node = <span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Root&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> node_1 <span style="color: #000000; font-weight: bold;">:</span> Node = <span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_1&quot;</span><span style="color: #000000;">&#41;</span>;
            node_1.addNode<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_1_1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
            node_1.addNode<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_1_2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
            dataSource.addNode<span style="color: #000000;">&#40;</span>node_1<span style="color: #000000;">&#41;</span>;
&nbsp;
            dataSource.addNode<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Node_2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> treeView <span style="color: #000000; font-weight: bold;">:</span> TreeView = <span style="color: #0033ff; font-weight: bold;">new</span> TreeView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            treeView.dataSource = dataSource;
            treeView.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span>
                ListItemContent.style.labelFunction, labelFunction
            <span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>treeView<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> labelFunction<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span> <span style="color: #000000; font-weight: bold;">:</span> TreeNodeData<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span> Node<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span>.item<span style="color: #000000;">&#41;</span>.key;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.core.dataprovider.IDataProvider;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #9900cc; font-weight: bold;">class</span> Node implements IDataProvider<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> key <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span>;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">childNodes</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Node<span style="color: #000000;">&#40;</span>theKey <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        key = theKey;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> addNode<span style="color: #000000;">&#40;</span>node <span style="color: #000000; font-weight: bold;">:</span> Node<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #004993;">childNodes</span>.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>node<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> getItemAt<span style="color: #000000;">&#40;</span><span style="color: #004993;">index</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">childNodes</span><span style="color: #000000;">&#91;</span><span style="color: #004993;">index</span><span style="color: #000000;">&#93;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> numItems<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span><span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">childNodes</span>.<span style="color: #004993;">length</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The label function is set as a style with the constant &#8220;ListItemContent.style.labelFunction&#8221; used as the property name. All styles properties within the ASDPC have their particular constant. This can be useful, if your IDE supports property completion. The style &#8220;labelFunction&#8221; is defined for the class ListItemContent, which finally renders the item. More to this in the <a href="#styles">Styling the TreeView</a> section.</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_4" width="320" height="120">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/LabelFunctionExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/LabelFunctionExample.swf" width="320" height="120">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h4 id="interface">Using the public interface</h4>
<p>The public interface of the TreeView control extends the ListView control interface and offers expand/collapse, selection and scroll operations beside the possibilities to set and retrieve data information. Visit the APIdoc for a comprehensive description of the <a href="http://sibirjak.com/projects/asdpc/apidoc/com/sibirjak/asdpc/treeview/ITreeView.html">TreeView interface</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.treeview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> PublicInterfaceExample extends Example <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> PublicInterfaceExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
            <span style="color: #009900;">// Fully expanded</span>
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> treeView <span style="color: #000000; font-weight: bold;">:</span> TreeView = <span style="color: #0033ff; font-weight: bold;">new</span> TreeView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            treeView.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">200</span>, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#41;</span>;
            treeView.dataSource = getDataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            treeView.expandNodeAt<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>treeView<span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #009900;">// Expanded and selected</span>
&nbsp;
            treeView = <span style="color: #0033ff; font-weight: bold;">new</span> TreeView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            treeView.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">200</span>, <span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000;">&#41;</span>;
            treeView.dataSource = getDataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            treeView.expandNodeAt<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
            treeView.selectItemAt<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
            treeView.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">210</span>, <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>treeView<span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #009900;">// Fully expanded and scrolled</span>
&nbsp;
            treeView = <span style="color: #0033ff; font-weight: bold;">new</span> TreeView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            treeView.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">200</span>, <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span>;
            treeView.dataSource = getDataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            treeView.expandNodeAt<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
            treeView.scrollToItemAt<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
            treeView.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">210</span>, <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>treeView<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> getDataSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span>
                <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Root&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1_1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1_2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                            <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1_2_1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                            <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1_2_2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;/</span>item<span style="color: #000000; font-weight: bold;">&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1_3&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;/</span>item<span style="color: #000000; font-weight: bold;">&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_2_1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_2_2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;/</span>item<span style="color: #000000; font-weight: bold;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;/</span>item<span style="color: #000000; font-weight: bold;">&gt;</span>
            <span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_5" width="430" height="220">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/PublicInterfaceExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/PublicInterfaceExample.swf" width="430" height="220">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h4 id="styles">Styling the TreeView</h4>
<p>The TreeView (as with all ASDPC controls) can be extensively customised in functionality and appearance using styles. Most of the styles can be set or reset at runtime, wich means after the control has been added to the stage the first time.</p>
<h5>Style management</h5>
<p>The ASDPC style management is pretty easy to understand. Styles can be set directly to an object that defines that styles:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">treeView.setSyle<span style="color: #000000;">&#40;</span>TreeView.style.showRoot, <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>;
scrollBar.setSyle<span style="color: #000000;">&#40;</span>ScrollBar.style.scrollButtonVisibility, <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>In composite structures (such as all controls are) you may set a sub component style also to the containing object:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">treeView.setSyle<span style="color: #000000;">&#40;</span>ScrollBar.style.scrollButtonVisibility, <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>;
treeView.setSyle<span style="color: #000000;">&#40;</span>TreeNodeRenderer.style.<span style="color: #004993;">indent</span>, <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>To work with styles it is then necessary to know:</p>
<ul>
<li>The structure of the control that should by styled</li>
<li>The style properties of the control and of all its sub components</li>
</ul>
<h5>TreeView structure</h5>
<p>The structure of a TreeView and all available styles are visualised in the info window of the <a href="#demo">demo application</a>. Here again a short list of all sub components of a TreeView. Please refer to the APIDoc and to the source code to get informed about the particular styling possibilies of each sub component.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">TreeView
    TreeNodeRenderer
        ListItemBackgroundSkin
        ConnectorContainer
            Connector
                DottedConnectorSkin
        ListItemContent
            Label
        DirectoryIcon
        DisclosureButton
&nbsp;
    ScrollBar
        Button
            ButtonSkin
            ScrollButtonIconSkin
        Track
            ScrollTrackSkin
        Thumb
            ButtonSkin
            ScrollThumbIconSkin</pre></div></div>

<h5>Style property definitions</h5>
<p>Styles in the ASDPC library are always defined in the class, that use the style. The label font size is defined by the Label class. The button background color is defined by the ButtonSkin class, and the color of the scroll button triangle icon is defined by the ScrollButtonIconSkin class.</p>
<p>By convention, a style property name includes the name of the class, which it defines. E.g. the style property name for the visibility of the root node of the TreeView is &#8220;treeView_showRoot&#8221;. You do not know those constant values, since all style properties are available as ActionScript constants. The constant for the root node visibility is simply TreeView.style.showRoot. Style property constants are either defined in a separate style object or directly to the class, that use the style. Examples:</p>
<ul>
<li>Label color: Label.style.color</li>
<li>List item height: ListView.style.itemSize</li>
<li>Scroll button visibility: ScrollBar.style.scrollButtonVisibility</li>
<li>Button background colors: ButtonSkin.style_backgroundColors</li>
<li>Tooltip border color: ToolTipSkin.style_borderColor</li>
</ul>
<h5>Styling example</h5>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.treeview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.core.constants.Visibility;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.scrollbar.ScrollBar;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.treeview.renderer.ConnectorContainer;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.treeview.renderer.DisclosureButton;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.treeview.renderer.TreeNodeRenderer;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.treeview.renderer.skins.DisclosureButtonBoxIconSkin;
&nbsp;
    <span style="color: #3f5fbf;">/**
     * @author jes 04.02.2010
     */</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> StylingExample extends Example <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> StylingExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> treeView <span style="color: #000000; font-weight: bold;">:</span> TreeView = <span style="color: #0033ff; font-weight: bold;">new</span> TreeView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            treeView.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">260</span>, <span style="color: #000000; font-weight:bold;">125</span><span style="color: #000000;">&#41;</span>;
            treeView.expandNodeAt<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            treeView.dataSource = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span>
                <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Root&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1_1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1_2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_1_3&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;/</span>item<span style="color: #000000; font-weight: bold;">&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;</span>item <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;Node_2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;/</span>item<span style="color: #000000; font-weight: bold;">&gt;</span>
            <span style="color: #000000;">&#41;</span>;
&nbsp;
            treeView.setStyles<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>
                <span style="color: #009900;">// item size</span>
                TreeView.style.itemSize, <span style="color: #000000; font-weight:bold;">25</span>,
&nbsp;
                <span style="color: #009900;">// scrollbar and button visibility</span>
                TreeView.style.scrollBarVisibility, Visibility.VISIBLE,
                ScrollBar.style.scrollButtonVisibility, Visibility.VISIBLE,
&nbsp;
                <span style="color: #009900;">// box shaped disclosure button</span>
                DisclosureButton.style_expandedIconSkin, DisclosureButtonBoxIconSkin,
                DisclosureButton.style_collapsedIconSkin, DisclosureButtonBoxIconSkin,
                DisclosureButton.style_size, <span style="color: #000000; font-weight:bold;">9</span>,
                DisclosureButtonBoxIconSkin.style_fillColor, 0x000000,
                DisclosureButtonBoxIconSkin.style_iconColor, 0xFFFFFF,
&nbsp;
                <span style="color: #009900;">// connectors below button and icon</span>
                ConnectorContainer.style_connectorAtButton, <span style="color: #0033ff; font-weight: bold;">true</span>,
                ConnectorContainer.style_connectorAtIcon, <span style="color: #0033ff; font-weight: bold;">true</span>,
&nbsp;
                <span style="color: #009900;">// list item indent</span>
                TreeNodeRenderer.style.<span style="color: #004993;">indent</span>, <span style="color: #000000; font-weight:bold;">26</span>,
&nbsp;
                <span style="color: #009900;">// list item colors</span>
                TreeNodeRenderer.style.separator, <span style="color: #0033ff; font-weight: bold;">true</span>,
                TreeNodeRenderer.style.separatorColor, 0xDDDDDD,
                TreeNodeRenderer.style.evenIndexBackgroundColors, <span style="color: #000000;">&#91;</span>0xFFFFFF, 0xEEEEEE<span style="color: #000000;">&#93;</span>,
                TreeNodeRenderer.style.oddIndexBackgroundColors, <span style="color: #000000;">&#91;</span>0xFFFFFF, 0xEEEEEE<span style="color: #000000;">&#93;</span>,
                TreeNodeRenderer.style.overBackgroundColors, <span style="color: #000000;">&#91;</span>0xDDDDDD, 0xBBBBBB<span style="color: #000000;">&#93;</span>,
                TreeNodeRenderer.style.selectedBackgroundColors, <span style="color: #000000;">&#91;</span>0x666666, 0x999999<span style="color: #000000;">&#93;</span>,
            <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>; 
&nbsp;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>treeView<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_6" width="280" height="145">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/StylingExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/StylingExample.swf" width="280" height="145">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h4 id="icons">Setting custom icons</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.treeview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.treeview.renderer.DirectoryIcon;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.treeview.renderer.DisclosureButton;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> DynamicIconExample extends Example <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;assets/plus.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _plus <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span>;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;assets/minus.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _minus <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span>;
&nbsp;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;assets/document.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _document <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span>;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;assets/folder.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _folder <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span>;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;assets/folder_open.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _folder_open <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span>;
&nbsp;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;assets/as.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _as <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span>;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;assets/html.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _html <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span>;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;assets/php.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _php <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span>;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;assets/pdf.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _pdf <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span>;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;assets/htdocs.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _htdocs <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span>;
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;assets/htdocs_open.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _htdocs_open <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span>;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> DynamicIconExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> treeView <span style="color: #000000; font-weight: bold;">:</span> TreeView = <span style="color: #0033ff; font-weight: bold;">new</span> TreeView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            treeView.dataSource = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span>
                <span style="color: #000000; font-weight: bold;">&lt;</span>folder <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;C:<span style="">\\</span>&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;</span>folder <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;documents&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>file <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;serialz.txt&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>file <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;asdoc.pdf&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>file <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;images.zip&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;/</span>folder<span style="color: #000000; font-weight: bold;">&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;</span>folder <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;htdocs&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>file <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;index.php&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>file <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;contact.html&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>file <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;popup.html&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;/</span>folder<span style="color: #000000; font-weight: bold;">&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;</span>file <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;manual.pdf&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;</span>file <span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;asdpc.exe&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;/</span>folder<span style="color: #000000; font-weight: bold;">&gt;</span>
            <span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #009900;">// disclosure buttons</span>
&nbsp;
            treeView.setStyles<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>
                DisclosureButton.style_collapsedIconSkin, _plus,
                DisclosureButton.style_expandedIconSkin, _minus,
                DisclosureButton.style_size, <span style="color: #000000; font-weight:bold;">16</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #009900;">// default icons</span>
&nbsp;
            treeView.setStyles<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>
                DirectoryIcon.style.branchClosedIconSkin, _folder,
                DirectoryIcon.style.branchOpenIconSkin, _folder_open,
                DirectoryIcon.style.leafIconSkin, _document
            <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #009900;">// dynamic icons</span>
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> iconFunction <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Function</span> = <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span> <span style="color: #000000; font-weight: bold;">:</span> TreeNodeData<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Class</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> label <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span>.item<span style="color: #000000;">&#41;</span>.<span style="color: #004993;">attribute</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;name&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>label.<span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;.as&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span> _as;
                <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>label.<span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;.php&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span> _php;
                <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>label.<span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;.pdf&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span> _pdf;
                <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>label.<span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;.html&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span> _html;
                <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>label.<span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;htdocs&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span>.isExpanded<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span> _htdocs_open;
                    <span style="color: #0033ff; font-weight: bold;">return</span> _htdocs;
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span>; <span style="color: #009900;">// else use default icon</span>
            <span style="color: #000000;">&#125;</span>;
&nbsp;
            treeView.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span>DirectoryIcon.style.iconSkinFunction, iconFunction<span style="color: #000000;">&#41;</span>;
            treeView.expandNodeAt<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>treeView<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_7" width="280" height="180">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/DynamicIconExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/DynamicIconExample.swf" width="280" height="180">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

]]></content:encoded>
			<wfw:commentRss>http://sibirjak.com/blog/index.php/asdpc/asdpc-treeview/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>ActionScript Data Provider Controls</title>
		<link>http://sibirjak.com/blog/index.php/asdpc/actionscript-data-provider-controls/</link>
		<comments>http://sibirjak.com/blog/index.php/asdpc/actionscript-data-provider-controls/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 16:36:14 +0000</pubDate>
		<dc:creator>Jens Struwe</dc:creator>
				<category><![CDATA[ASDPC]]></category>

		<guid isPermaLink="false">http://sibirjak.com/blog/?p=404</guid>
		<description><![CDATA[This is the ASDPC library main blog post. I started the development of the libray a few months ago with a TreeView component, I wanted to make fully customizable. Soon it turned out, that the tree required additional elements (list, scrollbar, button, label), which I created with similiar perfection. Primarily for the use in my [...]]]></description>
			<content:encoded><![CDATA[<p>This is the ASDPC library main blog post.</p>
<p>I started the development of the libray a few months ago with a TreeView component, I wanted to make fully customizable. Soon it turned out, that the tree required additional elements (list, scrollbar, button, label), which I created with similiar perfection. Primarily for the use in my examples, I later added a couple of nifty general purpose components such as a color picker, a combo box or a popup window. Now I am in possession of a sophisticated UI framework, that I am going to share here.</p>
<p><span id="more-404"></span></p>
<p>Note, this blog article is supposed to be updated, complemented or corrected in the future.</p>
<h4>Table of contents</h4>
<ul>
<li><a href="#definition">Definition and Placement</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#objectives">Objectives</a></li>
<li><a href="#overview">Quick overview</a></li>
<li><a href="#getting_started">Getting started</a></li>
<li><a href="#resources">Resources</a></li>
</ul>
<h4 id="definition">Definition and placement</h4>
<p>The ASDPC library consists of a set of standard user interface controls applicable to any project without any architectural requirement. The library is targeted to simplify the development of control and from based ActionScript applications.</p>
<p>Using the ASDPCs does not require special knowledge or technical preparation. The controls can be used in both commercial or non-commercial projects. Hence, the software is placed under an open source software licence. There is a <a href="http://code.google.com/p/as-dataprovider-controls/">google code account</a> containing the most recent sources and encouraging your contribution.</p>
<h4 id="examples">Examples</h4>
<p><strong>In a nutshell</strong></p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_8" width="500" height="256">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/01/ASDPCTeaser.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/01/ASDPCTeaser.swf" width="500" height="256">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p><strong>Button example</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.overview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.button.Button;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.button.ButtonEvent;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ButtonExample extends Example <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _count <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span>;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ButtonExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> button <span style="color: #000000; font-weight: bold;">:</span> Button = <span style="color: #0033ff; font-weight: bold;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            button.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">80</span>, <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span>;
            button.label = <span style="color: #990000;">&quot;Click: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> _count;
            button.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>ButtonEvent.<span style="color: #004993;">CLICK</span>, buttonClickHandler<span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>button<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> buttonClickHandler<span style="color: #000000;">&#40;</span>event <span style="color: #000000; font-weight: bold;">:</span> ButtonEvent<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
            Button<span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span>.label = <span style="color: #990000;">&quot;Click: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight: bold;">++</span>_count;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_9" width="100" height="44">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/ButtonExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/ButtonExample.swf" width="100" height="44">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p><strong>ListView example</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.overview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.listview.ListItemEvent;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.listview.ListView;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.textfield.Label;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ListViewExample extends Example <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _label <span style="color: #000000; font-weight: bold;">:</span> Label;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ListViewExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> listView <span style="color: #000000; font-weight: bold;">:</span> ListView = <span style="color: #0033ff; font-weight: bold;">new</span> ListView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            listView.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">160</span>, <span style="color: #000000; font-weight:bold;">120</span><span style="color: #000000;">&#41;</span>;
            listView.dataSource = <span style="color: #000000;">&#91;</span>
                <span style="color: #990000;">&quot;Item1&quot;</span>, <span style="color: #990000;">&quot;Item2&quot;</span>, <span style="color: #990000;">&quot;Item3&quot;</span>, <span style="color: #990000;">&quot;Item4&quot;</span>,
                <span style="color: #990000;">&quot;Item5&quot;</span>, <span style="color: #990000;">&quot;Item6&quot;</span>, <span style="color: #990000;">&quot;Item7&quot;</span>, <span style="color: #990000;">&quot;Item8&quot;</span>,
                <span style="color: #990000;">&quot;Item9&quot;</span>, <span style="color: #990000;">&quot;Item10&quot;</span>
            <span style="color: #000000;">&#93;</span>;
            listView.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>ListItemEvent.SELECTION_CHANGED, selectHandler<span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>listView<span style="color: #000000;">&#41;</span>;
&nbsp;
            _label = <span style="color: #0033ff; font-weight: bold;">new</span> Label<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            _label.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;No item selected&quot;</span>;
            _label.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">130</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_label<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> selectHandler<span style="color: #000000;">&#40;</span>event <span style="color: #000000; font-weight: bold;">:</span> ListItemEvent<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>event.selected<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                _label.<span style="color: #004993;">text</span> = event.item <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; selected&quot;</span>;
            <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
                _label.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;No item selected&quot;</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_10" width="180" height="170">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/ListViewExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/ListViewExample.swf" width="180" height="170">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />
(Deselect item: Ctrl key + Click)</p>
<h4 id="objectives">Objectives</h4>
<p><strong>No framework obligation</strong></p>
<p>All controls can be used natively without any requirement to the particular application type (Flex, ActionScript or Flash).</p>
<p><strong>Extensive customization capabilities</strong></p>
<p>All controls can be almost entirely customized in functionality and appearance. However, default renderers and skins are applied, if not specified else. Even those default renderers and skins are highly customizable.</p>
<p><strong>Performance</strong></p>
<p>The controls have been developed, tested and improved for an optimal performance.</p>
<h4 id="overview">Quick overview</h4>
<h5>Life cycle architecture</h5>
<p>The core of the library is a general base class called View. This class provides a life cycle, which is inherited to each particular control. The life cycle maintains the construction and update process of a component by invoking methods in a well defined order.</p>
<p>The View also offers a property change cache to avoid redundant computing. All subsequent property updates are collected and executes them cumulatively at only one single point (in the next frame). This is often called deferred rendering.</p>
<h5>Styling and skinning</h5>
<p>Each control defines its own particular style properties. Styles can be set to a control directly or to any display ancestor of that control. Most of the styles can also be set at runtime, which means after a control has been added to the stage the first time.</p>
<p>The styling possibilities:</p>
<ul>
<li>Setting styles to controls or default renderers and default skins</li>
<li>Creating own skins for controls and default renderers</li>
<li>Creating own renderers</li>
<li>Creating own controls :-)</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.overview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.button.Button;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.button.skins.ButtonSkin;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.textfield.Label;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> StyleExample extends Example <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> StyleExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
            <span style="color: #009900;">// button 1</span>
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> button <span style="color: #000000; font-weight: bold;">:</span> Button = <span style="color: #0033ff; font-weight: bold;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            button.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">60</span>, <span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000;">&#41;</span>;
            button.toggle = <span style="color: #0033ff; font-weight: bold;">true</span>;
            button.label = <span style="color: #990000;">&quot;Off&quot;</span>;
            button.selectedLabel = <span style="color: #990000;">&quot;On&quot;</span>;
&nbsp;
            button.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span>ButtonSkin.style_backgroundColors, <span style="color: #000000;">&#91;</span>0xAAAAAA, 0x333333<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
            button.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span>ButtonSkin.style_overBackgroundColors, <span style="color: #000000;">&#91;</span>0xBBBBBB, 0x444444<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
            button.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span>ButtonSkin.style_borderColors, <span style="color: #000000;">&#91;</span>0x999999, 0x000000<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            button.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span>Button.style.labelStyles, <span style="color: #000000;">&#91;</span>
                Label.style.<span style="color: #004993;">color</span>, 0xEEEEEE,
                Label.style.<span style="color: #004993;">underline</span>, <span style="color: #0033ff; font-weight: bold;">false</span>,
                Label.style.<span style="color: #004993;">size</span>, <span style="color: #000000; font-weight:bold;">12</span>
            <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
            button.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span>Button.style.overLabelStyles, <span style="color: #000000;">&#91;</span>
                Label.style.<span style="color: #004993;">color</span>, 0xEEEEEE,
                Label.style.<span style="color: #004993;">underline</span>, <span style="color: #0033ff; font-weight: bold;">true</span>,
                Label.style.<span style="color: #004993;">size</span>, <span style="color: #000000; font-weight:bold;">12</span>
            <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
            button.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span>Button.style.selectedLabelStyles, <span style="color: #000000;">&#91;</span>
                Label.style.<span style="color: #004993;">color</span>, 0xEEEEEE,
                Label.style.<span style="color: #004993;">underline</span>, <span style="color: #0033ff; font-weight: bold;">false</span>,
                Label.style.<span style="color: #004993;">size</span>, <span style="color: #000000; font-weight:bold;">12</span>
            <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>button<span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #009900;">// button 2</span>
&nbsp;
            button = <span style="color: #0033ff; font-weight: bold;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            button.setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">60</span>, <span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000;">&#41;</span>;
            button.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">80</span>, <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
            button.toggle = <span style="color: #0033ff; font-weight: bold;">true</span>;
            button.label = <span style="color: #990000;">&quot;Off&quot;</span>;
            button.selectedLabel = <span style="color: #990000;">&quot;On&quot;</span>;
&nbsp;
            button.setStyles<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>
                ButtonSkin.style_backgroundColors, <span style="color: #000000;">&#91;</span>0xFF0000, 0xAA0000<span style="color: #000000;">&#93;</span>,
                ButtonSkin.style_overBackgroundColors, <span style="color: #000000;">&#91;</span>0xFF0000, 0xDD0000<span style="color: #000000;">&#93;</span>,
                ButtonSkin.style_borderColors, <span style="color: #000000;">&#91;</span>0xFF0000, 0x990000<span style="color: #000000;">&#93;</span>,
                ButtonSkin.style_cornerRadius, <span style="color: #000000; font-weight:bold;">0</span>,
&nbsp;
                Button.style.labelStyles, <span style="color: #000000;">&#91;</span>
                    Label.style.<span style="color: #004993;">color</span>, 0xFFFFFF,
                    Label.style.<span style="color: #004993;">size</span>, <span style="color: #000000; font-weight:bold;">12</span>
                <span style="color: #000000;">&#93;</span>,
                Button.style.overLabelStyles, <span style="color: #000000;">&#91;</span>
                    Label.style.<span style="color: #004993;">color</span>, 0xFFFFFF,
                    Label.style.<span style="color: #004993;">size</span>, <span style="color: #000000; font-weight:bold;">12</span>
                <span style="color: #000000;">&#93;</span>,
                Button.style.selectedLabelStyles, <span style="color: #000000;">&#91;</span>
                    Label.style.<span style="color: #004993;">color</span>, 0xFFFFFF,
                    Label.style.<span style="color: #004993;">size</span>, <span style="color: #000000; font-weight:bold;">12</span>
                <span style="color: #000000;">&#93;</span>
            <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>button<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_11" width="160" height="50">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/StyleExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/StyleExample.swf" width="160" height="50">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h5>Data integration</h5>
<p>The list controls (ListView, TreeView, SelectBox) visualise data of an external data source. Here is no restriction in the type of the data source. The ASDPC library has a built-in support for the native types Array and XML and for the AS3Commons collections. All other types can be used by creating custom data source adapter (which is easy and makes fun).</p>
<p>If a data source dispatchs change notifications (items added, removed), all list controls reflect those changes and update automatically.</p>
<h5>Property binding</h5>
<p>Most of the controls are equipped with binding capabilities. Whenever a bindable property changes, a registered binding listener receives notification. Note, the binding here is something different than the Flex binding.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.sibirjak.asdpc.overview <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.common.Example;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpc.textfield.Label;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.sibirjak.asdpcbeta.checkbox.CheckBox;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> BindingExample extends Example <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> BindingExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> checkBox <span style="color: #000000; font-weight: bold;">:</span> CheckBox = <span style="color: #0033ff; font-weight: bold;">new</span> CheckBox<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            checkBox.label = <span style="color: #990000;">&quot;Hidden&quot;</span>;
            checkBox.selectedLabel = <span style="color: #990000;">&quot;Visible&quot;</span>;
            checkBox.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>checkBox<span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> label <span style="color: #000000; font-weight: bold;">:</span> Label = <span style="color: #0033ff; font-weight: bold;">new</span> Label<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            label.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;I am visible&quot;</span>;
            label.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">80</span>, <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>label<span style="color: #000000;">&#41;</span>;
&nbsp;
            checkBox.bindProperty<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;selected&quot;</span>, label, <span style="color: #990000;">&quot;visible&quot;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_12" width="200" height="40">
      <param name="movie" value="http://sibirjak.com/blog/wp-content/uploads/2010/02/BindingExample.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://sibirjak.com/blog/wp-content/uploads/2010/02/BindingExample.swf" width="200" height="40">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<h4 id="getting_started">Getting started</h4>
<p>There is not much to get the controls running.</p>
<ol>
<li><a href="http://sibirjak.com/blog/index.php/asdpc/">Download the SWC</a> and copy it into your project.</li>
<li>Import the controls of your desire into your class and write code.</li>
</ol>
<h4 id="resources">Resources</h4>
<ul>
<li><a href="http://sibirjak.com/blog/index.php/asdpc/">Project homepage</a></li>
<li><a href="http://sibirjak.com/blog/index.php/asdpc/">APIDoc</a></li>
<li><a href="http://sibirjak.com/blog/index.php/asdpc/">Download</a> and <a href="http://sibirjak.com/blog/index.php/asdpc/">SVN repository</a></li>
<li><a href="http://sibirjak.com/blog/index.php/asdpc/">Bug tracker</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://sibirjak.com/blog/index.php/asdpc/actionscript-data-provider-controls/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Why we need a collection framework in ActionScript</title>
		<link>http://sibirjak.com/blog/index.php/collections/why-we-need-a-collection-framework-in-actionscript/</link>
		<comments>http://sibirjak.com/blog/index.php/collections/why-we-need-a-collection-framework-in-actionscript/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 08:00:25 +0000</pubDate>
		<dc:creator>Jens Struwe</dc:creator>
				<category><![CDATA[Collections]]></category>
		<category><![CDATA[Schlagwort hinzufügen]]></category>

		<guid isPermaLink="false">http://sibirjak.com/blog/?p=62</guid>
		<description><![CDATA[In this post, I will introduce you to the meanings of data collections and the different possiblities to collect data we have in ActionScript. Building on that, I am going to point out the most general requirements to a collection framework before I give a survey to existing solutions. Table of contents Introduction to collections [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, I will introduce you to the meanings of data collections and the different possiblities to collect data we have in ActionScript. Building on that, I am going to point out the most general requirements to a collection framework before I give a survey to existing solutions.</p>
<p><span id="more-62"></span></p>
<h4>Table of contents</h4>
<ul>
<li>
<a href="#intro">Introduction to collections</a><br />
<a href="#built-in">From built-in containers &#8230;</a><br />
<a href="#collections">&#8230; to collections</a><br />
<a href="#classification">Classification of collections</a>
</li>
<li><a href="#reasons">10 reasons for a collection framework</a></li>
<li>
<a href="#requirements">Requirements to a collection framework</a><br />
<a href="#software_requirements">Software requirements</a><br />
<a href="#community_requirements">Acceptance criteria</a>
</li>
<li><a href="#survey">Existing solutions</a></li>
</ul>
<h4 id="intro">Introduction to collections</h4>
<p>Unlike scripting for server environments, where we usually synchronously access the underlying data base and process those data more or less consecutively in response to preceding HTTP calls, in client applications we need to more seriously take care about how we manage storage and retrieval that data during the entire application lifecycle. A common pattern is to load a bunch of resources from the network and keep it in stock until the appliction gets terminated. This is often called proxying, since the data we are working on are copies of the orginal data living in the remote data base. A second important difference to server side data handling comes up with the needs to collect user generated data to fulfill what the application is made for.</p>
<h5 id="built-in">Built-in data containers</h5>
<p><strong>Array</strong></p>
<p>Each programming language consists of several native containers to file and access data sets. The best known is the Array, wich stores its elements in an ordered fashion and provides convenient (random) access over its indexes or, by using a for loop, sequential access. The same item can be contained multiple times. Arrays are exceptional fast and can hardly be beaten. There is also a typed array called vector, which promises to be even faster. However, keeping elements sorted, adding elements mostly at the begin or finding elements is not really Array&#8217;s business.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ArrayTest<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #009900;">// adding at end</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> a <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #6699cc; font-weight: bold;">var</span> i <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span>;
    <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">start</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">50000</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> a.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>;
    <span style="color: #6699cc; font-weight: bold;">var</span> end <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;add last i:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; t:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>end <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">start</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #009900;">// adding at start</span>
    a = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #004993;">start</span> = end;
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">50000</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> a.<span style="color: #004993;">unshift</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>;
    end = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;add first i:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; t:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>end <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">start</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #009900;">// finding</span>
    <span style="color: #004993;">start</span> = end;
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">50000</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>i <span style="color: #000000; font-weight: bold;">+</span> a.<span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000; font-weight:bold;">49999</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Error</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;error&quot;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
    end = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;find i:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; t:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>end <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">start</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #009900;">// add last i:50000 t:16</span>
    <span style="color: #009900;">// add first i:50000 t:1812</span>
    <span style="color: #009900;">// find i:50000 t:24954</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>Associative Array</strong></p>
<p>Sometimes the programming language supports associative arrays. In Flash we can use the dynamic Object class to create simple lookup tables. We are here restricted to number or string typed keys. Internally new properties are being added to the object at runtime. Random access (using the keys) or sequential access (for in loop) is possible. The for in loop does not preserve the insertion order. Also, duplicate keys are not possible. ActionScript3 did introduce a Dictionary class, wich acts mainly like the Object but allows additionally reference typed keys (objects, arrays, functions).</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> DictionaryTest<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">d</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #6699cc; font-weight: bold;">var</span> o <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #6699cc; font-weight: bold;">var</span> i <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span>;
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">50000</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> o<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = <span style="color: #000000;">&#123;</span><span style="color: #004993;">index</span><span style="color: #000000; font-weight: bold;">:</span>i<span style="color: #000000;">&#125;</span>;
&nbsp;
    <span style="color: #009900;">// adding</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">start</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">50000</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">d</span><span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span> = i;
    <span style="color: #6699cc; font-weight: bold;">var</span> end <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;add i:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; t:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>end <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">start</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #009900;">// finding</span>
    <span style="color: #004993;">start</span> = end;
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">50000</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">d</span><span style="color: #000000;">&#91;</span>o<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">!</span>= i<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Error</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;error&quot;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
    end = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;find i:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; t:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>end <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">start</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #009900;">// add i:50000 t:16</span>
    <span style="color: #009900;">// find i:50000 t:15</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>Compositions</strong></p>
<p>A third fundamental data container can be easily self-made by applying composition. The idea is to link objects among each other, what creates this way a sequential list or even a tree. We always need to save the first object from that we start enumeration. The composite structure cannot be accessed randomly. Iterating returns the items in the order they were inserted. The composition can manage the insertion of duplicate elements.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CompositionTest<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #009900;">// adding at start</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> i <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span>;
    <span style="color: #6699cc; font-weight: bold;">var</span> first <span style="color: #000000; font-weight: bold;">:</span> Node = <span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>;;
    <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">start</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">1</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">50000</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        first = <span style="color: #0033ff; font-weight: bold;">new</span> Node<span style="color: #000000;">&#40;</span>i, first<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> end <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;add first i:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; t:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>end <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">start</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #009900;">// finding</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> node <span style="color: #000000; font-weight: bold;">:</span> Node;
    i = <span style="color: #000000; font-weight:bold;">0</span>; <span style="color: #004993;">start</span> = end;
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">1</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">1000</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        node = first;
        <span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>node<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>node.item == i<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">break</span>;
            node = node.<span style="color: #004993;">right</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    end = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;find i:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; t:&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>end <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">start</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #009900;">// add first i:50000 t:141</span>
    <span style="color: #009900;">// find i:1000 t:9719</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #9900cc; font-weight: bold;">class</span> Node <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">right</span> <span style="color: #000000; font-weight: bold;">:</span> Node;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> item <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span>;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Node<span style="color: #000000;">&#40;</span>theItem <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span>, theRight <span style="color: #000000; font-weight: bold;">:</span> Node<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        item = theItem;
        <span style="color: #004993;">right</span> = theRight;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h5 id="collections">&#8230; to collections</h5>
<p>You have seen that the different approaches to collect data have their particular pros and cons. More structured, there are 4 fields of quality, the choice of a collection should be done in respect to.</p>
<ul>
<li><strong>Performance of inserting</strong> an element at a specific position (at begin, in between, at end)</li>
<li><strong>Performance of finding</strong> an element (constant, logarithmic, linear or worse time)</li>
<li><strong>Order</strong> of the collection&#8217;s elements in enumeration (no order, insertion order, sorted order)</li>
<li><strong>Multiplicity</strong> of elements (unique, multiple)</li>
</ul>
<p>Each of the three described built-in data containers supports a distinctive set of the qualities just mentioned. For example, the Array returns its items in insertion order but is pretty slow in finding one, while the Object enables a very fast lookup but enumeration is always surprisingly. Well, what about an example phone book application where we need ordering (phone book index) as well as direct element access (search)? In cases like this we simply combine the advantages of different containers. We use a sorted array to store the phone book&#8217;s entries (index) and set up an associative array (in Flash the Object) to save the participant&#8217;s name together with the accordant array index (search). We can think about various combinations, and some of them are that common, that they became names and have been included into the core libraries of many programming languages where they are now called collections.</p>
<h5 id="classification">Classification of collections</h5>
<p><a href="http://java.sun.com/javase/6/docs/technotes/guides/collections/overview.html">The Java Collections Framework</a> defines three main collection types: Lists, sets and maps. (The queues can be considered as optimised lists.) Lists are always ordered, may contain duplicates and can be handled the same way as usual arrays. Sets cannot contain duplicates and provide random access to its elements. Maps connect unique keys with values, provide random access to its keys and may host duplicate values. The simplest implementions are respectively ArrayList, HashSet, HashMap. Different implementations are available for each of those types. Either they focus on ordering (LinkedHashSet, LinkedHashMap) or sorting (TreeSet, TreeMap) or fast inserting (LinkedXXX). </p>
<p>Besides the functional aspects, collections can also be classified by their internal structure (implementation). The table below lists a few important collections and their characteristics as well as realisation possibilies in ActionScript.</p>
<table class="simple_table">
<tr>
<th>Collection</th>
<th colspan="3">Characteristics</th>
<th>Realisation</th>
</tr>
<tr>
<td></td>
<td>Multiplicity</td>
<td>Order</td>
<td>Access</td>
<td></td>
</tr>
<tr class="st_border_top">
<td>ArrayList</td>
<td>multiple</td>
<td>ordered</td>
<td>random<br />
sequential</td>
<td>Array</td>
</tr>
<tr>
<td>LinkedList</td>
<td>multiple</td>
<td>ordered</td>
<td>sequential</td>
<td>Composition</td>
</tr>
<tr>
<td>SortedList</td>
<td>multiple</td>
<td>sorted</td>
<td>random<br />
sequential</td>
<td>Array</td>
</tr>
<tr class="st_border_top">
<td>Set</td>
<td>unique</td>
<td>unordered</td>
<td>random</td>
<td>Dictionary</td>
</tr>
<tr>
<td>LinkedSet</td>
<td>unique</td>
<td>ordered</td>
<td>random<br />
sequential</td>
<td>Dictionary +<br />
Composition</td>
</tr>
<tr>
<td>SortedSet</td>
<td>unique</td>
<td>sorted</td>
<td>random<br />
sequential</td>
<td>Binary tree</td>
</tr>
<tr class="st_border_top">
<td>Map</td>
<td>unique keys<br />
multiple items</td>
<td>unordered</td>
<td>random</td>
<td>Dictionary</td>
</tr>
<tr>
<td>LinkedMap</td>
<td>unique keys<br />
multiple items</td>
<td>ordered</td>
<td>random<br />
sequential</td>
<td>Dictionary +<br />
Composition</td>
</tr>
<tr>
<td>SortedMap</td>
<td>unique keys<br />
unique items</td>
<td>sorted</td>
<td>random<br />
sequential</td>
<td>Dictionary +<br />
Binary tree</td>
</tr>
</table>
<p>We can think of several applications for any of the different collections. The LinkedList would be for example perfectly suitable for an undo/redo history. Here we always add items at begin of the list and retrieve the elements sequentially. The phone book above uses the SortedMap. To reflect unmodifiable remote data we probably are going to use the LinkedMap, which enables access over an ID while it keeps the given order. The sets are most often used to collect runtime generated data. In a shopping application we might use a LinkedSet for the basket. Adding and removing of products can be done in constant time. The basket overview shows the products in the order they were added. When trying to add a product a second time, it&#8217;s simple to increase the quantity. Example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> as3.collections <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;    
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SetBasketExample extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> basket <span style="color: #000000; font-weight: bold;">:</span> ILinkedSet;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SetBasketExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
            basket = <span style="color: #0033ff; font-weight: bold;">new</span> LinkedSet<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #6699cc; font-weight: bold;">var</span> shirt <span style="color: #000000; font-weight: bold;">:</span> Product = <span style="color: #0033ff; font-weight: bold;">new</span> Product<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;shirt&quot;</span>, <span style="color: #000000; font-weight:bold;">19.90</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #6699cc; font-weight: bold;">var</span> cap <span style="color: #000000; font-weight: bold;">:</span> Product = <span style="color: #0033ff; font-weight: bold;">new</span> Product<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;cap&quot;</span>, <span style="color: #000000; font-weight:bold;">14.00</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span>shirt<span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span>cap<span style="color: #000000;">&#41;</span>;
            <span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span>shirt<span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #004993;">trace</span> <span style="color: #000000;">&#40;</span>basket.toArray<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">join</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #009900;">// cap #1 $14</span>
            <span style="color: #009900;">// shirt #2 $39.8</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span>product <span style="color: #000000; font-weight: bold;">:</span> Product<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>basket.hasItem<span style="color: #000000;">&#40;</span>product<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                product.quantity<span style="color: #000000; font-weight: bold;">++</span>;
            <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
                basket.addItemAtStart<span style="color: #000000;">&#40;</span>product<span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #9900cc; font-weight: bold;">class</span> Product <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">name</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span>;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> price <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span>;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> quantity <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">1</span>;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Product<span style="color: #000000;">&#40;</span>theName <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span>, thePrice <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #004993;">name</span> = theName;
        price = thePrice;
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">name</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; #&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> quantity <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; $&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> quantity <span style="color: #000000; font-weight: bold;">*</span> price;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Until here, I have illustrated the potential of collections to solve common software problems. However, that&#8217;s not everything we can benefit from. In the next chapter I will give you a compact overview to the goals of collections, which moves the perspective more to software architecture and collaboration.</p>
<h4 id="reasons">10 reasons for a collection framework</h4>
<ol>
<li>As we already know: Collections are design patterns for solutions of common problems with storing and retrieving data. Patterns help us in understanding situations and designing software. They clearly express their benefits and weaknesses.</li>
<li>Collections take over the implementation of the most commonly required functionality. No need to reinvent the wheel for each new project.</li>
<li>Wisely chosen, also in the mix with built-in containers, collections will enhance the performance of applications, even although they are built onto the programming language and are not part of the language itself.</li>
<li>Using collections results in far less and better readable source code.</li>
<li>Collections are entirely extendable. New functionality can be added using inheritance as well as by setting up completely new implementations for the particular interfaces.</li>
<li>Collections provide a generalised interface to the different underlying data structures. Wherever an ISet is accepted you can pass a Set, LinkedSet, SortedSet or MyCustomSet instance. May they internally hold an array or an object, the interface abstracts from the actual insertion strategy (push or []) and exposes the general addItem(). This way collections are interchangeable, portable and shareable.</li>
<li>Collections provide a uniform way of enumeration by engaging the iterator design pattern. Regardless of their distinctive implementations, collections can be interchangeable passed wherever an iterable object is expected.</li>
<li>A collection framework enables developers creating third party libraries based on collections rather than native containers. The libray interfaces are not restricted to accept ordinary arrays or objects. Without a framework, each libraray either would have to provide its own collection implementations, which can be considered as a reinvented framework, or simply had to abstain from using collections, which cannot be considered ;-).</li>
<li>The collection framework (assuming its existance) guarantees failure restistance, stability and sophistication. The framework is widely adapted, community based and proven by a lot of serious projects. Thus, it will be easy to explain its integration within official work flows.</li>
<li>Finally, an existing collection framework can make up one of the reasons keeping ActionScript/Flex being the technology of choice for web client application development. This is an important point in consideration of the fast growing JavaScript and JavaFX communities.</li>
</ol>
<p>At this point of explanations, I have no doubt, you fully agree to the needs of a unified collection framework in ActionScript. I will put my thoughts about realisation possibilities right away.</p>
<h4 id="requirements">Requirements to an ActionScript collection framework</h4>
<p>As with all frameworks, the collection framework combines sophisticated software with an active and helpful community. The following requirements are therefore slightly generic.</p>
<h5 id="software_requirements">Software requirements</h5>
<ul>
<li><strong>Slim and intuitive interfaces</strong><br />
The framework consists only of the most necessary and commonly interfaces. Their definition is a challenging process and need not to be remade by each individual user. The framework integrates theoretical reflections, expert-knowledge and best practices and can be described as a general recommendation of approaches rather than as a ready-for-use library, which it is in the second place.</li>
<li>
<strong>High degree of extensibility</strong><br />
To be applicable also in custom circumstances, the framework must provide straightforward mechanisms to extend the built-in functionality. There are three ways of doing this.</p>
<ol>
<li>An interface architecture allows interchangeable implementations of the same type. The collection framework must provide interfaces to all public functionality such as collections, iterators or configuration objects.</li>
<li>Inheritance let&#8217;s the developers benefit from available basic implementations. The latter must therefore live in a public or protected namespace.</li>
<li>Configuration as the third mechanism is dedicated the customisation of framework internal workflows by passing configuration objects (inversion of control). The collection framework encapsulates algorithms such as for sorting or comparing and makes them that way replaceable. Particular implementations can furthermore offer their own parametrisation.</li>
</ol>
</li>
<li><strong>Ready-for-use implementations</strong><br />
No framework would be accepted if it wouldn&#8217;t consists of a proper set of functionality applicable directly and without major preparation. The collection framework must contain base implemenations for all of the different collection types above.</li>
<li><strong>Predictable and consistent behaviour</strong><br />
A framework should smoothly handle special or corner cases such as the absence of data, type mismatchs or range errors. Those cases have to be described and tested sufficiently as well as how the framework is supposed to behave normally.</li>
<li><strong>Good performance</strong><br />
It&#8217;s obvious, that an unperformant framework is not much useful. The collection framework is targeted to the basis level of an application and bad performance here will be transferred to the overlying functionality. The performance of a collection depends on its structure and the algorithms modifying the structure. We have in ActionScript the high performing built-in Array and Dictionary, and in the most of the use cases it doesn&#8217;t get any faster than utilising them. A collection framework for ActionScript must reflect the special means and needs of the Flash platform.<br />
Performance has to be tested, compared and documented for each relevant function. Although performance is not the main goal of a collection framework, since performance and abstraction are a little bit contrary, it&#8217;s about to find the right balance between both poles.</li>
</ul>
<h5 id="community_requirements">Acceptance criteria</h5>
<ul>
<li><strong>Appropriate licence</strong><br />
First of all, a framework shouldn&#8217;t have much limitations in useage.</li>
<li><strong>Easy utilisation</strong><br />
Placing a new framework, you will need users for testing and feedback or getting convinced and hopefully spreading the word. For that, at least the installation of your framework should be exceedingly simple. Involving common software design concepts makes it relatively easy to get developers familiar with your framework. (In contrast, you cannot expect the user to spend much time to follow complicated and custom solutions.) This goes hand in hand with an intuitive and consistant naming of interfaces and methods, who should clearly express, what they are about and why they were invented.</li>
<li><strong>Documentation, examples, tutorials</strong><br />
Depending on the purpose of the software, either end user documentation (in running text) or source code documentation or even both are adequate, which is the case with a collection framework.<br />
There never can be enough examples and good tutorials. Missing manuals can disappoint beginners and cause them to leave before they had the chance to enjoy the benefits of the software.</li>
<li><strong>Tested and stable software</strong><br />
Existing test suites (and successful tests) are often the decisive factor for or against a third party software. A well-engineered framework ensures a high degree of stability. Subsequent and improved versions do not affect the base concepts and interfaces.</li>
<li><strong>Active community</strong><br />
Obviously some frameworks are widely accepted and gain users while others live a dire existance. As a rule of thumb: Active communities tend to become more active :-) It&#8217;s the good balance between excellent software, clever PR and the support of the right people, what makes a framework popular. Open source projects often limit themselves to the first point. Popular authorities can advance even immature software to a high distribution. Good documentation and promotion can compensate both weaknesses of the software and absent supporters.<br />
Besides the software itself, an active framework offers many possibilities to join and support the associated community.</p>
<ul>
<li>Independent project page</li>
<li>Source code repository</li>
<li>Feedback, error and change request management</li>
<li>Discussion board</li>
<li>Donation box</li>
</ul>
</li>
<li><strong>High adoption rate</strong><br />
There is no better recommendation as to have the software already being used in a large number of projects. A published list of applying projects provides confidence to new users and might give those projects a little advertisment.</li>
</ul>
<p>I am now finished with the theoretical backgrounds of collections and collection frameworks. I will continue with a short review of some existing collection libraries for ActionScript.</p>
<h4 id="survey">Existing solutions</h4>
<ul>
<li><strong>Flex collection package</strong><br />
Flex collections are designed to seamlessly integrate Flex user interfaces with data models. Whenever data changes, the Flex component gets automatically updated and vice versa. Using Flex collections without Flex components does not make much sense. The Flex collections actually consist only of a single list interface with two different implementations.<br />
<a href="http://livedocs.adobe.com/flex/3/html/help.html?content=about_dataproviders_1.html">http://livedocs.adobe.com/flex/3/html/help.html?content=about_dataproviders_1.html</a></li>
<li><strong>AS3 Data Structures For Game Developers</strong><br />
The first choice (and best source) when it comes to bare algorithms and speed optimised data structures. Apparently the widest acceptance of all libraries. More a losely coupled set of distinctive implementations than a framework (doesn&#8217;t claim do be one). Great explanations and visual examples of data structures. Provided and maintained by the German Michael Baczynski.<br />
<a href="http://lab.polygonal.de/ds/">http://lab.polygonal.de/ds/</a></li>
<li><strong>dpdk_os_flash</strong><br />
A pretty comprehensive and shophisticated library with excellent source code documentation. Entirely unit tested. Includes special purpose functionality such as commands, specifications, folding and mapping or remote data management and appears therefore a little bit overengineered. Maps are not dealed with. Provided and maintained by a Dutch media agency as their company framework.<br />
<a href="http://www.dpdk.nl/opensource/the-collections-package">http://www.dpdk.nl/opensource/the-collections-package</a></li>
<li><strong>AS3-Collection-Framework</strong><br />
A custom implementation of the Java interfaces. Provides various collections including a linked map. Very committed work. Could do with a little compression. Sometimes not using the best solution strategy. Developed by Tim Richter, Germany.<br />
<a href="http://www.addicted2flash.com/category/as3-collection-framework/">http://www.addicted2flash.com/category/as3-collection-framework/</a></li>
<li><strong>as3commons</strong><br />
A port of the Java Collections Framework to ActionScript, probably not longer active. The ported versions performed noticeable slow in tests. Might be an effect of the heavy composite architecture.<br />
<a href="http://sourceforge.net/projects/as3commons/">http://sourceforge.net/projects/as3commons/</a></li>
<li><strong>ActionScript Foundry collection package</strong><br />
The collections are part of the Foundry framework, which is targeted to simplify Flex application development. Is a port of the Java framework. I have not tested the collections, but after a short review of the code, I expect the collections performing similiar to those of the as3commons package.<br />
<a href="http://www.servebox.org/actionscript-foundry/actionscript-foundry-documentation/the-collections-framework/">http://www.servebox.org/actionscript-foundry/actionscript-foundry-documentation/the-collections-framework/</a></li>
<li><strong>VEGAS</strong><br />
Actually I didn&#8217;t get what VEGAS is especially for and if there are people out of the developer group using this huge library. However, they have their own package consisting of numerous different collections. Contains a lot of secondary and project internal functionality. Poor documented but readable source code. Depends on other VEGAS packages. It&#8217;s a bit tricky to come through to the sources.<br />
<a href="http://www.ekameleon.net/blog/index.php?pages/VEGAS-AS3-AS2-SSAS-Opensource-Framework">http://www.ekameleon.net/blog/index.php?pages/VEGAS-AS3-AS2-SSAS-Opensource-Framework</a></li>
<li><strong>Other libraries</strong><br />
The <a href="http://www.pranaframework.org/docs/0.7/api/org/springextensions/actionscript/collections/package-detail.html">Prada framework</a> (nowadays Spring ActionScript) contains a map extension of the Flex collections. The same with <a href="http://www.ericfeminella.com/blog/actionscript-3-apis/">Eric Feminella&#8217;s Open Source AS3 APIs</a>.</li>
</ul>
<p>Summary: We have quite a few solutions for exactly the same problem of how do we store and retrieve data in ActionScript client applications. There is obviously a need to work with collections rather than with native containers. Especially the general purpose frameworks rely on their custom collection implementations, who are often stuffed with internal functionality and are not likely to be used out of the box. Among the designated collection frameworks can be emphasized the dpdk_os_flash project because of the cleanest architecture and the AS3 Data Structures with the best algorithms.<br />
None of the solutions reviewed match the most of the requirements prior proposed. However, the Dutch&#8217;s work is the most serious alternative and should be considered when planning to involve a third party collection library.</p>
<p>Thank you for reading these long explanations. I hope, I could bring some light into the matter and have made you hungry for working with data collections.</p>
]]></content:encoded>
			<wfw:commentRss>http://sibirjak.com/blog/index.php/collections/why-we-need-a-collection-framework-in-actionscript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
