NumSeq/Base/Sparse.pm

filter: Statementstmt 95.2% 40 / 42 Branchbran 75.0% 6 / 8 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 90.2% 65 / 72 CC 7 SCAR 8.6
CC
7
Cov
91%
pred
4.1
ith
3.1
_extend
2.0
CRAP 2.4
« NumSeq/Modulo.pm ↑ Summary NumSeq/SternDiatomic.pm »
1 # Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde
2  
3 # This file is part of Math-NumSeq.
4 #
5 # Math-NumSeq is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # Math-NumSeq is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Math::NumSeq::Base::Sparse;
19 30 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 30 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 30 $VERSION = 75;
24 30 ▶use Math::NumSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 30 @ISA = ('Math::NumSeq');
26 30 *_is_infinite = \&Math::NumSeq::_is_infinite;
27  
28 # uncomment this to run the ### lines
29 #use Smart::Comments;
30  
31  
32 30 ▶use constant characteristic_sparse => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 27 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
35 27 my $class = shift;
36 ### Sparse new() ...
37 27 return $class->SUPER::new (pred_array => [],
38 pred_hash => {},
39 pred_value => -1,
40 @_);
41 }
42 66 ▶sub ith {
Subroutine ith: called CC=3 SCAR=11.2
Pod documented
43 66 my ($self, $i) = @_;
44  
45 66 ▶ if (_is_infinite($i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_infinite($i)) 0 66 66
46 0 return $i;
47 }
48  
49 ### pred_array last: $#{$self->{'pred_array'}}
50 66 ▶ while ($#{$self->{'pred_array'}} < $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$$self{"pred_array"};} < $i) 204 66 270
51 204 _extend ($self);
52 }
53 ### pred_array: $self->{'pred_array'}
54 66 return $self->{'pred_array'}->[$i];
55 }
56  
57 4087 ▶sub pred {
Subroutine pred: called CC=4 SCAR=14.0
Pod documented
58 4087 my ($self, $value) = @_;
59 ### Sparse pred(): $value
60 4087 ▶ if (_is_infinite($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_infinite($value)) 0 4087 4087
61 0 return 0;
62 }
63 4087 ▶ while ($self->{'pred_value'} < $value
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pred_value"} < $value or $self->{"pred_value"} < 10) 64 4087 4151
Condition100%3/3
$self->{"pred_value"} < $value or $self->{"pred_value"} < 10
l!l&&r!l&&!r
45194087
MC/DC100%2/2
$self->{"pred_value"} < $value or $self->{"pred_value"} < 10
$self->{"pred_value"} < $value $self->{"pred_value"} < 10
Truth table100%3/3
A or B
A= $self->{"pred_value"} < $valueB= $self->{"pred_value"} < 10
ABresult
1X1
011
000
64 || $self->{'pred_value'} < 10) {
65 64 _extend ($self);
66 }
67 ### pred_hash: $self->{'pred_hash'}
68 ### Sparse pred result: exists($self->{'pred_hash'}->{$value})
69 4087 return exists($self->{'pred_hash'}->{$value});
70 }
71  
72 268 ▶sub _extend {
Subroutine _extend: called CC=2 SCAR=6.9
73 268 my ($self) = @_;
74 ### Sparse _extend()
75 268 ▶ my $iter = ($self->{'pred_iter'} ||= do {
Condition66%2/3
$self->{"pred_iter"} ||= do { my $class = ref $self; my $it = $class->new(%$self); $it }
l!l&&r!l&&!r
26260
MC/DC0%0/2
$self->{"pred_iter"} ||= do { my $class = ref $self; my $it = $class->new(%$self); $it }
$self->{"pred_iter"} do { my $class = ref $self; my $it = $class->new(%$self); $it }
Truth table66%2/3
A ||= B
A= $self->{"pred_iter"}B= do { my $class = ref $self; my $it = $class->new(%$self); $it }
ABresult
1X1
011
000
76 ### Sparse create pred_iter
77 6 my $class = ref $self;
78 6 my $it = $class->new (%$self);
79 # while ($self->{'pred_value'} < 10) {
80 # my ($i, $pred_value) = $it->next;
81 # $self->{'pred_hash'}->{$self->{'pred_value'}=$pred_value} = undef;
82 # }
83 # ### $it
84 6 $it
85 });
86 268 my ($i, $value) = $iter->next;
87 ### $i
88 ### $value
89 268 $self->{'pred_value'} = $value;
90 268 $self->{'pred_array'}->[$i - $self->i_start] = $value;
91 268 $self->{'pred_hash'}->{$value} = undef;
92 }
93  
94 30 1;
95 __END__
« NumSeq/Modulo.pm ↑ Summary NumSeq/SternDiatomic.pm »