Graph::Matrix - create and manipulate a V x V matrix of graph G


Graph documentation Contained in the Graph distribution.

Index


Code Index:

NAME

Top

Graph::Matrix - create and manipulate a V x V matrix of graph G

SYNOPSIS

Top

    use Graph::Matrix;
    use Graph::Directed;
    my $g  = Graph::Directed->new;
    $g->add_...(); # build $g
    my $m = Graph::Matrix->new($g);
    $m->get($u, $v)
    $s->get($u, $v, $val)

DESCRIPTION

Top

This module is meant for internal use by the Graph module.

Class Methods

new($g)

Construct a new Matrix from the Graph $g.

Object Methods

get($u, $v)

Return the value at the edge from $u to $v.

set($u, $v, $val)

Set the edge from $u to $v to value $val.

AUTHOR AND COPYRIGHT

Top

LICENSE

Top

This module is licensed under the same terms as Perl itself.


Graph documentation Contained in the Graph distribution.

package Graph::Matrix;

# $SIG{__DIE__ } = sub { use Carp; confess };
# $SIG{__WARN__} = sub { use Carp; confess };

use strict;

sub new {
    my ($class, $g) = @_;
    my @V = $g->vertices;
    my $V = @V;
    my %V; @V{ @V } = 0 .. $#V;
    bless [ [ map { [ ] } 0 .. $#V ], \%V ], $class;
}

sub set {
    my ($m, $u, $v, $val) = @_;
    my ($i, $j) = map { $m->[1]->{ $_ } } ($u, $v);
    $m->[0]->[$i]->[$j] = $val;
}

sub get {
    my ($m, $u, $v) = @_;
    my ($i, $j) = map { $m->[1]->{ $_ } } ($u, $v);
    $m->[0]->[$i]->[$j];
}

1;
__END__