Graph/AdjacencyMap/Light.pm

filter: Statementstmt 100% 123 / 123 Branchbran 85.7% 60 / 70 Conditioncond 75.0% 12 / 16 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 25 / 25 Podpod 100% 10 / 10 totaltotal 91.3% 232 / 254 CC 47 SCAR 14.9
CC
47
Cov
93%
get_ids_by_paths
8.0
set_paths
7.0
del_path
6.0
CRAP 4.4
« Graph/UnionFind.pm ↑ Summary Graph/AdjacencyMatrix.pm »
1 package Graph::AdjacencyMap::Light;
2  
3 # THIS IS INTERNAL IMPLEMENTATION ONLY, NOT TO BE USED DIRECTLY.
4 # THE INTERFACE IS HARD TO USE AND GOING TO STAY THAT WAY AND
5 # ALMOST GUARANTEED TO CHANGE OR GO AWAY IN FUTURE RELEASES.
6  
7 82 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 82 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 82 ▶use Graph::AdjacencyMap qw(:flags :fields);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 82 ▶use base 'Graph::AdjacencyMap';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # $SIG{__DIE__ } = \&Graph::__carp_confess;
14 # $SIG{__WARN__} = \&Graph::__carp_confess;
15  
16 82 my @LOCAL_OVERRIDE = (_s, _p);
17  
18 sub _is_COUNT () { 0 }
19 sub _is_MULTI () { 0 }
20 sub _is_REF () { 0 }
21  
22 4345 ▶sub _new {
Subroutine _new: called CC=2 SCAR=6.9
23 4345 my ($class, $flags, $arity) = @_;
24 4345 (my $m = $class->SUPER::_new($flags | _LIGHT, $arity))->[ _attr ] = {};
25 4345 ▶ @$m[ @LOCAL_OVERRIDE ] = map $m->[ $_ ] ? [] : undef, @LOCAL_OVERRIDE;
Branch: 1 branch
BranchTrueFalseTotal
$m->[$_] ? : 2680 6010 8690
26 4345 $m;
27 }
28  
29 53538 ▶sub set_paths {
Subroutine set_paths: called CC=7 SCAR=19.5
Pod documented
30 53538 my ($m, @paths) = @_;
31 53538 my ($f, $a, $i, $pi, $map_s, $map_p, @ids) = (@$m[ _f, _arity, _i, _pi, _s, _p ]);
32 53538 for (@paths) {
33 79695 my $k = $_;
34 79695 ▶ Graph::__carp_confess("Wrong number of args, want $a, got (@$k)") if $a != 1 and $a != @$k;
Branch: 1 branch
BranchTrueFalseTotal
if $a != 1 and $a != @$k 0 79695 79695
Condition66%2/3
$a != 1 and $a != @$k
!ll&&!rl&&r
19460602350
MC/DC0%0/2
$a != 1 and $a != @$k
$a != 1 $a != @$k
Truth table66%2/3
A and B
A= $a != 1B= $a != @$k
ABresult
0X0
100
111
35 79695 ▶ my $l = $a == 1 ? $k : join ' ', @$k;
Branch: 1 branch
BranchTrueFalseTotal
$a == 1 ? : 19460 60235 79695
36 79695 ▶ push(@ids, $pi->{ $l }), next if defined $pi->{ $l };
Branch: 1 branch
BranchTrueFalseTotal
if defined $pi->{$l} 11955 67740 79695
37 67740 $i->[ my $n = $m->[ _n ]++ ] = $_;
38 67740 $pi->{ $l } = $n;
39 67740 push @ids, $n;
40 67740 ▶ _successors_add($f, $map_s, $map_p, $n, $_) if $map_s;
Branch: 1 branch
BranchTrueFalseTotal
if $map_s 49456 18284 67740
41 }
42 53538 @ids;
43 }
44  
45 49977 ▶sub _successors_set {
Subroutine _successors_set: called CC=4 SCAR=13.9
46 49977 my $val = pop;
47 49977 my ($f, $map_s, $map_p, $id, $path) = @_;
48 49977 my $pairs = Graph::AdjacencyMap::_successors_cartesian(($f & _UNORD), 0, $path);
49 82 ▶ no warnings 'uninitialized'; # needed 5.8
Subroutine BEGIN: called CC=1 SCAR=0.0
50 49977 vec($map_s->[ $_->[0] ], $_->[1], 1) = $val for @$pairs; # row-major
51 49977 ▶ return if !$map_p;
Branch: 1 branch
BranchTrueFalseTotal
unless $map_p 34976 15001 49977
52 15001 vec($map_p->[ $_->[1] ], $_->[0], 1) = $val for @$pairs;
53 }
54 49456 ▶sub _successors_add { push @_, 1; goto &_successors_set }
Subroutine _successors_add: called CC=1 SCAR=0.0
55 521 ▶sub _successors_del { push @_, 0; goto &_successors_set }
Subroutine _successors_del: called CC=1 SCAR=0.0
56  
57 1993 ▶sub _paths_fromto {
Subroutine _paths_fromto: called CC=6 SCAR=17.9
58 1993 my $offset = pop;
59 1993 my ($i, $pi, $f, $map_x, @v) = ( @{ $_[0] }[ _i, _pi, _f, $offset ], @_[1..$#_] );
60 1993 ▶ Graph::__carp_confess("undefined vertex") if grep !defined, @v;
Branch: 1 branch
BranchTrueFalseTotal
if grep((!defined($_)), @v) 0 1993 1993
61 1993 require Set::Object;
62 1993 my ($paths, $invert, $unord) = (Set::Object->new, $offset == _p, $f & _UNORD);
63 1993 for my $tuple (grep defined $_->[1], map [$_, $map_x->[$_]], @v) {
64 9816 my ($v, $s) = ($tuple->[0], scalar unpack("b*", $tuple->[1]));
65 9816 ▶ $paths->insert(join ' ', (
Branch: 3 branches
BranchTrueFalseTotal
$s =~ /1/g and do { $paths->insert(join(" ", $unord ? sort($v, pos($s) - 1) : ($invert ? (pos($s) - 1, $v) : ($v, pos($s) - 1)))) } 23233 9816 33049
$unord ? : 22792 441 23233
$invert ? : 178 263 441
66 $unord ? sort($v, pos($s) - 1) :
67 $invert ? (pos($s) - 1, $v) : ($v, pos($s) - 1)
68 )) while $s =~ /1/g;
69 }
70 1993 map $i->[ $pi->{ $_ } ], $paths->members;
71 }
72 1664 ▶sub paths_from { push @_, _s; goto &_paths_fromto }
Subroutine paths_from: called CC=1 SCAR=0.0
Pod documented
73 329 ▶sub paths_to { push @_, _p; goto &_paths_fromto }
Subroutine paths_to: called CC=1 SCAR=0.0
Pod documented
74  
75 37251 ▶sub _cessors {
Subroutine _cessors: called CC=4 SCAR=13.9
76 37251 my $offset = pop;
77 37251 my ($map_x, @v) = ( @{ $_[0] }[ $offset ], @_[1..$#_] );
78 37251 ▶ Graph::__carp_confess("undefined vertex") if grep !defined, @v;
Branch: 1 branch
BranchTrueFalseTotal
if grep((!defined($_)), @v) 0 37251 37251
79 37251 require Set::Object;
80 37251 my $c = Set::Object->new;
81 37251 for my $row (grep defined, @$map_x[ @v ]) {
82 # 10x quicker than: grep vec($row, $_, 1), 0..$#$m
83 36487 my $s = unpack("b*", $row);
84 36487 ▶ $c->insert(pos($s) - 1) while $s =~ /1/g;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /1/g and do { $c->insert(pos($s) - 1) } 147226 36487 183713
85 }
86 37251 $c->members;
87 }
88 35939 ▶sub successors { push @_, _s; goto &_cessors }
Subroutine successors: called CC=1 SCAR=0.0
Pod documented
89 1312 ▶sub predecessors { push @_, _p; goto &_cessors }
Subroutine predecessors: called CC=1 SCAR=0.0
Pod documented
90  
91 10 ▶sub has_successor {
Subroutine has_successor: called CC=3 SCAR=11.0
Pod documented
92 10 my ($map_s, $u, $v) = ( @{ $_[0] }[ _s ], @_[1, 2] );
93 10 ▶ Graph::__carp_confess("undefined vertex") if grep !defined, $u, $v;
Branch: 1 branch
BranchTrueFalseTotal
if grep((!defined($_)), $u, $v) 0 10 10
94 10 ▶ vec(($map_s->[ $u ] || return 0), $v, 1);
Condition100%2/2
$map_s->[$u] || (return 0)
l!l
82
MC/DC100%1/1
$map_s->[$u] || (return 0)
$map_s->[$u]
Truth table100%2/2
A
A= $map_s->[$u]
Aresult
11
00
95 }
96  
97 59929 ▶sub get_ids_by_paths {
Subroutine get_ids_by_paths: called CC=8 SCAR=20.8
Pod documented
98 59929 my ($pi, $m, $list, $ensure, $deep) = ( @{ $_[0] }[ _pi ], @_ );
99 59929 ▶ $deep ||= 0;
Condition100%2/2
$deep ||= 0
l!l
3867621253
MC/DC100%1/1
$deep ||= 0
$deep
Truth table100%2/2
A
A= $deep
Aresult
11
00
100 map {
101 59929 my @ret = map {
102 85252 my @ret2 = map {
103 140875 my $id = $pi->{ $_ };
104 140888 ▶ defined $id ? $id : $ensure ? $m->set_paths($_) : return;
Branch: 3 branches
BranchTrueFalseTotal
defined $id ? : 135305 5583 140888
$ensure ? : 5545 38 5583
$deep > 1 ? : 14 140861 140875
105 } $deep > 1 ? @$_ : $_;
106 140837 ▶ $deep > 1 ? \@ret2 : @ret2;
Branch: 2 branches
BranchTrueFalseTotal
$deep > 1 ? : 14 140823 140837
$deep ? : 55642 29610 85252
107 } $deep ? @$_ : $_;
108 85214 ▶ $deep ? \@ret : @ret;
Branch: 1 branch
BranchTrueFalseTotal
$deep ? : 55630 29584 85214
109 } @$list;
110 }
111  
112 1016 ▶sub has_path {
Subroutine has_path: called CC=4 SCAR=14.1
Pod documented
113 1016 my ($a, $pi, $k) = ( @{ $_[0] }[ _arity, _pi ], $_[1] );
114 1016 ▶ Graph::__carp_confess("Wrong number of args, want $a, got (@$k)") if $a != 1 and $a != @$k;
Branch: 1 branch
BranchTrueFalseTotal
if $a != 1 and $a != @$k 0 1016 1016
Condition66%2/3
$a != 1 and $a != @$k
!ll&&!rl&&r
579590
MC/DC0%0/2
$a != 1 and $a != @$k
$a != 1 $a != @$k
Truth table66%2/3
A and B
A= $a != 1B= $a != @$k
ABresult
0X0
100
111
115 1016 ▶ $pi->{ $a == 1 ? $k : join ' ', @$k };
Branch: 1 branch
BranchTrueFalseTotal
$a == 1 ? : 57 959 1016
116 }
117  
118 881 ▶sub _get_path_count {
Subroutine _get_path_count: called CC=2 SCAR=6.9
119 881 ▶ defined(my $dummy = &has_path) ? 1 : 0; # defined &x asks if func defined
Branch: 1 branch
BranchTrueFalseTotal
defined(my $dummy = &has_path) ? : 872 9 881
120 }
121  
122 556 ▶sub del_path {
Subroutine del_path: called CC=6 SCAR=18.0
Pod documented
123 556 my ($f, $a, $i, $pi, $map_s, $map_p, $attr, $k) = ( @{ my $m = $_[0] }[ _f, _arity, _i, _pi, _s, _p, _attr ], $_[1] );
124 556 ▶ Graph::__carp_confess("Wrong number of args, want $a, got (@$k)") if $a != 1 and $a != @$k;
Branch: 1 branch
BranchTrueFalseTotal
if $a != 1 and $a != @$k 0 556 556
Condition66%2/3
$a != 1 and $a != @$k
!ll&&!rl&&r
285280
MC/DC0%0/2
$a != 1 and $a != @$k
$a != 1 $a != @$k
Truth table66%2/3
A and B
A= $a != 1B= $a != @$k
ABresult
0X0
100
111
125 556 ▶ my $l = $a == 1 ? $k : join ' ', @$k;
Branch: 1 branch
BranchTrueFalseTotal
$a == 1 ? : 28 528 556
126 556 ▶ return 0 if !exists $pi->{ $l };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $pi->{$l} 7 549 556
127 549 my $id = delete $pi->{ $l };
128 549 delete $attr->{ $l };
129 549 my $path = delete $i->[ $id ];
130 549 ▶ _successors_del($f, $map_s, $map_p, $id, $path) if $map_s;
Branch: 1 branch
BranchTrueFalseTotal
if $map_s 521 28 549
131 549 return 1;
132 }
133  
134 12 ▶sub rename_path {
Subroutine rename_path: called CC=4 SCAR=14.0
Pod documented
135 12 my ($m, $from, $to) = @_;
136 12 my ($a, $i, $pi, $attr) = @$m[ _arity, _i, _pi, _attr ];
137 12 ▶ return 1 if $a > 1; # arity > 1, all integers, no names
Branch: 1 branch
BranchTrueFalseTotal
if $a > 1 0 12 12
138 12 ▶ return 0 unless exists $pi->{ $from };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $pi->{$from} 0 12 12
139 12 ▶ $attr->{ $to } = delete $attr->{ $from } if $attr->{ $from };
Branch: 1 branch
BranchTrueFalseTotal
if $attr->{$from} 2 10 12
140 12 $i->[ $pi->{ $to } = delete $pi->{ $from } ] = $to;
141 12 return 1;
142 }
143  
144 5800 ▶sub _set_path_attr_common {
Subroutine _set_path_attr_common: called CC=2 SCAR=6.9
145 5800 (my $m = $_[0])->set_paths($_[1]);
146 5800 my ($a, $attr, $k) = ( @$m[ _arity, _attr ], $_[1] );
147 5800 ▶ my $l = $a == 1 ? $k : join ' ', @$k;
Branch: 1 branch
BranchTrueFalseTotal
$a == 1 ? : 1169 4631 5800
148 5800 \$attr->{ $l };
149 }
150  
151 12267 ▶sub _get_path_attrs {
Subroutine _get_path_attrs: called CC=4 SCAR=14.0
152 12267 my ($a, $attr, $k) = ( @{ $_[0] }[ _arity, _attr ], $_[1] );
153 12267 ▶ Graph::__carp_confess("Wrong number of args, want $a, got (@$k)") if $a != 1 and $a != @$k;
Branch: 1 branch
BranchTrueFalseTotal
if $a != 1 and $a != @$k 0 12267 12267
Condition66%2/3
$a != 1 and $a != @$k
!ll&&!rl&&r
397118700
MC/DC0%0/2
$a != 1 and $a != @$k
$a != 1 $a != @$k
Truth table66%2/3
A and B
A= $a != 1B= $a != @$k
ABresult
0X0
100
111
154 12267 ▶ my $l = $a == 1 ? $k : join ' ', @$k;
Branch: 1 branch
BranchTrueFalseTotal
$a == 1 ? : 397 11870 12267
155 12267 $attr->{ $l };
156 }
157  
158 13 ▶sub _del_path_attrs {
Subroutine _del_path_attrs: called CC=4 SCAR=13.9
159 13 ▶ return undef unless defined &has_path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined &Graph::AdjacencyMap::Light::has_path 0 13 13
160 13 my ($a, $attr, $k) = ( @{ $_[0] }[ _arity, _attr ], $_[1] );
161 13 ▶ my $l = $a == 1 ? $k : join ' ', @$k;
Branch: 1 branch
BranchTrueFalseTotal
$a == 1 ? : 5 8 13
162 13 ▶ return 0 unless exists $attr->{ $l };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attr->{$l} 2 11 13
163 11 delete $attr->{ $l };
164 11 1;
165 }
166  
167 82 1;
« Graph/UnionFind.pm ↑ Summary Graph/AdjacencyMatrix.pm »