| 1 | package Algorithm::LCS::XS; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use version; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = qv(2.0.2); | |||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our @EXPORT_OK = qw/&ADLCS &LCSidx/; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | require XSLoader; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | XSLoader::load('Algorithm::LCS::XS', $VERSION); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # code adapted from Algorithm::Diff | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 200003 | ▶ | sub line_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line_map: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 200003 | my $ctx = shift; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 200003 | my %lines; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 200003 | push @{ $lines{$_[$_]} }, $_ for 0..$#_; # values MUST be SvIOK | |||||||||||||||||||||||||||||||||||||||||
| 20 | 200003 | \%lines; | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | sub callback { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
callback: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my ($ctx, @b) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | my $h = $ctx->line_map(@b); | |||||||||||||||||||||||||||||||||||||||||
| 26 | 100001 | ▶ | sub { @_ ? _core_loop($ctx, $_[0], 0, $#{$_[0]}, $h) : @b } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 200002 | ▶ | sub LCS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
LCS: called CC=10 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 200002 | my ($ctx, $a, $b) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 200002 | my ($amin, $amax, $bmin, $bmax) = (0, $#$a, 0, $#$b); | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 200002 | ▶ | while ($amin <= $amax and $bmin <= $bmax and $a->[$amin] eq $b->[$bmin]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$amin <= $amax and $bmin <= $bmax and $a->[$amin] eq $b->[$bmin]
$amin <= $amax and $bmin <= $bmax
MC/DC33%1/3
$amin <= $amax and $bmin <= $bmax and $a->[$amin] eq $b->[$bmin]
$amin <= $amax
$bmin <= $bmax
$a->[$amin] eq $b->[$bmin]
Truth table50%2/4
A and B and C
A= $amin <= $amaxB= $bmin <= $bmaxC= $a->[$amin] eq $b->[$bmin]
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 200002 | $amin++; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 200002 | $bmin++; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 200002 | ▶ | while ($amin <= $amax and $bmin <= $bmax and $a->[$amax] eq $b->[$bmax]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$amin <= $amax and $bmin <= $bmax and $a->[$amax] eq $b->[$bmax]
$amin <= $amax and $bmin <= $bmax
MC/DC33%1/3
$amin <= $amax and $bmin <= $bmax and $a->[$amax] eq $b->[$bmax]
$amin <= $amax
$bmin <= $bmax
$a->[$amax] eq $b->[$bmax]
Truth table50%2/4
A and B and C
A= $amin <= $amaxB= $bmin <= $bmaxC= $a->[$amax] eq $b->[$bmax]
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 400004 | $amax--; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 400004 | $bmax--; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 200002 | my $h = $ctx->line_map(@$b[$bmin..$bmax]); # line numbers are off by $bmin | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 200002 | ▶ | return $amin + _core_loop($ctx, $a, $amin, $amax, $h) + ($#$a - $amax) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | unless wantarray; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 200002 | my @lcs = _core_loop($ctx,$a,$amin,$amax,$h); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 200002 | ▶ | if ($bmin > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 200002 | $_->[1] += $bmin for @lcs; # correct line numbers | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 200002 | map([$_ => $_], 0 .. ($amin-1)), | |||||||||||||||||||||||||||||||||||||||||
| 53 | @lcs, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | map([$_ => ++$bmax], ($amax+1) .. $#$a); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | my $alg; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 100001 | ▶ | sub LCSidx { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
LCSidx: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 100001 | ▶ | $alg //= Algorithm::LCS::XS->new; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$alg //= "Algorithm::LCS::XS"->new
MC/DC0%0/2
$alg //= "Algorithm::LCS::XS"->new
$alg
"Algorithm::LCS::XS"->new
Truth table66%2/3
A //= B
A= $algB= "Algorithm::LCS::XS"->new
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 100001 | my (@l, @r); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 100001 | for my $arr ($alg->LCS(@_)) { | |||||||||||||||||||||||||||||||||||||||||
| 64 | 4000040 | push @l, $$arr[0]; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 4000040 | push @r, $$arr[1]; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 100001 | return \@l, \@r; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 100000 | ▶ | sub ADLCS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ADLCS: called CC=4 SCAR=14.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 100000 | ▶ | $alg //= Algorithm::LCS::XS->new; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$alg //= "Algorithm::LCS::XS"->new
MC/DC0%0/2
$alg //= "Algorithm::LCS::XS"->new
$alg
"Algorithm::LCS::XS"->new
Truth table33%1/3
A //= B
A= $algB= "Algorithm::LCS::XS"->new
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 100000 | my @rv; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 100000 | for my $arr ($alg->LCS(@_)) { | |||||||||||||||||||||||||||||||||||||||||
| 74 | 4000000 | $rv[$$arr[0]] = $_[0][$$arr[0]]; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 100000 | ▶ | return wantarray ? @rv : \@rv; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||||||||||||||||