in reply to mapping lists
It's not clear to me from your description, but is the thing you really want the set intersection of the set @F with 25..35 and with 50..75? If this is the case, maybe one of the Set:: or Array:: modules might be worth inspecting (Set::IntRange?). Although I'm not familiar with what's out there, I would assume there would be some modules out there highly optimized for the intersection operation.
If you're not looking for a set intersection, I don't see any obvious optimizations here, other than the possible sparseness of the reverse map that I mentioned.
Update: I noticed your code always returns a range, even if some of the intermediaries in the range aren't in @F. thinker gives a very nice algorithm for set intersection with a range, but if you need to always return a range (even including elements not in @F), here's an adaptation:
Depending on the data, this might be better than your original code. While this has to process your entire set of values, if the values are extremely sparse, you may end up ++'ing $lo and --'ing $hi all day in your algorithm.sub range{ my($lo, $hi) = @_; ($lo, $hi) = (sort grep {$_ >= $lo and $_ <= $hi} @F)[0,-1]; return $lo..$hi; }
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: mapping lists
by belg4mit (Prior) on Jan 24, 2003 at 19:52 UTC |