line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Heap::Simple::Wrapper; |
2
|
|
|
|
|
|
|
$VERSION = "0.04"; |
3
|
3
|
|
|
3
|
|
321
|
use strict; |
|
3
|
|
|
|
|
96
|
|
|
3
|
|
|
|
|
1912
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub _ELEMENTS_PREPARE { |
6
|
359
|
|
|
359
|
|
3788
|
return ""; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub _QUICK_KEY { |
10
|
170
|
|
|
170
|
|
645
|
return shift->_KEY(@_); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _KEY { |
14
|
2914
|
|
|
2914
|
|
78414
|
return $_[1] . "->[0]"; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _VALUE { |
18
|
604
|
|
|
604
|
|
27078
|
return $_[1] . "->[1]"; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _WRAPPER { |
22
|
421
|
|
|
421
|
|
18264
|
return "[$_[1], $_[2]]"; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub insert { |
26
|
115
|
|
|
115
|
0
|
33955
|
my $heap = shift; |
27
|
115
|
50
|
|
|
|
857
|
Carp::croak "Wrapped class with noop key" if $heap->_KEY("") eq ""; |
28
|
115
|
|
|
|
|
1219
|
$heap->_make('sub insert { |
29
|
|
|
|
|
|
|
my $heap = shift; |
30
|
|
|
|
|
|
|
_REAL_PREPARE() |
31
|
|
|
|
|
|
|
_CANT_DIE( |
32
|
|
|
|
|
|
|
_MAX_COUNT(my $available = _THE_MAX_COUNT()-$#$heap;) |
33
|
|
|
|
|
|
|
if (@_ > 1 _MAX_COUNT(&& $available > 1)) { |
34
|
|
|
|
|
|
|
my $first = @$heap; |
35
|
|
|
|
|
|
|
my $i = push(@$heap, map _WRAPPER(_REAL_KEY($_), $_), _MAX_COUNT(splice(@_, 0, $available), @_))-1; |
36
|
|
|
|
|
|
|
my @todo = reverse $first/2..$#$heap/2; |
37
|
|
|
|
|
|
|
while (my $j = shift @todo) { |
38
|
|
|
|
|
|
|
my $value = $heap->[$j]; |
39
|
|
|
|
|
|
|
my $key = _KEY($value); |
40
|
|
|
|
|
|
|
my $l = $j*2; |
41
|
|
|
|
|
|
|
while ($l < $i) { |
42
|
|
|
|
|
|
|
if (_SMALLER(_KEY($heap->[$l]), $key)) { |
43
|
|
|
|
|
|
|
$l++ if _SMALLER(_KEY($heap->[$l+1]), _KEY($heap->[$l])); |
44
|
|
|
|
|
|
|
} elsif (!(_SMALLER(_KEY($heap->[++$l]), $key))) { |
45
|
|
|
|
|
|
|
$l--; |
46
|
|
|
|
|
|
|
last; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
$heap->[$l >> 1] = $heap->[$l]; |
49
|
|
|
|
|
|
|
$l *= 2; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
if ($l == $i && _SMALLER(_KEY($heap->[$l]), $key)) { |
52
|
|
|
|
|
|
|
$heap->[$l >> 1] = $heap->[$l]; |
53
|
|
|
|
|
|
|
} else { |
54
|
|
|
|
|
|
|
$l >>= 1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
if ($j != $l) { |
57
|
|
|
|
|
|
|
$heap->[$l] = $value; |
58
|
|
|
|
|
|
|
$l >>= 1; |
59
|
|
|
|
|
|
|
push(@todo, $l) if !@todo || $l < $todo[0]; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
return _MAX_COUNT(unless @_); |
63
|
|
|
|
|
|
|
}) |
64
|
|
|
|
|
|
|
for my $value (@_) { |
65
|
|
|
|
|
|
|
my $key = _REAL_KEY($value); |
66
|
|
|
|
|
|
|
my $i = @$heap; |
67
|
|
|
|
|
|
|
_MAX_COUNT(if ($i > _THE_MAX_COUNT()) { |
68
|
|
|
|
|
|
|
next unless _SMALLER(_KEY($heap->[1]), $key); |
69
|
|
|
|
|
|
|
$i--; |
70
|
|
|
|
|
|
|
my $l = 2; |
71
|
|
|
|
|
|
|
_CAN_DIE(my $min = $heap->[1]; eval {) |
72
|
|
|
|
|
|
|
while ($l < $i) { |
73
|
|
|
|
|
|
|
if (_SMALLER(_KEY($heap->[$l]), $key)) { |
74
|
|
|
|
|
|
|
$l++ if _SMALLER(_KEY($heap->[$l+1]), _KEY($heap->[$l])); |
75
|
|
|
|
|
|
|
} elsif (!(_SMALLER(_KEY($heap->[++$l]), $key))) { |
76
|
|
|
|
|
|
|
$l--; |
77
|
|
|
|
|
|
|
last; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
$heap->[$l >> 1] = $heap->[$l]; |
80
|
|
|
|
|
|
|
$l *= 2; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
if ($l == $i && _SMALLER(_KEY($heap->[$l]), $key)) { |
83
|
|
|
|
|
|
|
$heap->[$l >> 1] = $heap->[$l]; |
84
|
|
|
|
|
|
|
$l *= 2; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
_CAN_DIE( 1 |
87
|
|
|
|
|
|
|
} || $heap->_e_recover($l, $min);) |
88
|
|
|
|
|
|
|
$heap->[$l >> 1] = _WRAPPER($key, $value); |
89
|
|
|
|
|
|
|
next;}) |
90
|
|
|
|
|
|
|
_CAN_DIE(eval {) |
91
|
|
|
|
|
|
|
$i = $i >> 1 while |
92
|
|
|
|
|
|
|
$i > 1 && _SMALLER($key, _KEY(($heap->[$i] = $heap->[$i >> 1]))); |
93
|
|
|
|
|
|
|
_CAN_DIE(1} || $heap->_i_recover($i);) |
94
|
|
|
|
|
|
|
$heap->[$i] = _WRAPPER($key, $value); |
95
|
|
|
|
|
|
|
}}'); |
96
|
115
|
|
|
|
|
80067
|
$heap->insert(@_); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub key_insert { |
100
|
95
|
|
|
95
|
0
|
1160251
|
my $heap = shift; |
101
|
95
|
|
|
|
|
829
|
$heap->_make('sub key_insert { |
102
|
|
|
|
|
|
|
my $heap = shift; |
103
|
|
|
|
|
|
|
_PREPARE() |
104
|
|
|
|
|
|
|
while (@_) { |
105
|
|
|
|
|
|
|
my $key = shift; |
106
|
|
|
|
|
|
|
my $i = @$heap; |
107
|
|
|
|
|
|
|
_MAX_COUNT(if ($i > _THE_MAX_COUNT()) { |
108
|
|
|
|
|
|
|
shift _COMMA() next unless _SMALLER(_KEY($heap->[1]), $key); |
109
|
|
|
|
|
|
|
$i--; |
110
|
|
|
|
|
|
|
my $l = 2; |
111
|
|
|
|
|
|
|
_CAN_DIE(my $min = $heap->[1]; eval {) |
112
|
|
|
|
|
|
|
while ($l < $i) { |
113
|
|
|
|
|
|
|
if (_SMALLER(_KEY($heap->[$l]), $key)) { |
114
|
|
|
|
|
|
|
$l++ if _SMALLER(_KEY($heap->[$l+1]), _KEY($heap->[$l])); |
115
|
|
|
|
|
|
|
} elsif (!(_SMALLER(_KEY($heap->[++$l]), $key))) { |
116
|
|
|
|
|
|
|
$l--; |
117
|
|
|
|
|
|
|
last; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
$heap->[$l >> 1] = $heap->[$l]; |
120
|
|
|
|
|
|
|
$l *= 2; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
if ($l == $i && _SMALLER(_KEY($heap->[$l]), $key)) { |
123
|
|
|
|
|
|
|
$heap->[$l >> 1] = $heap->[$l]; |
124
|
|
|
|
|
|
|
$l *= 2; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
_CAN_DIE( 1 |
127
|
|
|
|
|
|
|
} || $heap->_e_recover($l, $min);) |
128
|
|
|
|
|
|
|
$heap->[$l >> 1] = _WRAPPER($key, shift); |
129
|
|
|
|
|
|
|
next;}) |
130
|
|
|
|
|
|
|
_CAN_DIE(eval {) |
131
|
|
|
|
|
|
|
$i = $i >> 1 while |
132
|
|
|
|
|
|
|
$i > 1 && _SMALLER($key, _KEY(($heap->[$i] = $heap->[$i >> 1]))); |
133
|
|
|
|
|
|
|
_CAN_DIE(1} || $heap->_i_recover($i);) |
134
|
|
|
|
|
|
|
$heap->[$i] = _WRAPPER($key, shift); |
135
|
|
|
|
|
|
|
}}'); |
136
|
95
|
|
|
|
|
77668
|
$heap->key_insert(@_); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _key_insert { |
140
|
94
|
|
|
94
|
|
1385062
|
my $heap = shift; |
141
|
94
|
|
|
|
|
484
|
$heap->_make('sub _key_insert { |
142
|
|
|
|
|
|
|
my $heap = shift; |
143
|
|
|
|
|
|
|
_PREPARE() |
144
|
|
|
|
|
|
|
for my $pair (@_) { |
145
|
|
|
|
|
|
|
my $key = $pair->[0]; |
146
|
|
|
|
|
|
|
my $i = @$heap; |
147
|
|
|
|
|
|
|
_MAX_COUNT(if ($i > _THE_MAX_COUNT()) { |
148
|
|
|
|
|
|
|
next unless _SMALLER(_KEY($heap->[1]), $key); |
149
|
|
|
|
|
|
|
$i--; |
150
|
|
|
|
|
|
|
my $l = 2; |
151
|
|
|
|
|
|
|
_CAN_DIE(my $min = $heap->[1]; eval {) |
152
|
|
|
|
|
|
|
while ($l < $i) { |
153
|
|
|
|
|
|
|
if (_SMALLER(_KEY($heap->[$l]), $key)) { |
154
|
|
|
|
|
|
|
$l++ if _SMALLER(_KEY($heap->[$l+1]), _KEY($heap->[$l])); |
155
|
|
|
|
|
|
|
} elsif (!(_SMALLER(_KEY($heap->[++$l]), $key))) { |
156
|
|
|
|
|
|
|
$l--; |
157
|
|
|
|
|
|
|
last; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
$heap->[$l >> 1] = $heap->[$l]; |
160
|
|
|
|
|
|
|
$l *= 2; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
if ($l == $i && _SMALLER(_KEY($heap->[$l]), $key)) { |
163
|
|
|
|
|
|
|
$heap->[$l >> 1] = $heap->[$l]; |
164
|
|
|
|
|
|
|
$l *= 2; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
_CAN_DIE( 1 |
167
|
|
|
|
|
|
|
} || $heap->_e_recover($l, $min);) |
168
|
|
|
|
|
|
|
$heap->[$l >> 1] = $pair; |
169
|
|
|
|
|
|
|
next;}) |
170
|
|
|
|
|
|
|
_CAN_DIE(eval {) |
171
|
|
|
|
|
|
|
$i = $i >> 1 while |
172
|
|
|
|
|
|
|
$i > 1 && _SMALLER($key, _KEY(($heap->[$i] = $heap->[$i >> 1]))); |
173
|
|
|
|
|
|
|
_CAN_DIE(1} || $heap->_i_recover($i);) |
174
|
|
|
|
|
|
|
$heap->[$i] = $pair; |
175
|
|
|
|
|
|
|
}}'); |
176
|
94
|
|
|
|
|
63360
|
$heap->_key_insert(@_); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub _key_absorb { |
180
|
153
|
|
|
153
|
|
1224
|
my ($from, $to) = @_; |
181
|
153
|
50
|
|
|
|
673
|
Carp::croak "Self absorption" if $from == $to; |
182
|
153
|
100
|
100
|
|
|
952
|
if (@$from > 2 && !$to->can_die) { |
183
|
91
|
|
|
|
|
800
|
$to->_key_insert(@$from[1..$#$from]); |
184
|
61
|
|
|
|
|
3950
|
$#$from = 0; |
185
|
61
|
|
|
|
|
269
|
return; |
186
|
|
|
|
|
|
|
} |
187
|
62
|
|
|
|
|
202
|
while (@$from > 1) { |
188
|
64
|
|
|
|
|
747
|
$to->_key_insert($from->[-1]); |
189
|
2
|
|
|
|
|
40
|
pop @$from; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub wrapped { |
194
|
93
|
|
|
93
|
0
|
73956
|
return 1; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |