Maker/Utils.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 93.3% 56 / 60 CC 13 SCAR 18.3
CC
13
Cov
92%
is_valid_degree_seq
9.3
cartesian_product
5.0
BEGIN
1.0
CRAP 6.3
« Maker/CompleteBipartite.pm ↑ Summary Maker/Star.pm »
1 package Graph::Maker::Utils;
2
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Exporter 'import'; # gives you Exporter's import() method directly
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 our @EXPORT_OK = qw(cartesian_product is_valid_degree_seq); # symbols to export on request
8 7 our %EXPORT_TAGS = (all => [@EXPORT_OK]);
9
10 7 our $VERSION = '0.02';
11
12 sub cartesian_product
13 19 ▶{
Subroutine cartesian_product: called CC=5 SCAR=16.1
Pod documented
14 19 my ($g, $h) = @_;
15
16 19 my $p = $g->copy();
17 19 $p->delete_vertices($g->vertices());
18
19 19 my $G = $g->vertices();
20
21 19 foreach my $e($h->edges())
22 {
23 104 foreach my $v($g->vertices())
24 {
25 308 $p->add_edge($v + $G*($e->[0]-1), $v + $G*($e->[1]-1));
26 }
27 }
28
29 19 foreach my $e($g->edges())
30 {
31 61 foreach my $v($h->vertices())
32 {
33 247 $p->add_edge($e->[0] + $G*($v-1), $e->[1] + $G*($v-1));
34 }
35 }
36 19 return $p;
37 }
38
39 # BIG BIG copy from NetworkX, only rewrote...
40 sub is_valid_degree_seq
41 12 ▶{
Subroutine is_valid_degree_seq: called CC=9 SCAR=22.3
Pod documented
42 12 my (@seq) = @_;
43
44 12 ▶ return 1 if @seq == 0; # good if empty
Branch: 1 branch
BranchTrueFalseTotal
if @seq == 0 0 12 12
45 12 my $s = 0;
46 12 $s += $_ foreach (@seq);
47 12 ▶ return 0 if $s & 1; # must be even
Branch: 1 branch
BranchTrueFalseTotal
if $s & 1 2 10 12
48
49 10 ▶ while(@seq)
Branch: 1 branch
BranchTrueFalseTotal
if (@seq) 25 0 25
50 {
51 25 @seq = reverse sort {$a<=>$b} @seq;
52
53 25 ▶ return 0 if $seq[0] < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $seq[0] < 0 0 25 25
54
55 25 my $d = pop(@seq);
56 25 ▶ return 1 if $d == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $d == 0 9 16 25
57
58 16 ▶ return 0 if $d > @seq;
Branch: 1 branch
BranchTrueFalseTotal
if $d > @seq 1 15 16
59
60 15 $seq[@seq-$_]-- for (1..$d);
61 }
62
63 0 return 0;
64 }
65
66 __DATA__
« Maker/CompleteBipartite.pm ↑ Summary Maker/Star.pm »