2008/9/4 Roger Pack <rogerpack2005 / gmail.com>:
>> Why do that?  Your identifiers is constant anyway - as far as I can
>> see.  Why not just do
>>
>> identifiers = {/abc/ => 'an abc line', /def/ => 'a def line'}.to_a
>
> Yeah--works like a charm.

Great!

> This makes me wish that there were a data structure that has
> object-based O(1) lookup/insertion/deletion, and O(n) .each calls.
> Apparently Hash doesn't :)

Not so fast!  Keep in mind that these figures are *asymptotic* there
are always constants involved and it might well be that for the N's we
deal with results look very different. That's why we do all the
benchmarking when we want to find out which approach is best. :-)

> My theory is that some people use hashes just for the convenience of
> object-based lookup [ex: scope[:include] in rails] and not for the real
> strength of hashes, which, as you mentioned, is "efficient
> lookup/insertion/deletion"

I am not sure what you mean by "object-based lookup", especially how
it is not "efficient lookup/insertion/deletion" or differs from that.
I mean, people do use these lookups *because* they are efficient.

> Thanks!

You're welcome.

Cheers

robert


-- 
use.inject do |as, often| as.you_can - without end