Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Comparing a value to a list of numbers

by LanX (Cardinal)
on Jan 29, 2021 at 17:40 UTC ( #11127652=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11127652]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2021-06-18 19:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (90 votes). Check out past polls.

    Notices?