| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Sandy::Role::BSearch; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Binary search role |
|
3
|
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
4523
|
use App::Sandy::Base 'role'; |
|
|
6
|
|
|
|
|
14
|
|
|
|
6
|
|
|
|
|
35
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.24'; # VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub with_bsearch { |
|
9
|
22377
|
|
|
22377
|
0
|
49953
|
my ($self, $key, $base, $nmemb, $func) = @_; |
|
10
|
22377
|
|
|
|
|
54542
|
return $self->_bsearch($key, $base, 0, $nmemb - 1, $func); |
|
11
|
|
|
|
|
|
|
} |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _bsearch { |
|
14
|
30243
|
|
|
30243
|
|
56104
|
my ($self, $key1, $base, $start, $end, $func) = @_; |
|
15
|
|
|
|
|
|
|
|
|
16
|
30243
|
100
|
|
|
|
60876
|
if ($start > $end) { |
|
17
|
|
|
|
|
|
|
# Not found! |
|
18
|
7730
|
|
|
|
|
34692
|
return; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
22513
|
|
|
|
|
48440
|
my $index = int(($start + $end) / 2); |
|
22
|
22513
|
|
|
|
|
33458
|
my $key2 = $base->[$index]; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# $key1 <=> $key2 |
|
25
|
22513
|
|
|
|
|
46850
|
my $rc = $func->($key1, $key2); |
|
26
|
|
|
|
|
|
|
|
|
27
|
22513
|
100
|
|
|
|
53402
|
if ($rc > 0) { |
|
|
|
100
|
|
|
|
|
|
|
28
|
5612
|
|
|
|
|
13108
|
return $self->_bsearch($key1, $base, $index + 1, $end, $func); |
|
29
|
|
|
|
|
|
|
} elsif ($rc < 0) { |
|
30
|
2254
|
|
|
|
|
6732
|
return $self->_bsearch($key1, $base, $start, $index - 1, $func); |
|
31
|
|
|
|
|
|
|
} else { |
|
32
|
14647
|
|
|
|
|
41437
|
return $index; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__END__ |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=encoding UTF-8 |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
App::Sandy::Role::BSearch - Binary search role |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 VERSION |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
version 0.24 |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 AUTHORS |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=over 4 |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item * |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Thiago L. A. Miller <tmiller@mochsl.org.br> |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item * |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
J. Leonel Buzzo <lbuzzo@mochsl.org.br> |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item * |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Felipe R. C. dos Santos <fsantos@mochsl.org.br> |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item * |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Helena B. Conceição <hconceicao@mochsl.org.br> |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item * |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Rodrigo Barreiro <rbarreiro@mochsl.org.br> |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item * |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Gabriela Guardia <gguardia@mochsl.org.br> |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item * |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Fernanda Orpinelli <forpinelli@mochsl.org.br> |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item * |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Rafael Mercuri <rmercuri@mochsl.org.br> |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item * |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Rodrigo Barreiro <rbarreiro@mochsl.org.br> |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item * |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Pedro A. F. Galante <pgalante@mochsl.org.br> |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=back |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This software is Copyright (c) 2023 by Teaching and Research Institute from Sírio-Libanês Hospital. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This is free software, licensed under: |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |