Eivind Eklund wrote:

> 
> Apart from that, this is solvable in O(log N) per lookup using a
> binary tree.  If you need something faster, you could do it by
> constructing your tree in byte based buckets - essentially, you end up
> with one lookup per byte in your number, finding what range it is part
> of when the number is well enough resolved that it can only be in one
> range.
> 
> Eivind.

As a clarification, it's only LogN if you are using a sorted array with 
binary lookup, the RangedHash implementation as above will not perform 
LogN.. It will be N..

I also believe that this is not a case of premature optimization, If 
someone says hash to me, I immediately expect it to behave as a LogN and 
I don't want to concern myself with number of entries within the 
container.. Hashes are simply hashes, and if you want to make them 
perform different than from what every coder knows them to be, then at 
least have the courtesy to change the class name..

ilan
-- 
Posted via http://www.ruby-forum.com/.