Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: retrieve next avaiable element in sorted hash

by jmanning2k (Pilgrim)
on Oct 07, 2003 at 17:35 UTC ( [id://297346]=note: print w/replies, xml ) Need Help??


in reply to retrieve next avaiable element in sorted hash

Why don't you keep a pre-sorted index array of all the hash keys along with your hash. This would only have to be regenerated when you add or remove hash elements.

Then, you can use a binary search to look up your hash key in the index array and return the next largest key.

This eliminates the sort involved with each lookup, which I would guess is the biggest slowdown to your current code.

It also changes your search from simple to binary, which should cut the search time by an order of magnitude.

  • Comment on Re: retrieve next avaiable element in sorted hash

Replies are listed 'Best First'.
Re: Re: retrieve next avaiable element in sorted hash
by vinforget (Beadle) on Oct 07, 2003 at 20:44 UTC
    Thanks. This seems like a good general approach. Just what I was looking for. Vince

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-25 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found