| 1 | package Graph::Maker::BalancedTree; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use base qw/Graph::Maker/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Graph; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub init | ||||||||||||||||||||||||||||
| 12 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=14 SCAR=27.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 2 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | my $b = delete($params{fan_out}); | |||||||||||||||||||||||||||
| 16 | 2 | my $h = delete($params{height}); | |||||||||||||||||||||||||||
| 17 | 2 | my $gm = delete($params{graph_maker}); | |||||||||||||||||||||||||||
| 18 | 2 | ▶ | croak "graph_maker must be a reference to a function that creates a Graph.\n" if $gm && ref($gm) ne 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$gm and ref $gm ne "CODE"
MC/DC0%0/2
$gm and ref $gm ne "CODE"
$gm
ref $gm ne "CODE"
Truth table33%1/3
A and B
A= $gmB= ref $gm ne "CODE"
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | $gm ||= sub { new Graph(@_); }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$gm ||= sub {
"Graph"->new(@_);
}
MC/DC0%0/2
$gm ||= sub {
"Graph"->new(@_);
}
$gm
sub {
"Graph"->new(@_);
}
Truth table33%1/3
A ||= B
A= $gmB= sub {
"Graph"->new(@_);
}
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | croak "fan_out must be defined and at least 2\n" unless defined $b && $b >= 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $b and $b >= 2
MC/DC0%0/2
defined $b and $b >= 2
defined $b
$b >= 2
Truth table33%1/3
A and B
A= defined $bB= $b >= 2
| |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | croak "h must be defined and positive\n" unless defined $h && $h >= 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $h and $h >= 1
MC/DC0%0/2
defined $h and $h >= 1
defined $h
$h >= 1
Truth table33%1/3
A and B
A= defined $hB= $h >= 1
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | my $g = $gm->(%params); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # First handle the root | ||||||||||||||||||||||||||||
| 27 | 2 | my $v = 2; # the vertex number | |||||||||||||||||||||||||||
| 28 | 2 | my @newLeaves; # the set of new leaves | |||||||||||||||||||||||||||
| 29 | 2 | for (1..$b) | |||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||
| 31 | 6 | push(@newLeaves, $v); | |||||||||||||||||||||||||||
| 32 | 6 | $g->add_edge(1, $v); | |||||||||||||||||||||||||||
| 33 | 6 | ▶ | $g->add_edge($v, 1) unless $g->is_undirected(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 6 | $v++; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # Now the rest | ||||||||||||||||||||||||||||
| 38 | 2 | for (2..$h-1) | |||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 2 | my @leaves = @newLeaves; | |||||||||||||||||||||||||||
| 41 | 2 | @newLeaves = (); | |||||||||||||||||||||||||||
| 42 | 2 | foreach my $l(@leaves) | |||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||
| 44 | 6 | for (1..$b) | |||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | 18 | push(@newLeaves, $v); | |||||||||||||||||||||||||||
| 47 | 18 | $g->add_edge($l, $v); | |||||||||||||||||||||||||||
| 48 | 18 | ▶ | $g->add_edge($v, $l) unless $g->is_undirected(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 18 | $v++; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | return $g; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | Graph::Maker->add_factory_type( 'balanced_tree' => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | __DATA__ | ||||||||||||||||||||||||||||