Ralph Shnelvar wrote:
> Of course, I could use a hash ... but I doubt that a hash would beat
> my binary search ... I could be wrong about this.

You are almost certainly wrong about this. Ruby Hash implementation is 
in C and very efficient. I'm sure this would be the quickest way to find 
the row with a given key.

> The array is more-or-less static.  That is, access
> to this array swamps any changes to the array.

Especially good for a hash.

So my advice is: write it the simplest possible way first. Then analyse 
(a) the speed, and/or (b) the memory usage, if they are problematic.

There's a difference between "quickest" and "quick enough". If you were 
looking for "quickest" you wouldn't be using Ruby in the first place. 
But if you value your development time, you could implement this with a 
Hash in 10 minutes.

> 300K rows and 20 columns

If those are values that fit in a Fixnum then that's only 24MB in total 
on a 32-bit machine, or 48MB on a 64-bit machine. So just do the 
obvious. If a few of those values are Bignums, no big deal.

If you need better packing, you can always just allocate packed strings. 
For example, you can pack 20 32-bit integers (signed or unsigned) into 
an 80 byte string, and unpack the row again later. Look at Array#pack 
and String#unpack
-- 
Posted via http://www.ruby-forum.com/.