Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: getting hash key with value

by sundialsvc4 (Abbot)
on Apr 16, 2008 at 01:51 UTC ( [id://680715]=note: print w/replies, xml ) Need Help??


in reply to getting hash key with value

It all depends on how many thousand entries are in your hash to begin with. If the number is reasonable and you don't do it too often, it just might be simplest and quickest (if slightly aromatic...) to just iterate through the hash sequentially. In other words, you might get away with it.

Otherwise, you're going to have to create a reverse-hash, and each slot in that reverse-hash can contain either a single value, or an array-reference containing a list of values.

The tradeoff, as usual, is the usual one: speed versus space. By building a reverse-hash you just at-least-doubled your storage requirement... but it's fast.

The “brute force search” may or may not be so-bad. If the hash is very large and virtual-storage is not, then the potential exists that walking through that hash is going to trigger a slew of page-faults every time, and that's really bad. But if storage is plentiful then it's all probably sitting in real-RAM anyway and you can just blip-through all that storage at CPU-speed. So basically it comes down to the practical likelihood of page-faults.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found