On Wed, Nov 14, 2012 at 6:30 AM, Charles Hixson
<charleshixsn / earthlink.net> wrote:
> I've measured it in several languages, and occasionally implemented the hash
> algorithm from scratch in C (two or three different ways of handling
> collisions...but Unicode means that I don't want to use C, though pointers
> was my original reason).  I'll admit I haven't measured it yet in Ruby, but
> hash cannot be fast, though direct indexing can be slow.  It's in the nature
> of the algorithm.  It can be quite fast compared to a tree lookup, but not
> compared to a direct index.

That is still speculation.

> FWIW, the answer I was looking for is that Arrays are automatically extended
> to the last index inserted into.  This probably implies that Arrays use some
> sort of linked block index, though another possibility is that it just
> allocates a honking big chunk of memory, and does a copy whenever it needs
> to resize the array.  This seems unlikely.

Please stop speculating and verify the facts (i.e. check Ruby source
code).  You'll do yourself a big favor.

Note also that you can still implement a type with the same interface
as Hash or Array and drop it into your implementation later if you
find the std lib types to be too slow for your purposes.

Cheers

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/