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

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).