<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Unique records in AS3</title>
	<atom:link href="http://www.shiftperception.com/blog/2009/06/16/unique-records-in-as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shiftperception.com/blog/2009/06/16/unique-records-in-as3/</link>
	<description>shiftperception.010 blog</description>
	<lastBuildDate>Sat, 15 May 2010 14:34:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: dan</title>
		<link>http://www.shiftperception.com/blog/2009/06/16/unique-records-in-as3/comment-page-1/#comment-3262</link>
		<dc:creator>dan</dc:creator>
		<pubDate>Thu, 18 Jun 2009 04:05:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.shiftperception.com/blog/?p=622#comment-3262</guid>
		<description>Thanks for the heads up OJ :)

Optimisation for performance is something that I need to explore more of - im constantly looking for ways to optimise the code, but often its about reducing code, not improving performance.

For indexOf() (for example) - how does one know that it&#039;s O(n) - is this something you really need to have studied or is there some cheat sheet that highlights these tidbits of wisdom?</description>
		<content:encoded><![CDATA[<p>Thanks for the heads up OJ <img src='http://www.shiftperception.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Optimisation for performance is something that I need to explore more of &#8211; im constantly looking for ways to optimise the code, but often its about reducing code, not improving performance.</p>
<p>For indexOf() (for example) &#8211; how does one know that it&#8217;s O(n) &#8211; is this something you really need to have studied or is there some cheat sheet that highlights these tidbits of wisdom?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: OJ</title>
		<link>http://www.shiftperception.com/blog/2009/06/16/unique-records-in-as3/comment-page-1/#comment-3261</link>
		<dc:creator>OJ</dc:creator>
		<pubDate>Thu, 18 Jun 2009 03:22:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.shiftperception.com/blog/?p=622#comment-3261</guid>
		<description>Hey Dan,

Functions like this are pretty awesome. They&#039;ve got their roots in functional programming, which is where my heart lies!

Just one thing to look out for: &lt;a href=&quot;http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Array.html#indexOf()&quot; title=&quot;indexOf() at Adobe&quot; rel=&quot;nofollow&quot;&gt;indexOf()&lt;/a&gt; is an &lt;a href=&quot;http://en.wikipedia.org/wiki/Big_O_notation&quot; title=&quot;Big O @ Wikipedia&quot; rel=&quot;nofollow&quot;&gt;O(n)&lt;/a&gt; function, which means that for each value in the array you&#039;re traversing the whole array. That results in an algorithm of O(n&lt;sup&gt;2&lt;/sup&gt;) complexity. It&#039;ll scale really badly. Bear in mind that &lt;a href=&quot;http://www.codinghorror.com/blog/archives/000957.html&quot; title=&quot;Coding horror&quot; rel=&quot;nofollow&quot;&gt;everything is fast for small &lt;em&gt;n&lt;/em&gt;&lt;/a&gt; ;) When you start getting arrays that are really big, you&#039;ll find that performance is woeful.

Instead you&#039;re looking to get yourself into the position where you can process the array in O(n) time. This means you&#039;re going to have to use something like a map to keep track, rather than constantly reprocessing the list. For example:

&lt;code&gt;
var map:Object = new Object();
var fruits:Array = tmpArray.filter(function(e, i, a){
&#160;if(map[e] == null){
&#160;&#160;map[e] = true;
&#160;&#160;return true;
&#160;}
&#160;return false;
}, this);
&lt;/code&gt;

Here you can see that we&#039;re searching for items in an object/map rather than parsing the array. If the item is found, we indicate that it was already parsed. If it wasn&#039;t found, we add it to the map and indicate that it&#039;s unique.

Another approach is to brute-force convert the array to a set/map then convert it back. But that doesn&#039;t preserve ordering in the array.

For larger arrays, this will be substantially quicker than your current approach :)

Cheers mate, keep the posts coming! Great to have you blogging again.
OJ</description>
		<content:encoded><![CDATA[<p>Hey Dan,</p>
<p>Functions like this are pretty awesome. They&#8217;ve got their roots in functional programming, which is where my heart lies!</p>
<p>Just one thing to look out for: <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Array.html#indexOf()" title="indexOf() at Adobe" rel="nofollow">indexOf()</a> is an <a href="http://en.wikipedia.org/wiki/Big_O_notation" title="Big O @ Wikipedia" rel="nofollow">O(n)</a> function, which means that for each value in the array you&#8217;re traversing the whole array. That results in an algorithm of O(n<sup>2</sup>) complexity. It&#8217;ll scale really badly. Bear in mind that <a href="http://www.codinghorror.com/blog/archives/000957.html" title="Coding horror" rel="nofollow">everything is fast for small <em>n</em></a> <img src='http://www.shiftperception.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  When you start getting arrays that are really big, you&#8217;ll find that performance is woeful.</p>
<p>Instead you&#8217;re looking to get yourself into the position where you can process the array in O(n) time. This means you&#8217;re going to have to use something like a map to keep track, rather than constantly reprocessing the list. For example:</p>
<p><code><br />
var map:Object = new Object();<br />
var fruits:Array = tmpArray.filter(function(e, i, a){<br />
&nbsp;if(map[e] == null){<br />
&nbsp;&nbsp;map[e] = true;<br />
&nbsp;&nbsp;return true;<br />
&nbsp;}<br />
&nbsp;return false;<br />
}, this);<br />
</code></p>
<p>Here you can see that we&#8217;re searching for items in an object/map rather than parsing the array. If the item is found, we indicate that it was already parsed. If it wasn&#8217;t found, we add it to the map and indicate that it&#8217;s unique.</p>
<p>Another approach is to brute-force convert the array to a set/map then convert it back. But that doesn&#8217;t preserve ordering in the array.</p>
<p>For larger arrays, this will be substantially quicker than your current approach <img src='http://www.shiftperception.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Cheers mate, keep the posts coming! Great to have you blogging again.<br />
OJ</p>
]]></content:encoded>
	</item>
</channel>
</rss>
