| 1 | package Graph::Matrix; | ||||||||||
| 2 | |||||||||||
| 3 | # $SIG{__DIE__ } = \&Graph::__carp_confess; | ||||||||||
| 4 | # $SIG{__WARN__} = \&Graph::__carp_confess; | ||||||||||
| 5 | |||||||||||
| 6 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 133 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 10 | 133 | my ($class, $g) = @_; | |||||||||
| 11 | 133 | my @V = $g->vertices; | |||||||||
| 12 | 133 | my $V = @V; | |||||||||
| 13 | 133 | my %V; @V{ @V } = 0 .. $#V; | |||||||||
| 14 | 133 | bless [ [ map [], 0 .. $#V ], \%V ], $class; | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 1541 | ▶ | sub set { | ||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 18 | 1541 | my ($m, $u, $v, $val) = @_; | |||||||||
| 19 | 1541 | my ($i, $j) = map $m->[1]->{ $_ }, ($u, $v); | |||||||||
| 20 | 1541 | $m->[0]->[$i]->[$j] = $val; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 3125 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 24 | 3125 | my ($m, $u, $v) = @_; | |||||||||
| 25 | 3125 | my ($i, $j) = map $m->[1]->{ $_ }, ($u, $v); | |||||||||
| 26 | 3125 | $m->[0]->[$i]->[$j]; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 2 | ▶ | sub stringify { | ||||||||
|
Subroutine
stringify: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 30 | 2 | my ($m) = @_; | |||||||||
| 31 | 2 | my @V = sort keys %{ $m->[1] }; | |||||||||
| 32 | 2 | my $top = join ' ', map sprintf('%4s', $_), 'to:', @V; | |||||||||
| 33 | 2 | my @indices = map $m->[1]{$_}, @V; | |||||||||
| 34 | 2 | my @rows; | |||||||||
| 35 | 2 | for my $n (@V) { | |||||||||
| 36 | 12 | my $this_row = $m->[0][ $m->[1]->{$n} ]; | |||||||||
| 37 | 12 | my @vals = map $this_row->[ $_ ], @indices; | |||||||||
| 38 | 12 | ▶ | push @rows, join ' ', map sprintf('%4s', defined()?$_:''), $n, @vals; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | } | ||||||||||
| 40 | 2 | join '', map "$_\n", $top, @rows; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 7 | 1; | |||||||||
| 44 | __END__ | ||||||||||