Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: An iterator for (not "iterating") a recursive data structure.

by LanX (Archbishop)
on Jul 13, 2019 at 20:13 UTC ( #11102799=note: print w/replies, xml ) Need Help??


in reply to Re^2: An iterator for (not "iterating") a recursive data structure.
in thread An iterator for (not "iterating") a recursive data structure.

> duplicating that on a stack would blow my memory.

It's not duplicating the memory, just caching the current path from root to leave, very similar to my solution here

Worst case scenario with a balanced two level "tree" would mean approx @stack == 2*sqrt(@nodes) .

For 200 million elements that's about 28000 elements.

If that's still to many store a lazy iterator in the @stack returning the children of one node (like a function ref or an object or a tied array) and process it in the iterator.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

  • Comment on Re^3: An iterator for (not "iterating") a recursive data structure.
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2020-05-25 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (146 votes). Check out past polls.

    Notices?