line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graph::Matrix; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $SIG{__DIE__ } = \&Graph::__carp_confess; |
4
|
|
|
|
|
|
|
# $SIG{__WARN__} = \&Graph::__carp_confess; |
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
43
|
use strict; |
|
7
|
|
|
|
|
57
|
|
|
7
|
|
|
|
|
189
|
|
7
|
7
|
|
|
7
|
|
32
|
use warnings; |
|
7
|
|
|
|
|
23
|
|
|
7
|
|
|
|
|
2606
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
133
|
|
|
133
|
1
|
301
|
my ($class, $g) = @_; |
11
|
133
|
|
|
|
|
291
|
my @V = $g->vertices; |
12
|
133
|
|
|
|
|
249
|
my $V = @V; |
13
|
133
|
|
|
|
|
179
|
my %V; @V{ @V } = 0 .. $#V; |
|
133
|
|
|
|
|
539
|
|
14
|
133
|
|
|
|
|
942
|
bless [ [ map [], 0 .. $#V ], \%V ], $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub set { |
18
|
1523
|
|
|
1523
|
1
|
2424
|
my ($m, $u, $v, $val) = @_; |
19
|
1523
|
|
|
|
|
3273
|
my ($i, $j) = map $m->[1]->{ $_ }, ($u, $v); |
20
|
1523
|
|
|
|
|
3399
|
$m->[0]->[$i]->[$j] = $val; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub get { |
24
|
3125
|
|
|
3125
|
1
|
4197
|
my ($m, $u, $v) = @_; |
25
|
3125
|
|
|
|
|
6439
|
my ($i, $j) = map $m->[1]->{ $_ }, ($u, $v); |
26
|
3125
|
|
|
|
|
6734
|
$m->[0]->[$i]->[$j]; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub stringify { |
30
|
2
|
|
|
2
|
1
|
5
|
my ($m) = @_; |
31
|
2
|
|
|
|
|
5
|
my @V = sort keys %{ $m->[1] }; |
|
2
|
|
|
|
|
16
|
|
32
|
2
|
|
|
|
|
20
|
my $top = join ' ', map sprintf('%4s', $_), 'to:', @V; |
33
|
2
|
|
|
|
|
10
|
my @indices = map $m->[1]{$_}, @V; |
34
|
2
|
|
|
|
|
5
|
my @rows; |
35
|
2
|
|
|
|
|
6
|
for my $n (@V) { |
36
|
12
|
|
|
|
|
21
|
my $this_row = $m->[0][ $m->[1]->{$n} ]; |
37
|
12
|
|
|
|
|
32
|
my @vals = map $this_row->[ $_ ], @indices; |
38
|
12
|
100
|
|
|
|
92
|
push @rows, join ' ', map sprintf('%4s', defined()?$_:''), $n, @vals; |
39
|
|
|
|
|
|
|
} |
40
|
2
|
|
|
|
|
30
|
join '', map "$_\n", $top, @rows; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
__END__ |