<div class="gmail_quote">On Thu, Nov 11, 2010 at 5:16 PM, Daniel Pittman <span dir="ltr"><<a href="mailto:daniel@rimspace.net">daniel@rimspace.net</a>></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">
>>> Hmm, interesting to hear.<br>
>>> So, the array methods are quicker than hashes for small sets?<br>
>><br>
>> They should be faster than a hash for *any* set, because they are a constant<br>
>> time access with zero computation, rather than a just-above-constant time<br>
>> access with some computation.<br>
><br>
> I was confused by how it could be computation-free for a moment, then realised<br>
> you're talking about accessing things by doing $planets[$id], which of course<br>
> is quicker than $planets->{$id}.<br>
<br>
</div>I was talking about the more general case of array vs hash, where access is<br>
zero-cost "index times size" vs some-cost "index through hash, then walk past<br>
collisions". (Presumably your comment about speed wasn't quite so<br>
restricted. :)<br></blockquote><div><br>Be careful to think that this is absolutely true. Perl'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'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>