| 1 | package Data::RunningTotal; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use 5.005; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Data::RunningTotal::Item; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # Create a new Running Total object | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my $that = shift; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | my $class = ref($that) || $that; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table33%1/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | croak("Missing required parameter 'dimensions'") if !exists($opts{dimensions}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | croak("'dimensions' paramter must be an array ref") if (ref($opts{dimensions}) ne "ARRAY"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | my @dimensions = @{$opts{dimensions}}; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | # Remember the dimensions | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | my %state = (dims => \@dimensions, | |||||||||||||||||||||||||||||||||||||||||
| 28 | numDims => scalar(@dimensions), | ||||||||||||||||||||||||||||||||||||||||||
| 29 | counts => [], | ||||||||||||||||||||||||||||||||||||||||||
| 30 | pendingUpdates => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | updatesPending => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | return bless(\%state); | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # Increment the count for a specific point | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 14 | ▶ | sub inc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inc: called CC=5 SCAR=17.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 14 | my ($self, $time, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 14 | ▶ | croak("Missing required parameter 'coords'") if !exists($opts{coords}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 14 | ▶ | croak("'coords' paramter must be an array ref") if (ref($opts{coords}) ne "ARRAY"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 14 | ▶ | my $weight = $opts{weight} || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'weight'} || 1
MC/DC0%0/1
$opts{'weight'} || 1
$opts{'weight'}
Truth table50%1/2
A
A= $opts{'weight'}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 14 | ▶ | if (scalar(@{$opts{coords}}) != $self->{numDims}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | croak("Expected $self->{numDims} coordinates, but ".scalar(@{$opts{coords}})." given"); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 14 | $self->{updatesPending}++; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 14 | push(@{$self->{pendingUpdates}{$time}}, [$weight, @{$opts{coords}}]); | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # Decrement the count for a specific point | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 7 | ▶ | sub dec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dec: called CC=5 SCAR=17.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | my ($self, $time, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | ▶ | croak("Missing required parameter 'coords'") if !exists($opts{coords}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 7 | ▶ | croak("'coords' paramter must be an array ref") if (ref($opts{coords}) ne "ARRAY"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 7 | ▶ | my $weight = ($opts{weight} || 1) * -1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'weight'} || 1
MC/DC0%0/1
$opts{'weight'} || 1
$opts{'weight'}
Truth table50%1/2
A
A= $opts{'weight'}
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 7 | ▶ | if (scalar(@{$opts{coords}}) != $self->{numDims}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | croak("Expected $self->{numDims} coordinates, but ".scalar(@{$opts{coords}})." given"); | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 7 | $self->{updatesPending}++; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 7 | push(@{$self->{pendingUpdates}{$time}}, [$weight, @{$opts{coords}}]); | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | # Create a new item that can be moved in the space | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 5 | ▶ | sub newItem { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
newItem: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | ▶ | my $weight = $opts{weight} || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'weight'} || 1
MC/DC0%0/1
$opts{'weight'} || 1
$opts{'weight'}
Truth table50%1/2
A
A= $opts{'weight'}
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 5 | return Data::RunningTotal::Item->new($self, $self->{numDims}, $weight); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | # Get the count for a specific point or volume in time | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # Note that the coords can be code refs | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 16 | ▶ | sub getValue { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getValue: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 16 | my ($self, $time, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 16 | ▶ | croak("Missing required parameter 'coords'") if !exists($opts{coords}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 16 | ▶ | croak("'coords' paramter must be an array ref") if (ref($opts{coords}) ne "ARRAY"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 16 | $self->_applyPending(); | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 16 | my $lastIdx = $self->_findIndexForTime($time); | |||||||||||||||||||||||||||||||||||||||||
| 92 | my ($eligCoords, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 16 | $numPermutations) = $self->_getEligibleCoords(@{$opts{coords}}); | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # It is possible that the user asked for a value that has never been seen | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 16 | ▶ | return 0 if !defined $eligCoords; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 16 | my $dimArrays = $self->_getDimArrays($eligCoords, $lastIdx); | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | # Do the real work | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 16 | return $self->_getValueWalkingBackwards($dimArrays, $numPermutations); | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | # Get a list of changes to the weight of each of the specified points/volumes | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | ▶ | sub getChangeList { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getChangeList: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | ▶ | croak("Missing required parameter 'coords'") if !exists($opts{coords}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | croak("'coords' paramter must be an array ref") if (ref($opts{coords}) ne "ARRAY"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 6 | $self->_applyPending(); | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | my ($eligCoords, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | $numPermutations) = $self->_getEligibleCoords(@{$opts{coords}}); | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | # It is possible that the user asked for a value that has never been seen | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | ▶ | return [] if !defined $eligCoords; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 6 | my $dimArrays = $self->_getDimArrays($eligCoords); | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | # Do the real work | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 6 | return $self->_getListWalkingForwards($dimArrays, $opts{period}, $opts{start}, $opts{end}); | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | # Pass in N change lists and it will combine them into a single | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # changelist with a time value and N following values | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | sub combineChangeList { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
combineChangeList: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | my ($self, @lists) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | my $numLists = scalar(@lists); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | my @listIdxs; | |||||||||||||||||||||||||||||||||||||||||
| 136 | my @lastVals; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | for my $i (0 .. $numLists-1) { | |||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | $listIdxs[$i] = 0; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | $lastVals[$i] = 0; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | while(1) { | |||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | my $minTime = $lists[0][$listIdxs[0]][0]; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 4 | for my $i (1 .. $numLists-1) { | |||||||||||||||||||||||||||||||||||||||||
| 145 | 4 | my $listTime = $lists[$i][$listIdxs[$i]][0]; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 4 | ▶ | $minTime = $listTime if !defined $minTime || defined $listTime && $listTime < $minTime; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not defined $minTime or defined $listTime and $listTime < $minTime
defined $listTime and $listTime < $minTime
MC/DC100%3/3
not defined $minTime or defined $listTime and $listTime < $minTime
not defined $minTime
defined $listTime
$listTime < $minTime
Truth table100%4/4
not(A) or B and C
A= not defined $minTimeB= defined $listTimeC= $listTime < $minTime
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | ▶ | last if !defined $minTime; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | for my $i (0 .. $numLists-1) { | |||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | my $listTime = $lists[$i][$listIdxs[$i]][0]; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 6 | ▶ | if (defined $listTime && $listTime == $minTime) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $listTime and $listTime == $minTime
MC/DC100%2/2
defined $listTime and $listTime == $minTime
defined $listTime
$listTime == $minTime
Truth table100%3/3
A and B
A= defined $listTimeB= $listTime == $minTime
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | $lastVals[$i] = $lists[$i][$listIdxs[$i]][1]; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | $listIdxs[$i]++; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | push(@res, [$minTime, @lastVals]); | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | return \@res; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 167 | ## Private Methods | ||||||||||||||||||||||||||||||||||||||||||
| 168 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | # Just dump out the state - should be removed before prime time | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub _dumpState { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dumpState: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | # print Dumper $self; | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | # Apply all the pending updates | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 22 | ▶ | sub _applyPending { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_applyPending: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 22 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 22 | ▶ | if ($self->{updatesPending} == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 20 | return; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # Clean out last data | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | @{$self->{counts}} = (); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | @{$self->{dimIdxs}} = (); | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | my %last; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 2 | my $idx = 0; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 2 | foreach my $time (sort {$a <=> $b} keys(%{$self->{pendingUpdates}})) { | |||||||||||||||||||||||||||||||||||||||||
| 193 | 16 | foreach my $update (@{$self->{pendingUpdates}{$time}}) { | |||||||||||||||||||||||||||||||||||||||||
| 194 | 21 | my $tref = \%last; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 21 | my $coords = $update; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 21 | my $weight = shift(@{$coords}); | |||||||||||||||||||||||||||||||||||||||||
| 197 | # map {$tref->{$_} = {} if !defined($tref->{$_}); $tref = $tref->{$_};} @{$coords}; | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 21 | ▶ | map {$tref = ($tref->{$_} ||= {});} @{$coords}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$tref->{$_} ||= {}
MC/DC100%1/1
$tref->{$_} ||= {}
$tref->{$_}
Truth table100%2/2
A
A= $tref->{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 21 | $tref->{val} += $weight; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 21 | push(@{$self->{counts}}, [$time, $tref->{val}, $tref->{lastIdx}]); | |||||||||||||||||||||||||||||||||||||||||
| 201 | 21 | $tref->{lastIdx} = $idx; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 21 | foreach my $dim (0 .. $self->{numDims}-1) { | |||||||||||||||||||||||||||||||||||||||||
| 203 | 84 | push(@{$self->{dimIdxs}[$dim]{$coords->[$dim]}}, $idx); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 21 | $idx++; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 2 | $self->{updatesPending} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | # Look through the list of counts ordered by time and find the | ||||||||||||||||||||||||||||||||||||||||||
| 213 | # index for the specified time | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 16 | ▶ | sub _findIndexForTime { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_findIndexForTime: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 16 | my ($self, $time) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | # just do a simple binary search to find the first entry that | ||||||||||||||||||||||||||||||||||||||||||
| 218 | # is greater than the time or the last entry that equals the time | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 16 | my $start = 0; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 16 | my $end = scalar(@{$self->{counts}})-1; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 16 | my $origEnd = $end; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 16 | my $lastSmaller; | |||||||||||||||||||||||||||||||||||||||||
| 223 | my $lastEqual; | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 16 | my $notDone = 1; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 16 | ▶ | while ($notDone) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 53 | ▶ | if ($start >= $end) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 16 | $notDone = 0; | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 53 | my $idx = int(($end-$start)/2)+$start; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 53 | ▶ | if ($self->{counts}[$idx][0] < $time) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 38 | $lastSmaller = $idx; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 38 | $start = $idx+1; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | elsif ($self->{counts}[$idx][0] == $time) { | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | $lastEqual = $idx; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | $start = $idx+1; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 11 | $end = $idx-1; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 16 | ▶ | return $lastEqual if defined $lastEqual; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 13 | ▶ | return $lastSmaller if defined $lastSmaller; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return $origEnd; | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | # Go through all the possible coords and produce a list of lists of them | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 22 | ▶ | sub _getEligibleCoords { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getEligibleCoords: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 22 | my ($self, @coordSels) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 22 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 22 | my $permutations = 1; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 22 | for my $i (0 .. $self->{numDims}-1) { | |||||||||||||||||||||||||||||||||||||||||
| 261 | 88 | my @elig; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 88 | ▶ | if (ref $coordSels[$i] eq "CODE") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | # Call the code ref on each possible coordinate, collecting ones that return true | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | foreach my $coord (keys(%{$self->{dimIdxs}[$i]})) { | |||||||||||||||||||||||||||||||||||||||||
| 265 | 6 | ▶ | if (&{$coordSels[$i]}($coord)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 4 | push(@elig, $coord); | |||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | elsif (!defined $coordSels[$i]) { | ||||||||||||||||||||||||||||||||||||||||||
| 271 | # An undefined coordidate selector behaves like a wildcard | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # foreach my $coord (keys(%{$self->{dimIdxs}[$i]})) { | ||||||||||||||||||||||||||||||||||||||||||
| 273 | # push(@elig, $coord); | ||||||||||||||||||||||||||||||||||||||||||
| 274 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 63 | push(@res, undef); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 63 | $permutations *= scalar(keys(%{$self->{dimIdxs}[$i]})); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 63 | next; | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | elsif (defined $self->{dimIdxs}[$i]{$coordSels[$i]}) { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 23 | push(@elig, $coordSels[$i]); | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 25 | ▶ | if (scalar(@elig) == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | # No coords found for the selector - no value will be found | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 25 | $permutations *= scalar(@elig); | |||||||||||||||||||||||||||||||||||||||||
| 289 | 25 | push(@res, \@elig); | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 22 | return (\@res, $permutations); | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | # This will combine and sort all the selected coordinates into single | ||||||||||||||||||||||||||||||||||||||||||
| 298 | # arrays per dimension | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 22 | ▶ | sub _getDimArrays { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getDimArrays: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 22 | my ($self, $eligibleCoords, $lastIdx) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 22 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 22 | for my $i (0 .. $self->{numDims}-1) { | |||||||||||||||||||||||||||||||||||||||||
| 304 | 88 | ▶ | if (!defined $eligibleCoords->[$i]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | # Do nothing - this indicates that all coordinates should be | ||||||||||||||||||||||||||||||||||||||||||
| 306 | # included, which is what will happen if we don't include any | ||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 25 | elsif (scalar(@{$eligibleCoords->[$i]}) > 1) { | |||||||||||||||||||||||||||||||||||||||||
| 309 | 2 | my @coordList; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | foreach my $coord (@{$eligibleCoords->[$i]}) { | |||||||||||||||||||||||||||||||||||||||||
| 311 | 4 | my $list = $self->{dimIdxs}[$i]{$coord}; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 4 | ▶ | if (defined $lastIdx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 4 | my $end = _binarySearch($list, $lastIdx); | |||||||||||||||||||||||||||||||||||||||||
| 314 | 4 | @coordList = (@coordList, @{$list}[0..$end]); | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | @coordList = (@coordList, @{$list}); | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | @coordList = sort {$a <=> $b} @coordList; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | push(@res, \@coordList); | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 23 | ▶ | if (defined $lastIdx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 12 | my $end = _binarySearch($self->{dimIdxs}[$i]{$eligibleCoords->[$i][0]}, $lastIdx); | |||||||||||||||||||||||||||||||||||||||||
| 326 | 12 | my @subset = @{$self->{dimIdxs}[$i]{$eligibleCoords->[$i][0]}}[0..$end]; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 12 | push(@res, \@subset); | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 11 | push(@res, $self->{dimIdxs}[$i]{$eligibleCoords->[$i][0]}); | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | # Special case - if all the selectors were undef, then there | ||||||||||||||||||||||||||||||||||||||||||
| 337 | # will be no dimension arrays on the result list. Create | ||||||||||||||||||||||||||||||||||||||||||
| 338 | # a single list that contains all the indices | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 22 | ▶ | if (scalar(@res) == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 8 | my @allIndices = (0..$lastIdx); | |||||||||||||||||||||||||||||||||||||||||
| 341 | 8 | push(@res, \@allIndices); | |||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 22 | return \@res; | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 16 | ▶ | sub _getValueWalkingBackwards { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getValueWalkingBackwards: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 16 | my ($self, $dimArrays, $numPermutations) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 16 | my $sum = 0; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 16 | my $nDims = scalar(@{$dimArrays}); | |||||||||||||||||||||||||||||||||||||||||
| 352 | 16 | my $dimBound = $nDims-1; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 16 | my %blackList; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 16 | my $permsFound = 0; | |||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 16 | my @idxs; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 16 | for my $i (0 .. $dimBound) { | |||||||||||||||||||||||||||||||||||||||||
| 358 | 22 | $idxs[$i] = scalar(@{$dimArrays->[$i]})-1; | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 16 | my $currMin = scalar(@{$self->{counts}}); | |||||||||||||||||||||||||||||||||||||||||
| 362 | mainLoop: | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 16 | ▶ | while ($permsFound < $numPermutations) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 82 | my $allTheSame = 1; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 82 | foreach my $i (0 .. $dimBound) { | |||||||||||||||||||||||||||||||||||||||||
| 366 | 106 | ▶ | while ($idxs[$i] >= 0 && $dimArrays->[$i][$idxs[$i]] > $currMin) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$idxs[$i] >= 0 and $dimArrays->[$i][$idxs[$i]] > $currMin
MC/DC100%2/2
$idxs[$i] >= 0 and $dimArrays->[$i][$idxs[$i]] > $currMin
$idxs[$i] >= 0
$dimArrays->[$i][$idxs[$i]] > $currMin
Truth table100%3/3
A and B
A= $idxs[$i] >= 0B= $dimArrays->[$i][$idxs[$i]] > $currMin
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 36 | $idxs[$i]--; | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 106 | ▶ | if ($idxs[$i] < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 5 | last mainLoop; | |||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 101 | ▶ | if ($dimArrays->[$i][$idxs[$i]] < $currMin) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 82 | $currMin = $dimArrays->[$i][$idxs[$i]]; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 82 | ▶ | $allTheSame = 0 unless $i == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 77 | ▶ | if ($allTheSame) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 70 | ▶ | if ($blackList{$currMin}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 38 | $sum += $self->{counts}[$currMin][1]; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 38 | $permsFound++; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 70 | ▶ | $blackList{$self->{counts}[$currMin][2]} = 1 if defined $self->{counts}[$currMin][2]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 70 | $idxs[0]--; | |||||||||||||||||||||||||||||||||||||||||
| 387 | 70 | ▶ | if ($idxs[0] < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 11 | last mainLoop; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 16 | return $sum; | |||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 6 | ▶ | sub _getListWalkingForwards { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getListWalkingForwards: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 6 | my ($self, $dimArrays, $period, $start, $end) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 6 | my $currSum = 0; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 6 | my $nDims = scalar(@{$dimArrays}); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 6 | my $dimBound = $nDims-1; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 6 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | my @idxs; | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 6 | my @maxIdx; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 6 | for my $i (0 .. $dimBound) { | |||||||||||||||||||||||||||||||||||||||||
| 409 | 11 | $idxs[$i] = 0; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 11 | $maxIdx[$i] = scalar(@{$dimArrays->[$i]}); | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 6 | my $currMax = -1; | |||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 6 | my $lastSum; | |||||||||||||||||||||||||||||||||||||||||
| 416 | my $lastTime; | ||||||||||||||||||||||||||||||||||||||||||
| 417 | mainLoop: | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 6 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 419 | 43 | my $allTheSame = 1; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 43 | foreach my $i (0 .. $dimBound) { | |||||||||||||||||||||||||||||||||||||||||
| 421 | 71 | ▶ | while ($idxs[$i] < $maxIdx[$i] && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$idxs[$i] < $maxIdx[$i] and $dimArrays->[$i][$idxs[$i]] < $currMax
MC/DC100%2/2
$idxs[$i] < $maxIdx[$i] and $dimArrays->[$i][$idxs[$i]] < $currMax
$idxs[$i] < $maxIdx[$i]
$dimArrays->[$i][$idxs[$i]] < $currMax
Truth table100%3/3
A and B
A= $idxs[$i] < $maxIdx[$i]B= $dimArrays->[$i][$idxs[$i]] < $currMax
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | $dimArrays->[$i][$idxs[$i]] < $currMax) { | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 32 | $idxs[$i]++; | |||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 71 | ▶ | if ($idxs[$i] >= $maxIdx[$i]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 3 | last mainLoop; | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 68 | ▶ | if ($dimArrays->[$i][$idxs[$i]] > $currMax) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 45 | $currMax = $dimArrays->[$i][$idxs[$i]]; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 45 | ▶ | $allTheSame = 0 unless $i == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 40 | ▶ | if ($allTheSame) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 31 | ▶ | last mainLoop if defined($end) && $self->{counts}[$currMax][0] > $end; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $end and $self->{"counts"}[$currMax][0] > $end
MC/DC0%0/2
defined $end and $self->{"counts"}[$currMax][0] > $end
defined $end
$self->{"counts"}[$currMax][0] > $end
Truth table33%1/3
A and B
A= defined $endB= $self->{"counts"}[$currMax][0] > $end
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 31 | ▶ | $currSum -= $self->{counts}[$self->{counts}[$currMax][2]][1] if defined $self->{counts}[$currMax][2]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 31 | $currSum += $self->{counts}[$currMax][1]; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 31 | _addToPeriodicList(\@res, $period, $self->{counts}[$currMax][0], $currSum); | |||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 40 | $idxs[0]++; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 40 | ▶ | if ($idxs[0] >= $maxIdx[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 3 | last mainLoop; | |||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 6 | return \@res; | |||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | # Add the results to a list, taking into account | ||||||||||||||||||||||||||||||||||||||||||
| 452 | # duplicates for the same time as well as the periodic | ||||||||||||||||||||||||||||||||||||||||||
| 453 | # requirements | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 31 | ▶ | sub _addToPeriodicList { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_addToPeriodicList: called CC=8 SCAR=22.4
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 31 | my ($list, $period, $time, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 31 | my $adjustedTime; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 31 | ▶ | if ($period) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | $adjustedTime = (int($time/$period)+1)*$period; | |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 31 | $adjustedTime = $time; | |||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 31 | my $lastIdx = scalar(@{$list})-1; | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 31 | ▶ | if ($lastIdx >= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 25 | ▶ | if ($list->[$lastIdx][1] == $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||
| 471 | ▶ | elsif ($lastIdx >= 0 && $list->[$lastIdx][0] == $adjustedTime) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$lastIdx >= 0 and $list->[$lastIdx][0] == $adjustedTime
MC/DC50%1/2
$lastIdx >= 0 and $list->[$lastIdx][0] == $adjustedTime
$lastIdx >= 0
$list->[$lastIdx][0] == $adjustedTime
Truth table66%2/3
A and B
A= $lastIdx >= 0B= $list->[$lastIdx][0] == $adjustedTime
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | # The penultimate entry on the list may already have this value | ||||||||||||||||||||||||||||||||||||||||||
| 473 | # don't put it on if it is the same | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 5 | ▶ | if ($lastIdx >= 1 && $list->[$lastIdx-1][1] == $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$lastIdx >= 1 and $$list[$lastIdx - 1][1] == $value
MC/DC0%0/2
$lastIdx >= 1 and $$list[$lastIdx - 1][1] == $value
$lastIdx >= 1
$$list[$lastIdx - 1][1] == $value
Truth table33%1/3
A and B
A= $lastIdx >= 1B= $$list[$lastIdx - 1][1] == $value
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 5 | pop(@{$list}); | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | $list->[$lastIdx] = [$adjustedTime, $value]; | |||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 26 | $list->[$lastIdx+1] = [$adjustedTime, $value]; | |||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | # Returns the index of the last value that is equal to the search | ||||||||||||||||||||||||||||||||||||||||||
| 490 | # value or the first value that is greater. | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 16 | ▶ | sub _binarySearch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_binarySearch: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 16 | my ($list, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 16 | my $start = 0; | |||||||||||||||||||||||||||||||||||||||||
| 495 | 16 | my $end = scalar(@{$list}) - 1; | |||||||||||||||||||||||||||||||||||||||||
| 496 | 16 | my $origEnd = $end; | |||||||||||||||||||||||||||||||||||||||||
| 497 | 16 | my $notDone = 1; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 16 | my $lastSmaller; | |||||||||||||||||||||||||||||||||||||||||
| 499 | my $lastEqual; | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 16 | ▶ | while ($notDone) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 42 | ▶ | if ($start >= $end) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 16 | $notDone = 0; | |||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 42 | my $idx = int(($end-$start)/2)+$start; | |||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 42 | ▶ | if ($list->[$idx] < $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 28 | $lastSmaller = $idx; | |||||||||||||||||||||||||||||||||||||||||
| 510 | 28 | $start = $idx+1; | |||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||
| 512 | elsif ($list->[$idx] == $value) { | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 10 | $start = $idx+1; | |||||||||||||||||||||||||||||||||||||||||
| 514 | 10 | $lastEqual = $idx; | |||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 517 | 4 | $end = $idx; | |||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 16 | ▶ | return $lastEqual if defined $lastEqual; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 6 | ▶ | return $lastSmaller if defined $lastSmaller; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | return $origEnd; | |||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 529 | __END__ | ||||||||||||||||||||||||||||||||||||||||||