in reply to Re: Comparing a value to a list of numbers
in thread Comparing a value to a list of numbers

Well, there is another question lurking behind, which is IMHO not too tangential

What if large ranges are involved? The OP showed at least a little one with 41-56.

I'm sure a binary search would outperform a hash then.°

(Of course not if using random keys like you did)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

update

°) Well I need to be more precise: Large ranges are sometimes not practicable with hashes because of the memory complexity. This could lead to heavy swapping operations.

Having a little slower code with binary search O(ln) is often better than hash lookup with O(1)

  • Comment on Re^2: Comparing a value to a list of numbers