line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Sandy::Role::BSearch; |
2
|
|
|
|
|
|
|
# ABSTRACT: Binary search role |
3
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
3910
|
use App::Sandy::Base 'role'; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.25'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub with_bsearch { |
9
|
22513
|
|
|
22513
|
0
|
44976
|
my ($self, $key, $base, $nmemb, $func) = @_; |
10
|
22513
|
|
|
|
|
54808
|
return $self->_bsearch($key, $base, 0, $nmemb - 1, $func); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _bsearch { |
14
|
30303
|
|
|
30303
|
|
52361
|
my ($self, $key1, $base, $start, $end, $func) = @_; |
15
|
|
|
|
|
|
|
|
16
|
30303
|
100
|
|
|
|
59818
|
if ($start > $end) { |
17
|
|
|
|
|
|
|
# Not found! |
18
|
7794
|
|
|
|
|
31305
|
return; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
22509
|
|
|
|
|
46565
|
my $index = int(($start + $end) / 2); |
22
|
22509
|
|
|
|
|
36420
|
my $key2 = $base->[$index]; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# $key1 <=> $key2 |
25
|
22509
|
|
|
|
|
45376
|
my $rc = $func->($key1, $key2); |
26
|
|
|
|
|
|
|
|
27
|
22509
|
100
|
|
|
|
51937
|
if ($rc > 0) { |
|
|
100
|
|
|
|
|
|
28
|
5567
|
|
|
|
|
13088
|
return $self->_bsearch($key1, $base, $index + 1, $end, $func); |
29
|
|
|
|
|
|
|
} elsif ($rc < 0) { |
30
|
2223
|
|
|
|
|
5547
|
return $self->_bsearch($key1, $base, $start, $index - 1, $func); |
31
|
|
|
|
|
|
|
} else { |
32
|
14719
|
|
|
|
|
38476
|
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.25 |
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 |