<div class="gmail_quote">On Thu, Nov 11, 2010 at 5:16 PM, Daniel Pittman <span dir="ltr">&lt;<a href="mailto:daniel@rimspace.net">daniel@rimspace.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">
&gt;&gt;&gt; Hmm, interesting to hear.<br>
&gt;&gt;&gt; So, the array methods are quicker than hashes for small sets?<br>
&gt;&gt;<br>
&gt;&gt; They should be faster than a hash for *any* set, because they are a constant<br>
&gt;&gt; time access with zero computation, rather than a just-above-constant time<br>
&gt;&gt; access with some computation.<br>
&gt;<br>
&gt; I was confused by how it could be computation-free for a moment, then realised<br>
&gt; you&#39;re talking about accessing things by doing $planets[$id], which of course<br>
&gt; is quicker than $planets-&gt;{$id}.<br>
<br>
</div>I was talking about the more general case of array vs hash, where access is<br>
zero-cost &quot;index times size&quot; vs some-cost &quot;index through hash, then walk past<br>
collisions&quot;.  (Presumably your comment about speed wasn&#39;t quite so<br>
restricted. :)<br></blockquote><div><br>Be careful to think that this is absolutely true. Perl&#39;s arrays are not C arrays. If your index is greater than the number of elements in the array, then the array will be extended i.e. the array element pointers will be copied into a new array which can hold just one more element. This will happen *each time* you extend the size of an array i.e. push()!<br>
<br>If you are reading and writing to an array of fixed size, then yes it&#39;s zero cost. Otherwise, know the size upfront and do something like:<br><br>  my @array; $array[MAX_SIZE-1] = undef;<br><br>Alfie<br><br></div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<font color="#888888"><br>
        Daniel<br>
</font><div class="im"><br>
--<br>
✣ Daniel Pittman            ✉ <a href="mailto:daniel@rimspace.net">daniel@rimspace.net</a>            ☎ +61 401 155 707<br>
               ♽ made with 100 percent post-consumer electrons<br>
_______________________________________________<br>
</div><div><div></div><div class="h5">Melbourne-pm mailing list<br>
<a href="mailto:Melbourne-pm@pm.org">Melbourne-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/listinfo/melbourne-pm</a></div></div></blockquote></div><br>