1package Graph::Matrix;
2
3# $SIG{__DIE__ } = sub { use Carp; confess };
4# $SIG{__WARN__} = sub { use Carp; confess };
5
6use strict;
7
8sub new {
9    my ($class, $g) = @_;
10    my @V = $g->vertices;
11    my $V = @V;
12    my %V; @V{ @V } = 0 .. $#V;
13    bless [ [ map { [ ] } 0 .. $#V ], \%V ], $class;
14}
15
16sub set {
17    my ($m, $u, $v, $val) = @_;
18    my ($i, $j) = map { $m->[1]->{ $_ } } ($u, $v);
19    $m->[0]->[$i]->[$j] = $val;
20}
21
22sub get {
23    my ($m, $u, $v) = @_;
24    my ($i, $j) = map { $m->[1]->{ $_ } } ($u, $v);
25    $m->[0]->[$i]->[$j];
26}
27
281;
29__END__
30=pod
31
32=head1 NAME
33
34Graph::Matrix - create and manipulate a V x V matrix of graph G
35
36=head1 SYNOPSIS
37
38    use Graph::Matrix;
39    use Graph::Directed;
40    my $g  = Graph::Directed->new;
41    $g->add_...(); # build $g
42    my $m = Graph::Matrix->new($g);
43    $m->get($u, $v)
44    $s->get($u, $v, $val)
45
46=head1 DESCRIPTION
47
48B<This module is meant for internal use by the Graph module.>
49
50=head2 Class Methods
51
52=over 4
53
54=item new($g)
55
56Construct a new Matrix from the Graph $g.
57
58=back
59
60=head2 Object Methods
61
62=over 4
63
64=item get($u, $v)
65
66Return the value at the edge from $u to $v.
67
68=item set($u, $v, $val)
69
70Set the edge from $u to $v to value $val.
71
72=back
73
74=head1 AUTHOR AND COPYRIGHT
75
76Jarkko Hietaniemi F<jhi@iki.fi>
77
78=head1 LICENSE
79
80This module is licensed under the same terms as Perl itself.
81
82=cut
83