DataStructure/BTree/Node.pm

filter: Statementstmt 29.3% 22 / 75 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 36.8% 7 / 19 Podpod 0.0% 0 / 7 totaltotal 22.3% 29 / 130 CC 17 SCAR 23.9
CC
17
Cov
22%
new
20.0
_succ
20.0
_rotate_left
20.0
CRAP 10.9
« DataStructure/RedBlackTree.pm ↑ Summary DataStructure/LinkedList.pm »
1 package DataStructure::BTree::Node;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use feature ':5.24';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub new ($class, $tree, $value, $parent = undef, $left = undef, $right = undef) {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
13 0 my $self = bless {
14 tree => $tree,
15 parent => $parent,
16 left => $left,
17 right => $right,
18 value => $value,
19 }, $class;
20 0 weaken($self->{tree});
21 0 return $self;
22 }
23  
24 0 ▶sub parent ($self) {
Subroutine parent: not called CC=1 SCAR=6.9
Pod undocumented
25 0 return $self->{parent};
26 }
27  
28  
29 0 ▶sub left ($self) {
Subroutine left: not called CC=1 SCAR=6.9
Pod undocumented
30 0 return $self->{left};
31 }
32  
33  
34 0 ▶sub right ($self) {
Subroutine right: not called CC=1 SCAR=6.9
Pod undocumented
35 0 return $self->{right};
36 }
37  
38  
39 0 ▶sub value ($self) {
Subroutine value: not called CC=1 SCAR=6.9
Pod undocumented
40 0 return $self->{value};
41 }
42  
43 0 ▶sub next ($self) {
Subroutine next: not called CC=2 SCAR=17.9
Pod undocumented
44 0 ▶ return unless defined $self->{right};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"right"} 0 0 0
45 0 return $self->{right}->_min_child();
46 }
47  
48 0 ▶sub prev ($self) {
Subroutine prev: not called CC=2 SCAR=17.9
Pod undocumented
49 0 ▶ return unless defined $self->{left};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"left"} 0 0 0
50 0 return $self->{left}->_max_child();
51 }
52  
53 # Returns the child with the smallest value (possibly itself).
54 0 ▶sub _min_child ($self) {
Subroutine _min_child: not called CC=2 SCAR=17.9
55 0 my $current = $self;
56 0 ▶ while (defined $current->{left}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current->{"left"}) 0 0 0
57 0 $current = $current->{left};
58 }
59 0 return $current;
60 }
61  
62 # Returns the child with the biggest value (possibly itself).
63 0 ▶sub _max_child ($self) {
Subroutine _max_child: not called CC=2 SCAR=17.9
64 0 my $current = $self;
65 0 ▶ while (defined $current->{right}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current->{"right"}) 0 0 0
66 0 $current = $current->{right};
67 }
68 0 return $current;
69 }
70  
71 # Returns the node with the smallest value bigger than the value of the current
72 # node (or undef).
73 0 ▶sub _succ ($self) {
Subroutine _succ: not called CC=4 SCAR=30.0
74 0 ▶ return $self->{right}->_min_child() if defined $self->{right};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"right"} 0 0 0
75 0 my $current = $self;
76 0 ▶ while (defined $current->{parent} && $current == $self->{parent}{right}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current->{"parent"} and $current == $self->{"parent"}{"right"}) 0 0 0
Condition0%0/3
defined $current->{"parent"} and $current == $self->{"parent"}{"right"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $current->{"parent"} and $current == $self->{"parent"}{"right"}
defined $current->{"parent"} $current == $self->{"parent"}{"right"}
Truth table0%0/3
A and B
A= defined $current->{"parent"}B= $current == $self->{"parent"}{"right"}
ABresult
0X0
100
111
77 0 $current = $self->{parent};
78 }
79 0 return $current->{parent};
80 }
81  
82 # Requires that defined $self->{right}
83 0 ▶sub _rotate_left ($self) {
Subroutine _rotate_left: not called CC=4 SCAR=30.0
84 0 my $n = $self->{right};
85 0 $self->{right} = $n->{left};
86 0 ▶ return unless defined $n->{left};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n->{"left"} 0 0 0
87 0 $n->{left}{parent} = $self;
88 0 $n->{parent} = $self->{parent};
89 0 ▶ if (defined $self->{parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'parent'}) { } 0 0 0
90 0 ▶ if ($self == $self->{parent}{left}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self == $self->{'parent'}{'left'}) { } 0 0 0
91 0 $self->{parent}{left} = $n;
92 } else {
93 0 $self->{parent}{right} = $n;
94 }
95 } else {
96 0 $self->{tree}{root} = $n;
97 }
98 0 $n->{left} = $self;
99 0 $self->{parent} = $n;
100 0 return;
101 }
102  
103 # Requires that defined $self->{right}
104 0 ▶sub _rotate_right ($self) {
Subroutine _rotate_right: not called CC=4 SCAR=30.0
105 0 my $n = $self->{left};
106 0 $self->{left} = $n->{right};
107 0 ▶ return unless defined $n->{right};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n->{"right"} 0 0 0
108 0 $n->{right}{parent} = $self;
109 0 $n->{parent} = $self->{parent};
110 0 ▶ if (defined $self->{parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'parent'}) { } 0 0 0
111 0 ▶ if ($self == $self->{parent}{left}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self == $self->{'parent'}{'left'}) { } 0 0 0
112 0 $self->{parent}{left} = $n;
113 } else {
114 0 $self->{parent}{right} = $n;
115 }
116 } else {
117 0 $self->{tree}{root} = $n;
118 }
119 0 $n->{right} = $self;
120 0 $self->{parent} = $n;
121 0 return;
122 }
123  
124 1 1;
« DataStructure/RedBlackTree.pm ↑ Summary DataStructure/LinkedList.pm »