blib/lib/Algorithm/LCS/XS.pm

filter: Statementstmt 100% 55 / 55 Branchbran 66.6% 8 / 12 Conditioncond 50.0% 9 / 18 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 11 / 11 Podpod 60.0% 3 / 5 totaltotal 79.2% 88 / 111 CC 17 SCAR 17.4
CC
17
Cov
85%
LCS
11.3
ADLCS
4.4
LCSidx
3.0
CRAP 5.7
↑ Summary XS.xs »
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
BranchTrueFalseTotal
@_ ? : 100001 0 100001
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
BranchTrueFalseTotal
if ($amin <= $amax and $bmin <= $bmax and $a->[$amin] eq $b->[$bmin]) 200002 200002 400004
Condition50%3/6
$amin <= $amax and $bmin <= $bmax and $a->[$amin] eq $b->[$bmin]
!ll&&!rl&&r
0200002200002
$amin <= $amax and $bmin <= $bmax
!ll&&!rl&&r
00400004
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]
ABCresult
0XX0
10X0
1100
1111
34 200002 $amin++;
35 200002 $bmin++;
36 }
37 200002 ▶ while ($amin <= $amax and $bmin <= $bmax and $a->[$amax] eq $b->[$bmax]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($amin <= $amax and $bmin <= $bmax and $a->[$amax] eq $b->[$bmax]) 400004 200002 600006
Condition50%3/6
$amin <= $amax and $bmin <= $bmax and $a->[$amax] eq $b->[$bmax]
!ll&&!rl&&r
0200002400004
$amin <= $amax and $bmin <= $bmax
!ll&&!rl&&r
00600006
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]
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
unless wantarray 0 200002 200002
45 unless wantarray;
46  
47 200002 my @lcs = _core_loop($ctx,$a,$amin,$amax,$h);
48 200002 ▶ if ($bmin > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bmin > 0) 200002 0 200002
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
l!l&&r!l&&!r
10000010
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
ABresult
1X1
011
000
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
l!l&&r!l&&!r
10000000
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
wantarray ? : 0 100000 100000
77 }
78  
79 1 1;
80  
81 __END__
↑ Summary XS.xs »