Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?by ikegami (Patriarch) |
on Jun 16, 2008 at 21:28 UTC ( [id://692375]=note: print w/replies, xml ) | Need Help?? |
Depending on your data, you might save a lot of memory by changing from to
For starters, you have way fewer values, and hashes are better for sparse data. You could even pack the data down if you know the range of the numbers.
fr_key( substr($branches, $i*4, 4) ) would be used instead of @{ $branches->[$i] }. Aside from that, moving to an iterator (as you suggested) would also help. Your current function generates *all* paths before returning. Instead, it could return a path as soon as it finds one. But before you do anything, are you sure the deep recursion is simply deep (not a problem, except you might run out of memory) and not infinite?
In Section
Seekers of Perl Wisdom
|
|