in reply to Re: Partial sort for dependency graph
in thread Partial sort for dependency graph

t_d_o would have to do a tree walk, true, but if it cached the result then t_d_o would not be that inefficient.
  • Comment on Re^2: Partial sort for dependency graph

Replies are listed 'Best First'.
Re^3: Partial sort for dependency graph
by jbert (Priest) on Nov 11, 2006 at 16:55 UTC
    I haven't thought it through in detail, but I would guess that (memoising t_d_o) would only help if the sort algo called the comparator multiple times for the same pair of $a and $b, which it presumably avoids doing as far as possible.

    Inefficiency is in the eye of the beholder anyway. If it turns out to be the difference between 10ms and 100ms on the problem in question then it probably doesn't matter...

    To fill in the missing piece, I guess t_d_o could look something like (sadly untested, so apologies for any craziness):

    sub t_d_o { my $s = shift; my $obj = shift; return 1 if $s eq $obj; # String compare on objects ok? foreach my $dependency ($s->dependencies) { return 1 if $dependency->t_d_o($obj); # Inf. loop on cycles. Whee. } return undef; }
    Hmmm...in which case memoising might help a lot (on the recursive steps) - you'd end up storing approx N^2 t_d_o values (for N objects).