Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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.

Replies are listed 'Best First'.
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.


    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.


        New address of my CGI Course.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2021-04-17 04:58 GMT
Find Nodes?
    Voting Booth?

    No recent polls found