From: Trans Date: 2008-04-05T00:15:41+09:00 Subject: Re: using a range as a key On Apr 4, 4:13 am, Calamitas wrote: > On Fri, Apr 4, 2008 at 3:04 AM, Trans wrote: > > It's an interesting idea. What is needed is a Hash that can have key > > equality redefined. I seem to recall that 1.9 may have something for > > this, so as too allow indifferent key access, and it may work here too > > (using === instead of ==, or is it eql?) but I haven't explored it > > yet. > > Interesting idea, and it would work, but it wouldn't work very well as > you'll lost most of the advantage of hashing > > Say we limit ourselves to ranges of integers for now. Then for hashing > to work, any integer and any range that integer is in should have the > same hash value. This means that all integers a and b, a < b, have the > same hash value because a..b includes both, so both must have the same > hash value as a..b. This obviously also means that all such ranges > must have the same hash value. So although it will still work, the > hashing function will be very bad. You are right of course. And actually, I'm not sure it could even work, now that you mention these details. How could a..b and a..c have the same hash value in order to match the hash value of x such that a < x < b and a < x < c. -- Am I understanding this right? However, beyond that, I can imagine some sort of flexible and optimized Lookup class that uses a re-definable key match proc which could be quite handy. T.