Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Optimized Previous and Next Accessors

by tedv (Pilgrim)
on Dec 12, 2000 at 08:26 UTC ( #46211=note: print w/ replies, xml ) Need Help??


in reply to Re: Finding Previous and Next in a HASH
in thread Finding Previous and Next in a HASH

You can get away with $keys[$index-1] and $keys[($index+1) % @keys] because the first array access, should it be negative, will access from the back of the array, and the last array access is guaranteed to be in range. So no extra checking is needed for boundaries.

-Ted


Comment on Optimized Previous and Next Accessors
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2015-07-08 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (96 votes), past polls