in reply to Re^10: Finding All Paths From a Graph From a Given Source and End Node
in thread Finding All Paths From a Graph From a Given Source and End Node
Simply avoiding the array-copy my @path=@_ makes a factor 4.5 performance boost...
Fascinating!!! What a pity Perl doesn't support aliasing out of the box!
{ my %seen; sub track { my $last=$_[-1]; $seen{$last}=1; for my $next (@{$graph{$last}}) { next if $seen{$next}; if ($next eq $stop) { #print join ("->",@_,$stop),"\n"; $anzahl++; print "$anzahl at ",time-$time0,"\n" if $anzahl%10000==0; } else { track(@_,$next); } } delete $seen{$last}; } }
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^12: Finding All Paths From a Graph From a Given Source and End Node
by BrowserUk (Patriarch) on Nov 02, 2010 at 19:43 UTC | |
by LanX (Saint) on Nov 02, 2010 at 20:23 UTC | |
by BrowserUk (Patriarch) on Nov 02, 2010 at 20:33 UTC | |
by LanX (Saint) on Nov 02, 2010 at 20:39 UTC | |
by BrowserUk (Patriarch) on Nov 02, 2010 at 21:14 UTC |