| 1 | package Graph::AdjacencyMatrix; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 7 | ▶ | use Graph::BitMatrix; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 7 | ▶ | use Graph::Matrix; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 7 | ▶ | use base 'Graph::BitMatrix'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 7 | ▶ | use Graph::AdjacencyMap qw(:flags :fields); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | sub _AM () { 0 } | ||||||||||||||
| 14 | sub _DM () { 1 } | ||||||||||||||
| 15 | sub _V () { 2 } # Graph::_V | ||||||||||||||
| 16 | sub _E () { 3 } # Graph::_E | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 75 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||
| 19 | 75 | my ($class, $g, %opt) = @_; | |||||||||||||
| 20 | 75 | my @V = $g->vertices; | |||||||||||||
| 21 | 75 | my $want_distance = delete $opt{distance_matrix}; | |||||||||||||
| 22 | 75 | my $d = Graph::_defattr(); | |||||||||||||
| 23 | 75 | ▶ | if (exists $opt{attribute_name}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | 1 | $d = delete $opt{attribute_name}; | |||||||||||||
| 25 | 1 | $want_distance++; | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | 75 | my $want_transitive = delete $opt{is_transitive}; | |||||||||||||
| 28 | 75 | Graph::_opt_unknown(\%opt); | |||||||||||||
| 29 | 75 | my $m = Graph::BitMatrix->new($g); | |||||||||||||
| 30 | 75 | my $self = bless [ $m, undef, \@V ], $class; | |||||||||||||
| 31 | 75 | ▶ | return $self if !$want_distance; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 72 | my $n = $self->[ _DM ] = Graph::Matrix->new($g); | |||||||||||||
| 33 | 72 | $n->set($_, $_, 0) for @V; | |||||||||||||
| 34 | 72 | my $n0 = $n->[0]; | |||||||||||||
| 35 | 72 | my $n1 = $n->[1]; | |||||||||||||
| 36 | 72 | my $undirected = $g->is_undirected; | |||||||||||||
| 37 | 72 | my $multiedged = $g->multiedged; | |||||||||||||
| 38 | 72 | for my $e ($g->edges) { | |||||||||||||
| 39 | 699 | my ($u, $v) = @$e; | |||||||||||||
| 40 | 699 | ▶ | $n->set($u, $v, $multiedged | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | ? _multiedged_distances($g, $u, $v, $d) | ||||||||||||||
| 42 | : $g->get_edge_attribute($u, $v, $d) | ||||||||||||||
| 43 | ); | ||||||||||||||
| 44 | 699 | ▶ | $n->set($v, $u, $multiedged | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 45 | ? _multiedged_distances($g, $v, $u, $d) | ||||||||||||||
| 46 | : $g->get_edge_attribute($v, $u, $d) | ||||||||||||||
| 47 | ) if $undirected; | ||||||||||||||
| 48 | } | ||||||||||||||
| 49 | 72 | $self; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 12 | ▶ | sub _multiedged_distances { | ||||||||||||
|
Subroutine
_multiedged_distances: called CC=4 SCAR=13.9
| |||||||||||||||
| 53 | 12 | my ($g, $u, $v, $attr) = @_; | |||||||||||||
| 54 | 12 | my %r; | |||||||||||||
| 55 | 12 | for my $id ($g->get_multiedge_ids($u, $v)) { | |||||||||||||
| 56 | 26 | my $w = $g->get_edge_attribute_by_id($u, $v, $id, $attr); | |||||||||||||
| 57 | 26 | ▶ | $r{$id} = $w if defined $w; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | } | ||||||||||||||
| 59 | 12 | ▶ | keys %r ? \%r : undef; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 71 | ▶ | sub adjacency_matrix { $_[0]->[ _AM ] } | ||||||||||||
|
Subroutine
adjacency_matrix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 63 | |||||||||||||||
| 64 | 61 | ▶ | sub distance_matrix { $_[0]->[ _DM ] } | ||||||||||||
|
Subroutine
distance_matrix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 65 | |||||||||||||||
| 66 | 1 | ▶ | sub vertices { @{ $_[0]->[ _V ] } } | ||||||||||||
|
Subroutine
vertices: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 67 | |||||||||||||||
| 68 | 2 | ▶ | sub is_adjacent { | ||||||||||||
|
Subroutine
is_adjacent: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 69 | 2 | my ($m, $u, $v) = @_; | |||||||||||||
| 70 | 2 | ▶ | $m->[ _AM ]->get($u, $v) ? 1 : 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 10 | ▶ | sub distance { | ||||||||||||
|
Subroutine
distance: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 74 | 10 | my ($m, $u, $v) = @_; | |||||||||||||
| 75 | 10 | ▶ | defined $m->[ _DM ] ? $m->[ _DM ]->get($u, $v) : undef; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 7 | 1; | |||||||||||||
| 79 | __END__ | ||||||||||||||