NASM 2.01rc1
[nasm/avx512.git] / perllib / Graph / Matrix.pm
blobd3b9d407d86811c04168519d4c902d0c39500065
1 package Graph::Matrix;
3 # $SIG{__DIE__ } = sub { use Carp; confess };
4 # $SIG{__WARN__} = sub { use Carp; confess };
6 use strict;
8 sub 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;
16 sub set {
17 my ($m, $u, $v, $val) = @_;
18 my ($i, $j) = map { $m->[1]->{ $_ } } ($u, $v);
19 $m->[0]->[$i]->[$j] = $val;
22 sub get {
23 my ($m, $u, $v) = @_;
24 my ($i, $j) = map { $m->[1]->{ $_ } } ($u, $v);
25 $m->[0]->[$i]->[$j];
29 __END__
30 =pod
32 =head1 NAME
34 Graph::Matrix - create and manipulate a V x V matrix of graph G
36 =head1 SYNOPSIS
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)
46 =head1 DESCRIPTION
48 B<This module is meant for internal use by the Graph module.>
50 =head2 Class Methods
52 =over 4
54 =item new($g)
56 Construct a new Matrix from the Graph $g.
58 =back
60 =head2 Object Methods
62 =over 4
64 =item get($u, $v)
66 Return the value at the edge from $u to $v.
68 =item set($u, $v, $val)
70 Set the edge from $u to $v to value $val.
72 =back
74 =head1 AUTHOR AND COPYRIGHT
76 Jarkko Hietaniemi F<jhi@iki.fi>
78 =head1 LICENSE
80 This module is licensed under the same terms as Perl itself.
82 =cut