| 1 | package Algorithm::Diff; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Skip to first "=head" line for documentation. | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use integer; # see below in _replaceNextLargerWith() for mod to make | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # if you don't use this | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use vars qw( $VERSION @EXPORT_OK ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | $VERSION = '1.201'; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | *import = \&Exporter::import; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | prepare LCS LCSidx LCS_length | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | diff sdiff compact_diff | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | traverse_sequences traverse_balanced | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # McIlroy-Hunt diff algorithm | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Adapted from the Smalltalk code of Mario I. Wolczko, <mario@wolczko.com> | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # by Ned Konz, perl@bike-nomad.com | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # Updates by Tye McQueen, http://perlmonks.org/?node=tye | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # Create a hash that maps each element of $aCollection to the set of | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # positions it occupies in $aCollection, restricted to the elements | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # within the range of indexes specified by $start and $end. | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # The fourth parameter is a subroutine reference that will be called to | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # generate a string to use as a key. | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # Additional parameters, if any, will be passed to this subroutine. | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # my $hashRef = _withPositionsOfInInterval( \@array, $start, $end, $keyGen ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | sub _withPositionsOfInInterval | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 36 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_withPositionsOfInInterval: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 36 | my $aCollection = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 36 | my $start = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 36 | my $end = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 36 | my $keyGen = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 36 | my %d; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | my $index; | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 36 | ▶ | for ( $index = $start ; $index <= $end ; $index++ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 154 | my $element = $aCollection->[$index]; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 154 | ▶ | my $key = $keyGen ? &$keyGen( $element, @_ ) : $element; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 154 | ▶ | if ( exists( $d{$key} ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | unshift ( @{ $d{$key} }, $index ); | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 153 | $d{$key} = [$index]; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 36 | ▶ | return wantarray ? %d : \%d; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # Find the place at which aValue would normally be inserted into the | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # array. If that place is already occupied by aValue, do nothing, and | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # return undef. If the place does not exist (i.e., it is off the end of | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # the array), add it to the end, otherwise replace the element at that | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # point with aValue. It is assumed that the array's values are numeric. | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # This is where the bulk (75%) of the time is spent in this module, so | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # try to make it fast! | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | sub _replaceNextLargerWith | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 55 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_replaceNextLargerWith: called CC=7 SCAR=30.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 55 | my ( $array, $aValue, $high ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 55 | ▶ | $high ||= $#$array; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$high ||= $array->$#*
MC/DC50%1/2
$high ||= $array->$#*
$high
$array->$#*
Truth table66%2/3
A ||= B
A= $highB= $array->$#*
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # off the end? | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 55 | ▶ | if ( $high == -1 || $aValue > $array->[-1] ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$high == -1 or $aValue > $array->[-1]
MC/DC0%0/2
$high == -1 or $aValue > $array->[-1]
$high == -1
$aValue > $array->[-1]
Truth table66%2/3
A or B
A= $high == -1B= $aValue > $array->[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 55 | push ( @$array, $aValue ); | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 55 | return $high + 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # binary search for insertion point... | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $low = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $index; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | my $found; | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | while ( $low <= $high ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $index = ( $high + $low ) / 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # $index = int(( $high + $low ) / 2); # without 'use integer' | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $found = $array->[$index]; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ( $aValue == $found ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif ( $aValue > $found ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $low = $index + 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $high = $index - 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # now insertion point is in $low. | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $array->[$low] = $aValue; # overwrite next larger | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return $low; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # This method computes the longest common subsequence in $a and $b. | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # Result is array or ref, whose contents is such that | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # $a->[ $i ] == $b->[ $result[ $i ] ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # foreach $i in ( 0 .. $#result ) if $result[ $i ] is defined. | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # An additional argument may be passed; this is a hash or key generating | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # function that should return a string that uniquely identifies the given | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # element. It should be the case that if the key is the same, the elements | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # will compare the same. If this parameter is undef or missing, the key | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # will be the element as a string. | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # By default, comparisons will use "eq" and elements will be turned into keys | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # using the default stringizing operator '""'. | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Additional parameters, if any, will be passed to the key generation | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # routine. | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | sub _longestCommonSubsequence | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 36 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_longestCommonSubsequence: called CC=28 SCAR=37.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 36 | my $a = shift; # array ref or hash ref | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 36 | my $b = shift; # array ref or hash ref | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 36 | my $counting = shift; # scalar | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 36 | my $keyGen = shift; # code ref | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | 36 | my $compare; # code ref | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 36 | ▶ | if ( ref($a) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | { # prepared hash must be in $b | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $tmp = $b; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $b = $a; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $a = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # Check for bogus (non-ref) argument values | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 36 | ▶ | if ( !ref($a) || !ref($b) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $a and ref $b
MC/DC0%0/2
ref $a and ref $b
ref $a
ref $b
Truth table33%1/3
A and B
A= ref $aB= ref $b
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my @callerInfo = caller(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | die 'error: must pass array or hash references to ' . $callerInfo[3]; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # set up code refs | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # Note that these are optimized. | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 36 | ▶ | if ( $keyGen ) # optimize for strings | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | $compare = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $a = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my $b = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | &$keyGen( $a, @_ ) eq &$keyGen( $b, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 36 | my ( $aStart, $aFinish, $matchVector ) = ( 0, $#$a, [] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 36 | my ( $prunedCount, $bMatches ) = ( 0, {} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 36 | ▶ | if ( ref($b) eq 'HASH' ) # was $bMatches prepared for us? | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $bMatches = $b; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 36 | my ( $bStart, $bFinish ) = ( 0, $#$b ); | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # First we prune off any common elements at the beginning | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 36 | ▶ | while ( $aStart <= $aFinish | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
$aStart <= $aFinish and $bStart <= $bFinish and $keyGen ? &$compare($a->[$aStart], $b->[$bStart], @_) : $a->[$aStart] eq $b->[$bStart]
$aStart <= $aFinish and $bStart <= $bFinish
MC/DC100%3/3
$aStart <= $aFinish and $bStart <= $bFinish and $keyGen ? &$compare($a->[$aStart], $b->[$bStart], @_) : $a->[$aStart] eq $b->[$bStart]
$aStart <= $aFinish
$bStart <= $bFinish
$keyGen ? &$compare($a->[$aStart], $b->[$bStart], @_) : $a->[$aStart] eq $b->[$bStart]
Truth table100%4/4
A and B and C
A= $aStart <= $aFinishB= $bStart <= $bFinishC= $keyGen ? &$compare($a->[$aStart], $b->[$bStart], @_) : $a->[$aStart] eq $b->[$bStart]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | and $bStart <= $bFinish | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | and ( $keyGen ? &$compare( $a->[$aStart], $b->[$bStart], @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | : ( $a->[$aStart] eq $b->[$bStart] ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 13 | $matchVector->[ $aStart++ ] = $bStart++; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | 13 | $prunedCount++; | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # now the end | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 36 | ▶ | while ( $aStart <= $aFinish | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
$aStart <= $aFinish and $bStart <= $bFinish and $keyGen ? &$compare($a->[$aFinish], $b->[$bFinish], @_) : $a->[$aFinish] eq $b->[$bFinish]
$aStart <= $aFinish and $bStart <= $bFinish
MC/DC100%3/3
$aStart <= $aFinish and $bStart <= $bFinish and $keyGen ? &$compare($a->[$aFinish], $b->[$bFinish], @_) : $a->[$aFinish] eq $b->[$bFinish]
$aStart <= $aFinish
$bStart <= $bFinish
$keyGen ? &$compare($a->[$aFinish], $b->[$bFinish], @_) : $a->[$aFinish] eq $b->[$bFinish]
Truth table100%4/4
A and B and C
A= $aStart <= $aFinishB= $bStart <= $bFinishC= $keyGen ? &$compare($a->[$aFinish], $b->[$bFinish], @_) : $a->[$aFinish] eq $b->[$bFinish]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | and $bStart <= $bFinish | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | and ( $keyGen ? &$compare( $a->[$aFinish], $b->[$bFinish], @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | : ( $a->[$aFinish] eq $b->[$bFinish] ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 16 | $matchVector->[ $aFinish-- ] = $bFinish--; | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 16 | $prunedCount++; | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # Now compute the equivalence classes of positions of elements | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | $bMatches = | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 36 | _withPositionsOfInInterval( $b, $bStart, $bFinish, $keyGen, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 36 | my $thresh = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | 36 | my $links = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 36 | my ( $i, $ai, $j, $k ); | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 36 | ▶ | for ( $i = $aStart ; $i <= $aFinish ; $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 129 | ▶ | $ai = $keyGen ? &$keyGen( $a->[$i], @_ ) : $a->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 129 | ▶ | if ( exists( $bMatches->{$ai} ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 55 | $k = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 55 | for $j ( @{ $bMatches->{$ai} } ) | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # optimization: most of the time this will be true | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 55 | ▶ | if ( $k and $thresh->[$k] > $j and $thresh->[ $k - 1 ] < $j ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$k and $thresh->[$k] > $j and $$thresh[$k - 1] < $j
$k and $thresh->[$k] > $j
MC/DC0%0/3
$k and $thresh->[$k] > $j and $$thresh[$k - 1] < $j
$k
$thresh->[$k] > $j
$$thresh[$k - 1] < $j
Truth table25%1/4
A and B and C
A= $kB= $thresh->[$k] > $jC= $$thresh[$k - 1] < $j
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $thresh->[$k] = $j; | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 55 | $k = _replaceNextLargerWith( $thresh, $j, $k ); | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # oddly, it's faster to always test this (CPU cache?). | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 55 | ▶ | if ( defined($k) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 55 | ▶ | $links->[$k] = | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | [ ( $k ? $links->[ $k - 1 ] : undef ), $i, $j ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 36 | ▶ | if (@$thresh) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 14 | ▶ | return $prunedCount + @$thresh if $counting; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 14 | ▶ | for ( my $link = $links->[$#$thresh] ; $link ; $link = $link->[0] ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 55 | $matchVector->[ $link->[1] ] = $link->[2]; | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | elsif ($counting) | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return $prunedCount; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 36 | ▶ | return wantarray ? @$matchVector : $matchVector; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | sub traverse_sequences | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
traverse_sequences: called CC=20 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 3 | my $a = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 3 | my $b = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | 3 | ▶ | my $callbacks = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 3 | my $keyGen = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 247 | 3 | ▶ | my $matchCallback = $callbacks->{'MATCH'} || sub { }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'MATCH'} || sub {
}
MC/DC0%0/2
$callbacks->{'MATCH'} || sub {
}
$callbacks->{'MATCH'}
sub {
}
Truth table33%1/3
A || B
A= $callbacks->{'MATCH'}B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | ▶ | my $discardACallback = $callbacks->{'DISCARD_A'} || sub { }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'DISCARD_A'} || sub {
}
MC/DC0%0/2
$callbacks->{'DISCARD_A'} || sub {
}
$callbacks->{'DISCARD_A'}
sub {
}
Truth table33%1/3
A || B
A= $callbacks->{'DISCARD_A'}B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 3 | my $finishedACallback = $callbacks->{'A_FINISHED'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | 3 | ▶ | my $discardBCallback = $callbacks->{'DISCARD_B'} || sub { }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'DISCARD_B'} || sub {
}
MC/DC0%0/2
$callbacks->{'DISCARD_B'} || sub {
}
$callbacks->{'DISCARD_B'}
sub {
}
Truth table33%1/3
A || B
A= $callbacks->{'DISCARD_B'}B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 3 | my $finishedBCallback = $callbacks->{'B_FINISHED'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 3 | my $matchVector = _longestCommonSubsequence( $a, $b, 0, $keyGen, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # Process all the lines in @$matchVector | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 3 | my $lastA = $#$a; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | 3 | my $lastB = $#$b; | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | 3 | my $bi = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 3 | my $ai; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 3 | ▶ | for ( $ai = 0 ; $ai <= $#$matchVector ; $ai++ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 24 | my $bLine = $matchVector->[$ai]; | |||||||||||||||||||||||||||||||||||||||||||||
| 263 | 24 | ▶ | if ( defined($bLine) ) # matched | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 18 | ▶ | &$discardBCallback( $ai, $bi++, @_ ) while $bi < $bLine; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 18 | &$matchCallback( $ai, $bi++, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 6 | &$discardACallback( $ai, $bi, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # The last entry (if any) processed was a match. | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # $ai and $bi point just past the last matching lines in their sequences. | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 3 | ▶ | while ( $ai <= $lastA or $bi <= $lastB ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ai <= $lastA or $bi <= $lastB
MC/DC100%2/2
$ai <= $lastA or $bi <= $lastB
$ai <= $lastA
$bi <= $lastB
Truth table100%3/3
A or B
A= $ai <= $lastAB= $bi <= $lastB
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # last A? | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 9 | ▶ | if ( $ai == $lastA + 1 and $bi <= $lastB ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ai == $lastA + 1 and $bi <= $lastB
MC/DC50%1/2
$ai == $lastA + 1 and $bi <= $lastB
$ai == $lastA + 1
$bi <= $lastB
Truth table66%2/3
A and B
A= $ai == $lastA + 1B= $bi <= $lastB
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 3 | ▶ | if ( defined($finishedACallback) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | &$finishedACallback( $lastA, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | $finishedACallback = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | ▶ | &$discardBCallback( $ai, $bi++, @_ ) while $bi <= $lastB; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # last B? | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 9 | ▶ | if ( $bi == $lastB + 1 and $ai <= $lastA ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$bi == $lastB + 1 and $ai <= $lastA
MC/DC0%0/2
$bi == $lastB + 1 and $ai <= $lastA
$bi == $lastB + 1
$ai <= $lastA
Truth table66%2/3
A and B
A= $bi == $lastB + 1B= $ai <= $lastA
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if ( defined($finishedBCallback) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | &$finishedBCallback( $lastB, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $finishedBCallback = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | &$discardACallback( $ai++, $bi, @_ ) while $ai <= $lastA; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 9 | ▶ | &$discardACallback( $ai++, $bi, @_ ) if $ai <= $lastA; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 9 | ▶ | &$discardBCallback( $ai, $bi++, @_ ) if $bi <= $lastB; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | sub traverse_balanced | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 20 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
traverse_balanced: called CC=20 SCAR=30.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 20 | my $a = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | 20 | my $b = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | 20 | ▶ | my $callbacks = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 20 | my $keyGen = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | 20 | ▶ | my $matchCallback = $callbacks->{'MATCH'} || sub { }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'MATCH'} || sub {
}
MC/DC0%0/2
$callbacks->{'MATCH'} || sub {
}
$callbacks->{'MATCH'}
sub {
}
Truth table33%1/3
A || B
A= $callbacks->{'MATCH'}B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 20 | ▶ | my $discardACallback = $callbacks->{'DISCARD_A'} || sub { }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'DISCARD_A'} || sub {
}
MC/DC0%0/2
$callbacks->{'DISCARD_A'} || sub {
}
$callbacks->{'DISCARD_A'}
sub {
}
Truth table33%1/3
A || B
A= $callbacks->{'DISCARD_A'}B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 20 | ▶ | my $discardBCallback = $callbacks->{'DISCARD_B'} || sub { }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$callbacks->{'DISCARD_B'} || sub {
}
MC/DC0%0/2
$callbacks->{'DISCARD_B'} || sub {
}
$callbacks->{'DISCARD_B'}
sub {
}
Truth table33%1/3
A || B
A= $callbacks->{'DISCARD_B'}B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 20 | my $changeCallback = $callbacks->{'CHANGE'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | 20 | my $matchVector = _longestCommonSubsequence( $a, $b, 0, $keyGen, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # Process all the lines in match vector | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 20 | my $lastA = $#$a; | |||||||||||||||||||||||||||||||||||||||||||||
| 329 | 20 | my $lastB = $#$b; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | 20 | my $bi = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | 20 | my $ai = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | 20 | my $ma = -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | 20 | my $mb; | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 20 | while (1) | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # Find next match indices $ma and $mb | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 52 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ma <= $matchVector->$#* and not defined $matchVector->[$ma]
MC/DC100%2/2
$ma <= $matchVector->$#* and not defined $matchVector->[$ma]
$ma <= $matchVector->$#*
not defined $matchVector->[$ma]
Truth table100%3/3
A and not(B)
A= $ma <= $matchVector->$#*B= not defined $matchVector->[$ma]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 71 | $ma++; | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | } while( | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | $ma <= $#$matchVector | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | && !defined $matchVector->[$ma] | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 52 | ▶ | last if $ma > $#$matchVector; # end of matchVector? | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 32 | $mb = $matchVector->[$ma]; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # Proceed with discard a/b or change events until | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # next match | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 32 | ▶ | while ( $ai < $ma || $bi < $mb ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ai < $ma or $bi < $mb
MC/DC100%2/2
$ai < $ma or $bi < $mb
$ai < $ma
$bi < $mb
Truth table100%3/3
A or B
A= $ai < $maB= $bi < $mb
| |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 38 | ▶ | if ( $ai < $ma && $bi < $mb ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$ai < $ma and $bi < $mb
MC/DC100%2/2
$ai < $ma and $bi < $mb
$ai < $ma
$bi < $mb
Truth table100%3/3
A and B
A= $ai < $maB= $bi < $mb
| |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # Change | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 10 | ▶ | if ( defined $changeCallback ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 9 | &$changeCallback( $ai++, $bi++, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | &$discardACallback( $ai++, $bi, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | &$discardBCallback( $ai, $bi++, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | elsif ( $ai < $ma ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 9 | &$discardACallback( $ai++, $bi, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # $bi < $mb | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 19 | &$discardBCallback( $ai, $bi++, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # Match | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 32 | &$matchCallback( $ai++, $bi++, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 20 | ▶ | while ( $ai <= $lastA || $bi <= $lastB ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ai <= $lastA or $bi <= $lastB
MC/DC100%2/2
$ai <= $lastA or $bi <= $lastB
$ai <= $lastA
$bi <= $lastB
Truth table100%3/3
A or B
A= $ai <= $lastAB= $bi <= $lastB
| |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 22 | ▶ | if ( $ai <= $lastA && $bi <= $lastB ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$ai <= $lastA and $bi <= $lastB
MC/DC100%2/2
$ai <= $lastA and $bi <= $lastB
$ai <= $lastA
$bi <= $lastB
Truth table100%3/3
A and B
A= $ai <= $lastAB= $bi <= $lastB
| |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # Change | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 10 | ▶ | if ( defined $changeCallback ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 10 | &$changeCallback( $ai++, $bi++, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | &$discardACallback( $ai++, $bi, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | &$discardBCallback( $ai, $bi++, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | elsif ( $ai <= $lastA ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 7 | &$discardACallback( $ai++, $bi, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # $bi <= $lastB | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 5 | &$discardBCallback( $ai, $bi++, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 20 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | sub prepare | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my $a = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $keyGen = shift; # code ref | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # set up code ref | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | $keyGen = sub { $_[0] } unless defined($keyGen); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | return scalar _withPositionsOfInInterval( $a, 0, $#$a, $keyGen, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | sub LCS | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
LCS: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 1 | my $a = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | my $b = shift; # array ref or hash ref | |||||||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | my $matchVector = _longestCommonSubsequence( $a, $b, 0, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 431 | 1 | my @retval; | |||||||||||||||||||||||||||||||||||||||||||||
| 432 | my $i; | ||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 1 | ▶ | for ( $i = 0 ; $i <= $#$matchVector ; $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 8 | ▶ | if ( defined( $matchVector->[$i] ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 6 | push ( @retval, $a->[$i] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 1 | ▶ | return wantarray ? @retval : \@retval; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | sub LCS_length | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
LCS_length: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $a = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my $b = shift; # array ref or hash ref | |||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | return _longestCommonSubsequence( $a, $b, 1, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||
| 450 | sub LCSidx | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
LCSidx: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 11 | my $a= shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | 11 | my $b= shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 454 | 11 | my $match= _longestCommonSubsequence( $a, $b, 0, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 455 | 11 | my @am= grep defined $match->[$_], 0..$#$match; | |||||||||||||||||||||||||||||||||||||||||||||
| 456 | 11 | my @bm= @{$match}[@am]; | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | 11 | return \@am, \@bm; | |||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | sub compact_diff | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compact_diff: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 11 | my $a= shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 463 | 11 | my $b= shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 464 | 11 | my( $am, $bm )= LCSidx( $a, $b, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | 11 | my @cdiff; | |||||||||||||||||||||||||||||||||||||||||||||
| 466 | 11 | my( $ai, $bi )= ( 0, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 467 | 11 | push @cdiff, $ai, $bi; | |||||||||||||||||||||||||||||||||||||||||||||
| 468 | 11 | while( 1 ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 469 | 22 | ▶ | while( @$am && $ai == $am->[0] && $bi == $bm->[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@$am and $ai == $am->[0] and $bi == $bm->[0]
@$am and $ai == $am->[0]
MC/DC100%3/3
@$am and $ai == $am->[0] and $bi == $bm->[0]
@$am
$ai == $am->[0]
$bi == $bm->[0]
Truth table100%4/4
A and B and C
A= @$amB= $ai == $am->[0]C= $bi == $bm->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 22 | shift @$am; | |||||||||||||||||||||||||||||||||||||||||||||
| 471 | 22 | shift @$bm; | |||||||||||||||||||||||||||||||||||||||||||||
| 472 | 22 | ++$ai, ++$bi; | |||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 22 | push @cdiff, $ai, $bi; | |||||||||||||||||||||||||||||||||||||||||||||
| 475 | 22 | ▶ | last if ! @$am; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 11 | $ai = $am->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 477 | 11 | $bi = $bm->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 478 | 11 | push @cdiff, $ai, $bi; | |||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 11 | ▶ | push @cdiff, 0+@$a, 0+@$b | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ai < @$a or $bi < @$b
MC/DC100%2/2
$ai < @$a or $bi < @$b
$ai < @$a
$bi < @$b
Truth table100%3/3
A or B
A= $ai < @$aB= $bi < @$b
| |||||||||||||||||||||||||||||||||||||||||||||||
| 481 | if $ai < @$a || $bi < @$b; | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 11 | ▶ | return wantarray ? @cdiff : \@cdiff; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | sub diff | ||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diff: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 1 | my $a = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | my $b = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 489 | 1 | my $retval = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 490 | 1 | my $hunk = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 491 | 4 | ▶ | my $discard = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 4 | push @$hunk, [ '-', $_[0], $a->[ $_[0] ] ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 493 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 494 | 6 | ▶ | my $add = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 6 | push @$hunk, [ '+', $_[1], $b->[ $_[1] ] ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 497 | 7 | ▶ | my $match = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 7 | ▶ | push @$retval, $hunk | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 499 | if 0 < @$hunk; | ||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 7 | $hunk = [] | |||||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 502 | 1 | traverse_sequences( $a, $b, | |||||||||||||||||||||||||||||||||||||||||||||
| 503 | { MATCH => $match, DISCARD_A => $discard, DISCARD_B => $add }, @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 1 | &$match(); | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | 1 | ▶ | return wantarray ? @$retval : $retval; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | sub sdiff | ||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sdiff: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 12 | my $a = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 511 | 12 | my $b = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 512 | 12 | my $retval = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 513 | 12 | ▶ | my $discard = sub { push ( @$retval, [ '-', $a->[ $_[0] ], "" ] ) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 12 | ▶ | my $add = sub { push ( @$retval, [ '+', "", $b->[ $_[1] ] ] ) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 8 | ▶ | my $change = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 8 | push ( @$retval, [ 'c', $a->[ $_[0] ], $b->[ $_[1] ] ] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 517 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 518 | 23 | ▶ | my $match = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 23 | push ( @$retval, [ 'u', $a->[ $_[0] ], $b->[ $_[1] ] ] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 520 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 521 | 12 | traverse_balanced( | |||||||||||||||||||||||||||||||||||||||||||||
| 522 | $a, | ||||||||||||||||||||||||||||||||||||||||||||||
| 523 | $b, | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | MATCH => $match, | ||||||||||||||||||||||||||||||||||||||||||||||
| 526 | DISCARD_A => $discard, | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | DISCARD_B => $add, | ||||||||||||||||||||||||||||||||||||||||||||||
| 528 | CHANGE => $change, | ||||||||||||||||||||||||||||||||||||||||||||||
| 529 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | @_ | ||||||||||||||||||||||||||||||||||||||||||||||
| 531 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 12 | ▶ | return wantarray ? @$retval : $retval; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||
| 535 | ######################################## | ||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 2 | my $Root= __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||||||
| 537 | package Algorithm::Diff::_impl; | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||
| 540 | sub _Idx() { 0 } # $me->[_Idx]: Ref to array of hunk indices | ||||||||||||||||||||||||||||||||||||||||||||||
| 541 | # 1 # $me->[1]: Ref to first sequence | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | # 2 # $me->[2]: Ref to second sequence | ||||||||||||||||||||||||||||||||||||||||||||||
| 543 | sub _End() { 3 } # $me->[_End]: Diff between forward and reverse pos | ||||||||||||||||||||||||||||||||||||||||||||||
| 544 | sub _Same() { 4 } # $me->[_Same]: 1 if pos 1 contains unchanged items | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | sub _Base() { 5 } # $me->[_Base]: Added to range's min and max | ||||||||||||||||||||||||||||||||||||||||||||||
| 546 | sub _Pos() { 6 } # $me->[_Pos]: Which hunk is currently selected | ||||||||||||||||||||||||||||||||||||||||||||||
| 547 | sub _Off() { 7 } # $me->[_Off]: Offset into _Idx for current position | ||||||||||||||||||||||||||||||||||||||||||||||
| 548 | sub _Min() { -2 } # Added to _Off to get min instead of max+1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||
| 550 | sub Die | ||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 230 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Die: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 230 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||
| 553 | 230 | Carp::confess( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||
| 556 | sub _ChkPos | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 1052 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ChkPos: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 1052 | my( $me )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 559 | 1052 | ▶ | return if $me->[_Pos]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 110 | my $meth= ( caller(1) )[3]; | |||||||||||||||||||||||||||||||||||||||||||||
| 561 | 110 | Die( "Called $meth on 'reset' object" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||
| 564 | sub _ChkSeq | ||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 650 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ChkSeq: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 650 | my( $me, $seq )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 567 | 650 | ▶ | return $seq + $me->[_Off] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
1 == $seq or 2 == $seq
MC/DC100%2/2
1 == $seq or 2 == $seq
1 == $seq
2 == $seq
Truth table100%3/3
A or B
A= 1 == $seqB= 2 == $seq
| |||||||||||||||||||||||||||||||||||||||||||||||
| 568 | if 1 == $seq || 2 == $seq; | ||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 110 | my $meth= ( caller(1) )[3]; | |||||||||||||||||||||||||||||||||||||||||||||
| 570 | 110 | Die( "$meth: Invalid sequence number ($seq); must be 1 or 2" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||
| 573 | sub getObjPkg | ||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 13 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getObjPkg: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 13 | my( $us )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 576 | 13 | ▶ | return ref $us if ref $us; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 13 | return $us . "::_obj"; | |||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||
| 580 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 11 | my( $us, $seq1, $seq2, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 583 | 11 | my @args; | |||||||||||||||||||||||||||||||||||||||||||||
| 584 | 11 | for( $opts->{keyGen} ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 585 | 11 | ▶ | push @args, $_ if $_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 11 | for( $opts->{keyGenArgs} ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 588 | 11 | ▶ | push @args, @$_ if $_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 11 | my $cdif= Algorithm::Diff::compact_diff( $seq1, $seq2, @args ); | |||||||||||||||||||||||||||||||||||||||||||||
| 591 | 11 | my $same= 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 592 | 11 | ▶ | if( 0 == $cdif->[2] && 0 == $cdif->[3] ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
0 == $cdif->[2] and 0 == $cdif->[3]
MC/DC50%1/2
0 == $cdif->[2] and 0 == $cdif->[3]
0 == $cdif->[2]
0 == $cdif->[3]
Truth table66%2/3
A and B
A= 0 == $cdif->[2]B= 0 == $cdif->[3]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 8 | $same= 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 594 | 8 | splice @$cdif, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 11 | my @obj= ( $cdif, $seq1, $seq2 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 597 | 11 | $obj[_End] = (1+@$cdif)/2; | |||||||||||||||||||||||||||||||||||||||||||||
| 598 | 11 | $obj[_Same] = $same; | |||||||||||||||||||||||||||||||||||||||||||||
| 599 | 11 | $obj[_Base] = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 600 | 11 | my $me = bless \@obj, $us->getObjPkg(); | |||||||||||||||||||||||||||||||||||||||||||||
| 601 | 11 | $me->Reset( 0 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 602 | 11 | return $me; | |||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||
| 605 | sub Reset | ||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 330 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Reset: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 330 | my( $me, $pos )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 608 | 330 | ▶ | $pos= int( $pos || 0 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pos || 0
MC/DC100%1/1
$pos || 0
$pos
Truth table100%2/2
A
A= $pos
| |||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 330 | ▶ | $pos += $me->[_End] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 610 | if $pos < 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 330 | ▶ | $pos= 0 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pos < 0 or $me->[3] <= $pos
MC/DC100%2/2
$pos < 0 or $me->[3] <= $pos
$pos < 0
$me->[3] <= $pos
Truth table100%3/3
A or B
A= $pos < 0B= $me->[3] <= $pos
| |||||||||||||||||||||||||||||||||||||||||||||||
| 612 | if $pos < 0 || $me->[_End] <= $pos; | ||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 330 | ▶ | $me->[_Pos]= $pos || !1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pos || !1
MC/DC100%1/1
$pos || !1
$pos
Truth table100%2/2
A
A= $pos
| |||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 330 | $me->[_Off]= 2*$pos - 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | 330 | return $me; | |||||||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||
| 618 | sub Base | ||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 162 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Base: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 162 | my( $me, $base )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 621 | 162 | my $oldBase= $me->[_Base]; | |||||||||||||||||||||||||||||||||||||||||||||
| 622 | 162 | ▶ | $me->[_Base]= 0+$base if defined $base; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 162 | return $oldBase; | |||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||||||
| 626 | sub Copy | ||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 54 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Copy: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 54 | my( $me, $pos, $base )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 629 | 54 | my @obj= @$me; | |||||||||||||||||||||||||||||||||||||||||||||
| 630 | 54 | my $you= bless \@obj, ref($me); | |||||||||||||||||||||||||||||||||||||||||||||
| 631 | 54 | ▶ | $you->Reset( $pos ) if defined $pos; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 54 | $you->Base( $base ); | |||||||||||||||||||||||||||||||||||||||||||||
| 633 | 54 | return $you; | |||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 347 | ▶ | sub Next { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Next: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 347 | my( $me, $steps )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 638 | 347 | ▶ | $steps= 1 if ! defined $steps; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 347 | ▶ | if( $steps ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 242 | my $pos= $me->[_Pos]; | |||||||||||||||||||||||||||||||||||||||||||||
| 641 | 242 | my $new= $pos + $steps; | |||||||||||||||||||||||||||||||||||||||||||||
| 642 | 242 | ▶ | $new= 0 if $pos && $new < 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pos and $new < 0
MC/DC100%2/2
$pos and $new < 0
$pos
$new < 0
Truth table100%3/3
A and B
A= $posB= $new < 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 242 | $me->Reset( $new ) | |||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 347 | return $me->[_Pos]; | |||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 109 | ▶ | sub Prev { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Prev: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 109 | my( $me, $steps )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 650 | 109 | ▶ | $steps= 1 if ! defined $steps; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 109 | my $pos= $me->Next(-$steps); | |||||||||||||||||||||||||||||||||||||||||||||
| 652 | 109 | ▶ | $pos -= $me->[_End] if $pos; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 109 | return $pos; | |||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 81 | ▶ | sub Diff { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Diff: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 81 | my( $me )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 658 | 81 | $me->_ChkPos(); | |||||||||||||||||||||||||||||||||||||||||||||
| 659 | 70 | ▶ | return 0 if $me->[_Same] == ( 1 & $me->[_Pos] ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 50 | my $ret= 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 661 | 50 | my $off= $me->[_Off]; | |||||||||||||||||||||||||||||||||||||||||||||
| 662 | 50 | for my $seq ( 1, 2 ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 663 | 100 | ▶ | $ret |= $seq | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 664 | if $me->[_Idx][ $off + $seq + _Min ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 665 | < $me->[_Idx][ $off + $seq ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 50 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 91 | ▶ | sub Min { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Min: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 91 | my( $me, $seq, $base )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 672 | 91 | $me->_ChkPos(); | |||||||||||||||||||||||||||||||||||||||||||||
| 673 | 80 | my $off= $me->_ChkSeq($seq); | |||||||||||||||||||||||||||||||||||||||||||||
| 674 | 50 | ▶ | $base= $me->[_Base] if !defined $base; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 50 | return $base + $me->[_Idx][ $off + _Min ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 91 | ▶ | sub Max { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Max: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 91 | my( $me, $seq, $base )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 680 | 91 | $me->_ChkPos(); | |||||||||||||||||||||||||||||||||||||||||||||
| 681 | 80 | my $off= $me->_ChkSeq($seq); | |||||||||||||||||||||||||||||||||||||||||||||
| 682 | 50 | ▶ | $base= $me->[_Base] if !defined $base; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 50 | return $base + $me->[_Idx][ $off ] -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 295 | ▶ | sub Range { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Range: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 295 | my( $me, $seq, $base )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 688 | 295 | $me->_ChkPos(); | |||||||||||||||||||||||||||||||||||||||||||||
| 689 | 284 | my $off = $me->_ChkSeq($seq); | |||||||||||||||||||||||||||||||||||||||||||||
| 690 | 254 | ▶ | if( !wantarray ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 104 | return $me->[_Idx][ $off ] | |||||||||||||||||||||||||||||||||||||||||||||
| 692 | - $me->[_Idx][ $off + _Min ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 150 | ▶ | $base= $me->[_Base] if !defined $base; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 150 | return ( $base + $me->[_Idx][ $off + _Min ] ) | |||||||||||||||||||||||||||||||||||||||||||||
| 696 | .. ( $base + $me->[_Idx][ $off ] - 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 217 | ▶ | sub Items { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Items: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 217 | my( $me, $seq )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 701 | 217 | $me->_ChkPos(); | |||||||||||||||||||||||||||||||||||||||||||||
| 702 | 206 | my $off = $me->_ChkSeq($seq); | |||||||||||||||||||||||||||||||||||||||||||||
| 703 | 186 | ▶ | if( !wantarray ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 48 | return $me->[_Idx][ $off ] | |||||||||||||||||||||||||||||||||||||||||||||
| 705 | - $me->[_Idx][ $off + _Min ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 707 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 138 | @{$me->[$seq]}[ | |||||||||||||||||||||||||||||||||||||||||||||
| 709 | $me->[_Idx][ $off + _Min ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 710 | .. ( $me->[_Idx][ $off ] - 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 711 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 156 | ▶ | sub Same { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Same: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 156 | my( $me )= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 716 | 156 | $me->_ChkPos(); | |||||||||||||||||||||||||||||||||||||||||||||
| 717 | 112 | ▶ | return wantarray ? () : 0 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 718 | if $me->[_Same] != ( 1 & $me->[_Pos] ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 62 | return $me->Items(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 2 | my %getName; | |||||||||||||||||||||||||||||||||||||||||||||
| 723 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 2 | %getName= ( | |||||||||||||||||||||||||||||||||||||||||||||
| 725 | same => \&Same, | ||||||||||||||||||||||||||||||||||||||||||||||
| 726 | diff => \&Diff, | ||||||||||||||||||||||||||||||||||||||||||||||
| 727 | base => \&Base, | ||||||||||||||||||||||||||||||||||||||||||||||
| 728 | min => \&Min, | ||||||||||||||||||||||||||||||||||||||||||||||
| 729 | max => \&Max, | ||||||||||||||||||||||||||||||||||||||||||||||
| 730 | range=> \&Range, | ||||||||||||||||||||||||||||||||||||||||||||||
| 731 | items=> \&Items, # same thing | ||||||||||||||||||||||||||||||||||||||||||||||
| 732 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||
| 735 | sub Get | ||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 121 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Get: called CC=8 SCAR=21.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 121 | my $me= shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 738 | 121 | $me->_ChkPos(); | |||||||||||||||||||||||||||||||||||||||||||||
| 739 | 110 | my @value; | |||||||||||||||||||||||||||||||||||||||||||||
| 740 | 110 | for my $arg ( @_ ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 741 | 130 | for my $word ( split ' ', $arg ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 742 | 160 | my $meth; | |||||||||||||||||||||||||||||||||||||||||||||
| 743 | 160 | ▶ | if( $word !~ /^(-?\d+)?([a-zA-Z]+)([12])?$/ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$word =~ /^(-?\d+)?([a-zA-Z]+)([12])?$/ and $meth = $getName{lc $2}
MC/DC0%0/2
$word =~ /^(-?\d+)?([a-zA-Z]+)([12])?$/ and $meth = $getName{lc $2}
$word =~ /^(-?\d+)?([a-zA-Z]+)([12])?$/
$meth = $getName{lc $2}
Truth table33%1/3
A and B
A= $word =~ /^(-?\d+)?([a-zA-Z]+)([12])?$/B= $meth = $getName{lc $2}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 744 | || not $meth= $getName{ lc $2 } | ||||||||||||||||||||||||||||||||||||||||||||||
| 745 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | Die( $Root, ", Get: Invalid request ($word)" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 160 | my( $base, $name, $seq )= ( $1, $2, $3 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 749 | 160 | ▶ | push @value, scalar( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 4 == length($name) | ||||||||||||||||||||||||||||||||||||||||||||||
| 751 | ? $meth->( $me ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 752 | : $meth->( $me, $seq, $base ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 753 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 80 | ▶ | if( wantarray ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 30 | return @value; | |||||||||||||||||||||||||||||||||||||||||||||
| 758 | } elsif( 1 == @value ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 40 | return $value[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 10 | Die( 0+@value, " values requested from ", | |||||||||||||||||||||||||||||||||||||||||||||
| 762 | $Root, "'s Get in scalar context" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 2 | my $Obj= getObjPkg($Root); | |||||||||||||||||||||||||||||||||||||||||||||
| 767 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 2 | for my $meth ( qw( new getObjPkg ) ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 770 | 4 | *{$Root."::".$meth} = \&{$meth}; | |||||||||||||||||||||||||||||||||||||||||||||
| 771 | 4 | *{$Obj ."::".$meth} = \&{$meth}; | |||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 2 | for my $meth ( qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 774 | Next Prev Reset Copy Base Diff | ||||||||||||||||||||||||||||||||||||||||||||||
| 775 | Same Items Range Min Max Get | ||||||||||||||||||||||||||||||||||||||||||||||
| 776 | _ChkPos _ChkSeq | ||||||||||||||||||||||||||||||||||||||||||||||
| 777 | ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 28 | *{$Obj."::".$meth} = \&{$meth}; | |||||||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 782 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||