Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Efficient partial deep cloning

by jbert (Priest)
on Jan 08, 2008 at 12:06 UTC ( #661067=note: print w/ replies, xml ) Need Help??


in reply to Efficient partial deep cloning

Walking the data structure and finding the elements is one way to do it (can there be more than one such elt? Do you need to worry about cycles in the structure?).

But it seems to me that these data structures have meta-information which you aren't currently storing. If you want efficiency you should store that information rather than recalculate it via a search.

One way to do this would be to wrap accesses to the data structure so that when a logic var is added to it, it's position is remembered (perhaps in some kind of inside-out object attribute stash). I'd do it this way, with a class around the data structure (add a "addLogicVar" method) although you could use TIE I guess.


Comment on Re: Efficient partial deep cloning
Re^2: Efficient partial deep cloning
by Ovid (Cardinal) on Jan 08, 2008 at 12:09 UTC

    I forgot about cycles, so yes, I need to worry about those. Damn.

    Cheers,
    Ovid

    New address of my CGI Course.

      Can't you use something like the reference of the current "thing" and the "thing" to be considered to be copied as a key in a hashset? Everytime you encounter those two things in that relationsip, process it once and only once?

      Or.. create an algorithm to do a breadth first search (can be less memory intense) to discover all edges and copy them in a graph?

        In my current implementation, I use a %seen hash which tracks those references. Very easy to implement.

        Cheers,
        Ovid

        New address of my CGI Course.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-11-28 12:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (196 votes), past polls