1 |
sashby |
1.2 |
package Graph::Directed;
|
2 |
|
|
use strict;
|
3 |
|
|
local $^W = 1;
|
4 |
|
|
use Graph::Base;
|
5 |
|
|
use vars qw(@ISA);
|
6 |
|
|
@ISA = qw(Graph::Base);
|
7 |
|
|
|
8 |
|
|
sub new
|
9 |
|
|
{
|
10 |
|
|
my $class = shift;
|
11 |
|
|
my $G = Graph::Base->new(@_);
|
12 |
|
|
|
13 |
|
|
bless $G, $class;
|
14 |
|
|
$G->directed(1);
|
15 |
|
|
return $G;
|
16 |
|
|
}
|
17 |
|
|
|
18 |
|
|
sub _edges
|
19 |
|
|
{
|
20 |
|
|
my ($G, $u, $v) = @_;
|
21 |
|
|
my @e;
|
22 |
|
|
|
23 |
|
|
if (defined $u and defined $v)
|
24 |
|
|
{
|
25 |
|
|
@e = ($u, $v)
|
26 |
|
|
if exists $G->{ Succ }->{ $u }->{ $v };
|
27 |
|
|
}
|
28 |
|
|
elsif (defined $u)
|
29 |
|
|
{
|
30 |
|
|
foreach $v ($G->successors($u))
|
31 |
|
|
{
|
32 |
|
|
push @e, $G->_edges($u, $v);
|
33 |
|
|
}
|
34 |
|
|
}
|
35 |
|
|
elsif (defined $v)
|
36 |
|
|
{ # not defined $u and defined $v
|
37 |
|
|
foreach $u ($G->predecessors($v))
|
38 |
|
|
{
|
39 |
|
|
push @e, $G->_edges($u, $v);
|
40 |
|
|
}
|
41 |
|
|
}
|
42 |
|
|
else
|
43 |
|
|
{ # not defined $u and not defined $v
|
44 |
|
|
foreach $u ($G->vertices)
|
45 |
|
|
{
|
46 |
|
|
push @e, $G->_edges($u);
|
47 |
|
|
}
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
return @e;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
1;
|