line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LCS::Similar; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
14422
|
use 5.010001; |
|
2
|
|
|
|
|
7
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
43
|
|
5
|
2
|
|
|
2
|
|
18
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1106
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
#use utf8; |
8
|
|
|
|
|
|
|
#use Data::Dumper; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
7
|
|
|
7
|
1
|
1191
|
my $class = shift; |
12
|
|
|
|
|
|
|
# uncoverable condition false |
13
|
7
|
100
|
66
|
|
|
52
|
bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class; |
|
2
|
100
|
|
|
|
16
|
|
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub LCS { |
17
|
49
|
|
|
49
|
1
|
334584
|
my ($self, $X, $Y, $compare, $threshold) = @_; |
18
|
|
|
|
|
|
|
|
19
|
49
|
|
100
|
18274
|
|
256
|
$compare //= sub { $_[0] eq $_[1] }; |
|
18274
|
|
|
|
|
60196
|
|
20
|
|
|
|
|
|
|
|
21
|
49
|
|
|
|
|
79
|
my $m = scalar @$X; |
22
|
49
|
|
|
|
|
65
|
my $n = scalar @$Y; |
23
|
|
|
|
|
|
|
|
24
|
49
|
|
|
|
|
80
|
my $c = []; |
25
|
49
|
|
|
|
|
71
|
my ($i,$j); |
26
|
49
|
|
|
|
|
140
|
for ($i=0;$i<=$m;$i++) { |
27
|
659
|
|
|
|
|
1343
|
for ($j=0;$j<=$n;$j++) { |
28
|
20446
|
|
|
|
|
44832
|
$c->[$i][$j]=0; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
49
|
|
|
|
|
117
|
for ($i=1;$i<=$m;$i++) { |
32
|
610
|
|
|
|
|
1319
|
for ($j=1;$j<=$n;$j++) { |
33
|
19221
|
|
|
|
|
38928
|
$c->[$i][$j] = $self->max3( |
34
|
|
|
|
|
|
|
&$compare( |
35
|
|
|
|
|
|
|
$X->[$i-1], |
36
|
|
|
|
|
|
|
$Y->[$j-1], |
37
|
|
|
|
|
|
|
$threshold |
38
|
|
|
|
|
|
|
) + $c->[$i-1][$j-1], |
39
|
|
|
|
|
|
|
$c->[$i][$j-1], |
40
|
|
|
|
|
|
|
$c->[$i-1][$j], |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
49
|
|
|
|
|
160
|
my $path = $self->_lcs($X,$Y,$c,$m,$n,[],$compare, $threshold); |
45
|
49
|
|
|
|
|
640
|
return $path; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
0
|
1
|
0
|
sub max { ($_[1] > $_[2]) ? $_[1] : $_[2]; } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub max3 { |
52
|
19221
|
100
|
|
19221
|
1
|
720110
|
($_[1] >= $_[2]) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
53
|
|
|
|
|
|
|
? ($_[1] >= $_[3] |
54
|
|
|
|
|
|
|
? $_[1] : $_[3] |
55
|
|
|
|
|
|
|
) |
56
|
|
|
|
|
|
|
: ($_[2] >= $_[3] |
57
|
|
|
|
|
|
|
? $_[2] : $_[3] |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _lcs { |
62
|
49
|
|
|
49
|
|
108
|
my ($self,$X,$Y,$c,$i,$j,$L,$compare, $threshold) = @_; |
63
|
|
|
|
|
|
|
|
64
|
49
|
|
100
|
|
|
307
|
while ($i > 0 && $j > 0) { |
65
|
635
|
100
|
|
|
|
1335
|
if ( &$compare($X->[$i-1],$Y->[$j-1], $threshold) ) { |
|
|
100
|
|
|
|
|
|
66
|
435
|
|
|
|
|
24873
|
unshift @{$L},[$i-1,$j-1]; |
|
435
|
|
|
|
|
1277
|
|
67
|
435
|
|
|
|
|
571
|
$i--; |
68
|
435
|
|
|
|
|
1818
|
$j--; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
elsif ($c->[$i][$j] == $c->[$i-1][$j]) { |
71
|
154
|
|
|
|
|
8241
|
$i--; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { |
74
|
46
|
|
|
|
|
778
|
$j--; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
49
|
|
|
|
|
111
|
return $L; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |