What I did at the end was:
- The challenge is to find all paths of length N between two nodes. Cycles excluded.
- - , . - > ( )
- - ( unordered_map boost stl, ++) node - .
- - , node .
A->B
A->C
B->D
C->E
E->D
, perl-, "edgelist":
my %hash = (
'A' => {'B' => 1, 'C' => 1},
'B' => {'D' => 1},
'C' => {'E' => 1},
'E' => {'D' => 1},
);
, DIRECTLY , (perl):
sub search {
my ($from,$to) = @_;
if( $to eq '*' ){ return defined($x=$hash{$from}) ? [keys $hash{$from}] : [] }
return defined($x=$hash{$from}) && defined($x{$to}) ? [$to] : []
}
, a 'from' node, $to '*'. , $from.
.
.
sub path {
my ($from,$to, $hops, $save_results) = @_;
if( $hops < 0 ){ return 0 }
$results = search($from, '*');
if( "".@$results == 0 ){ return 0 }
$found = 0;
foreach $result (@$results){
$a_node = new Tree::Nary($result);
if( path($result, $to, $hops-1, $a_node) == 1 ){
$save_results->insert($save_results, -1, $a_node);
$found = 1;
}
}
return $found;
}
, (.. $hops < 6?) - [sic].
- . Tree:: Nary (n-arry tree) . :
|-> B -> D
A -> |-> C -> E -> D
, :
perl, ++, boost:: unordered_map hashtable. ++.
: 3281415 18601 perl 3 , A → '*' → '*' → B. , ++.