Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: inline perl and recursion

by jackdied (Monk)
on Aug 07, 2002 at 20:38 UTC ( [id://188451]=note: print w/replies, xml ) Need Help??


in reply to inline perl and recursion

Inline::C would likely be more complicated that it is worth. You may be able to squeeze some more uumph out of the perl version, as the poster above pointed out.

If you are recalculating this more than once (it doesn't look like you are) you could have the children notify the parent when their own depth changes. This way you wouldn't have to recalc the whole tree if just a couple changed.

If you are only doing this once, you could try some other optimizations. Keep two lists of children in the parent, one for object type #1's (which have variable depth) and the main list which has all objects. If the max depth of the #1s list is greater than one, just use that. If there are alot of #2 nodes, you save the function call overhead. Not great OO, but if you need the speed ...

You could try something like

sub depth { my $self = shift; return $self->{myDepth} = shift(sort map{ $_->depth(); } @{$self->{chi +ld}}[0:14]) + 1; }
To speed up the inner loop as well. That might have a touch of python syntax in it, but it is close to what you want.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found