line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::LCSS; |
2
|
1
|
|
|
1
|
|
1299
|
use base ( 'Exporter' ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
106
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
7755
|
use utf8; |
|
1
|
|
|
|
|
20
|
|
|
1
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
BEGIN |
6
|
|
|
|
|
|
|
{ |
7
|
1
|
|
|
1
|
|
85
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
62
|
|
8
|
1
|
|
|
1
|
|
5
|
use vars qw( $VERSION @EXPORT_OK); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
89
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
2
|
$VERSION = "0.12"; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
459
|
@EXPORT_OK = qw( lcss ); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub lcss |
17
|
|
|
|
|
|
|
{ |
18
|
6
|
|
|
6
|
0
|
4203
|
my ($a, $b) = @_; |
19
|
6
|
|
|
|
|
11
|
my (@x, @y); |
20
|
6
|
|
|
|
|
9
|
my ($maxLength, $maxXi, $maxXk, $switch) = (0,0,0,0); |
21
|
6
|
|
|
|
|
7
|
my $returnString; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
6
|
|
|
|
|
10
|
my $m = length ( $a ); |
25
|
6
|
|
|
|
|
7
|
my $n = length ( $b ); |
26
|
|
|
|
|
|
|
|
27
|
6
|
100
|
|
|
|
16
|
if ( $m > $n ) { |
28
|
2
|
|
|
|
|
5
|
( $m, $n ) = ( $n, $m ); |
29
|
2
|
|
|
|
|
5
|
( $a, $b ) = ( $b, $a ); |
30
|
2
|
|
|
|
|
6
|
$switch = 1; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
6
|
|
|
|
|
70
|
@x = split ( //, $a ); |
34
|
6
|
|
|
|
|
81
|
@y = split ( //, $b ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# declare varialbes outside of loops for a hair more speed. |
38
|
|
|
|
|
|
|
# |
39
|
6
|
|
|
|
|
19
|
my ( $i, $ii, $j, $k, $length, $xi, $xj ); |
40
|
|
|
|
|
|
|
|
41
|
6
|
|
|
|
|
16
|
for ( $k = 0; $k < $n; $k++ ) { |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
# abort if the remainder of the string to check is |
44
|
|
|
|
|
|
|
# less than the common substring length already found |
45
|
|
|
|
|
|
|
# |
46
|
127
|
100
|
|
|
|
246
|
last if ( $maxLength >= ( $m - $k ) ); |
47
|
|
|
|
|
|
|
|
48
|
121
|
|
|
|
|
157
|
( $xi, $length ) = ( 0, 0 ); |
49
|
|
|
|
|
|
|
|
50
|
121
|
|
|
|
|
262
|
for ( $i = 0; $i < $m; $i++ ) { |
51
|
5084
|
|
|
|
|
5097
|
$j = $k; |
52
|
5084
|
|
|
|
|
5092
|
$length = 0; |
53
|
5084
|
|
|
|
|
10370
|
for ( $ii = 0; $ii < ($m-$i); $ii++ ) { |
54
|
67507
|
100
|
|
|
|
276886
|
if ( $x[$i+$ii] eq $y[$j] ) { |
|
|
100
|
|
|
|
|
|
55
|
9668
|
100
|
|
|
|
16306
|
$xi = $i+$ii unless ( $length ); |
56
|
9668
|
100
|
|
|
|
16227
|
$xj = $j unless ( $length ); |
57
|
9668
|
|
|
|
|
10468
|
$length++; |
58
|
9668
|
|
|
|
|
23808
|
$j++; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif ( $length ) { |
61
|
2716
|
100
|
|
|
|
6326
|
if ( $length > $maxLength ) { |
62
|
17
|
|
|
|
|
16
|
$maxLength = $length; |
63
|
17
|
|
|
|
|
14
|
$maxXi = $xi; |
64
|
17
|
|
|
|
|
16
|
$maxXk = $xj; |
65
|
|
|
|
|
|
|
} |
66
|
2716
|
|
|
|
|
5615
|
last; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
6
|
100
|
|
|
|
13
|
if ( $maxLength > 1 ) { |
73
|
5
|
|
|
|
|
14
|
for ($i = $maxXi; $i < $maxXi+$maxLength; $i++ ) { |
74
|
70
|
|
|
|
|
137
|
$returnString .= $x[$i]; |
75
|
|
|
|
|
|
|
} |
76
|
5
|
100
|
|
|
|
22
|
($maxXi, $maxXk) = ($maxXk, $maxXi) if ( $switch ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
6
|
50
|
|
|
|
73
|
( wantarray ) ? ( $returnString, $maxXi, $maxXk ) : $returnString; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
######################################################### |
85
|
|
|
|
|
|
|
# Do not change this, Do not put anything below this. |
86
|
|
|
|
|
|
|
# File must return "true" value at termination |
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
########################################################## |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |