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

S'fine for small AoAoA..s, but the top level array in my application will contain upto 200 million elements -- circa. 7GB -- duplicating that on a stack would blow my memory.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
  • Comment on Re^2: An iterator for (not "iterating") a recursive data structure.

Replies are listed 'Best First'.
Re^3: An iterator for (not "iterating") a recursive data structure.
by LanX (Saint) on Jul 13, 2019 at 20:13 UTC
    > 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