Oh, if only life were so easy. :^)

Basically, the algorithm recursively processes this data structure, and deeper levels of the recursion rely on earlier levels having removed branches of the structure. This pruning effectively stops previously processed and rejected branches of the data being reprocessed at any given level.

However, as the recursion unwinds (having so far failed to resolve the solution), I need to restore the pruned branches in order that they may be considered when walking other branches taken higher (shallower) in the recursion process. The structure contains many cross-references at the leaf nodes. It is these that get pruned as the process progresses at the deeper levels, but that must be restored as the recursion unwinds.

The routine only selectively clones subtrees at any given level and passes these in when it recurses, so it is, in effect, tracking the changes and unwinding them. but given that the nature and depth of the structure is variable between runs, coming up with a generalised alternative tracking mechanism is more complex (and costly) than cloning the subtrees to lexicals as I go.


Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.


In reply to Re: Re: Deepcopy of complex structures. by BrowserUk
in thread Deepcopy of complex structures. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.