package Graph
::Undirected
;
use overload
'""' => \
&stringify
;
Graph::Directed - directed graphs
$g = new Graph::Directed;
See Graph::Base for the available methods.
Copyright 1999, O'Reilly & Associates.
This code is distributed under the same copyright terms as Perl itself.
# $U = Graph::Undirected->new(@V)
# The Constructor. Returns a new undirected graph $U, possibly
# populated with the optional initial vertices @V.
my $G = Graph
::Base
->new(@_);
return $G->_stringify("=", ",");
return ref $H ?
$G->stringify eq $H->stringify : $G->stringify eq $H;
# @e = $G->_edges($u, $v, $E)
# Both vertices undefined:
# returns all the edges of the graph.
# returns all the edges between the vertices.
# Only 1st vertex defined:
# returns all the edges at the vertex.
# Only 2nd vertex defined:
# returns all the edges at the vertex.
# The already seen vertices are recorded in $E.
# Edges @e are returned as ($start_vertex, $end_vertex) pairs.
my ($G, $u, $v, $E) = @_;
$E = { } unless defined $E;
if (defined $u and defined $v) {
if (exists $G->{ Succ
}->{ $u }->{ $v }) {
if not $E->{ $u }->{ $v } and
$E->{ $u }->{ $v } = $E->{ $v }->{ $u } = 1;
foreach $v ($G->successors($u)) {
push @e, $G->_edges($u, $v);
foreach $u ($G->predecessors($v)) {
push @e, $G->_edges($u, $v);
foreach $u ($G->vertices) {