line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DataStructure::BTree::Node; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
8
|
|
6
|
1
|
|
|
1
|
|
22
|
use feature ':5.24'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
82
|
|
7
|
1
|
|
|
1
|
|
6
|
use feature 'signatures'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
8
|
1
|
|
|
1
|
|
5
|
no warnings 'experimental::signatures'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw(weaken); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1122
|
|
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
0
|
0
|
|
sub new ($class, $tree, $value, $parent = undef, $left = undef, $right = undef) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
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
|
|
|
0
|
0
|
|
sub parent ($self) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
return $self->{parent}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
0
|
0
|
|
sub left ($self) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return $self->{left}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
0
|
|
sub right ($self) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return $self->{right}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
0
|
0
|
|
sub value ($self) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $self->{value}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
0
|
0
|
|
sub next ($self) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
return unless defined $self->{right}; |
45
|
0
|
|
|
|
|
|
return $self->{right}->_min_child(); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
0
|
0
|
|
sub prev ($self) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
return unless defined $self->{left}; |
50
|
0
|
|
|
|
|
|
return $self->{left}->_max_child(); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Returns the child with the smallest value (possibly itself). |
54
|
0
|
|
|
0
|
|
|
sub _min_child ($self) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $current = $self; |
56
|
0
|
|
|
|
|
|
while (defined $current->{left}) { |
57
|
0
|
|
|
|
|
|
$current = $current->{left}; |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
return $current; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Returns the child with the biggest value (possibly itself). |
63
|
0
|
|
|
0
|
|
|
sub _max_child ($self) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $current = $self; |
65
|
0
|
|
|
|
|
|
while (defined $current->{right}) { |
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
|
|
|
0
|
|
|
sub _succ ($self) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
return $self->{right}->_min_child() if defined $self->{right}; |
75
|
0
|
|
|
|
|
|
my $current = $self; |
76
|
0
|
|
0
|
|
|
|
while (defined $current->{parent} && $current == $self->{parent}{right}) { |
77
|
0
|
|
|
|
|
|
$current = $self->{parent}; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
return $current->{parent}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Requires that defined $self->{right} |
83
|
0
|
|
|
0
|
|
|
sub _rotate_left ($self) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $n = $self->{right}; |
85
|
0
|
|
|
|
|
|
$self->{right} = $n->{left}; |
86
|
0
|
0
|
|
|
|
|
return unless defined $n->{left}; |
87
|
0
|
|
|
|
|
|
$n->{left}{parent} = $self; |
88
|
0
|
|
|
|
|
|
$n->{parent} = $self->{parent}; |
89
|
0
|
0
|
|
|
|
|
if (defined $self->{parent}) { |
90
|
0
|
0
|
|
|
|
|
if ($self == $self->{parent}{left}) { |
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
|
|
|
0
|
|
|
sub _rotate_right ($self) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $n = $self->{left}; |
106
|
0
|
|
|
|
|
|
$self->{left} = $n->{right}; |
107
|
0
|
0
|
|
|
|
|
return unless defined $n->{right}; |
108
|
0
|
|
|
|
|
|
$n->{right}{parent} = $self; |
109
|
0
|
|
|
|
|
|
$n->{parent} = $self->{parent}; |
110
|
0
|
0
|
|
|
|
|
if (defined $self->{parent}) { |
111
|
0
|
0
|
|
|
|
|
if ($self == $self->{parent}{left}) { |
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; |