| 1 | # Copyright 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::IteratePred; | ||||||||||
| 19 | 4 | ▶ | use 5.004; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 4 | ▶ | use List::Util 'max'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 4 | ▶ | use vars '$VERSION'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 4 | $VERSION = 75; | |||||||||
| 25 | |||||||||||
| 26 | # uncomment this to run the ### lines | ||||||||||
| 27 | # use Smart::Comments; | ||||||||||
| 28 | |||||||||||
| 29 | 4 | ▶ | use constant characteristic_increasing => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 4 | ▶ | use constant characteristic_integer => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 4 | ▶ | use constant characteristic_smaller => 0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | 29 | ▶ | sub rewind { | ||||||||
|
Subroutine
rewind: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 34 | 29 | my ($self) = @_; | |||||||||
| 35 | ### IteratePred rewind() ... | ||||||||||
| 36 | |||||||||||
| 37 | 29 | $self->{'i'} = $self->i_start; | |||||||||
| 38 | 29 | my $value = $self->values_min; | |||||||||
| 39 | 29 | ▶ | if (! defined $value) { die "Oops, no values_min() for predicate start"; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 28 | $self->{'value'} = $value; | |||||||||
| 41 | |||||||||||
| 42 | ### i: $self->{'i'} | ||||||||||
| 43 | ### $value | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 202 | ▶ | sub next { | ||||||||
|
Subroutine
next: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 47 | 202 | my ($self) = @_; | |||||||||
| 48 | ### IteratePred next() at value: $self->{'value'} | ||||||||||
| 49 | |||||||||||
| 50 | 202 | for (my $value = $self->{'value'}; ; $value++) { | |||||||||
| 51 | 1110 | ▶ | if ($self->pred($value)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 202 | $self->{'value'} = $value+1; | |||||||||
| 53 | 202 | return ($self->{'i'}++, $value); | |||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | # Would have to scan all values to find correct i. | ||||||||||
| 59 | # sub seek_to_value { | ||||||||||
| 60 | # my ($self, $value) = @_; | ||||||||||
| 61 | # $value = int($value); | ||||||||||
| 62 | # $self->{'value'} = max ($value, $self->values_min); | ||||||||||
| 63 | # $self->{'i'} = ... | ||||||||||
| 64 | # } | ||||||||||
| 65 | |||||||||||
| 66 | # Slow to scan through all values. | ||||||||||
| 67 | # sub ith { | ||||||||||
| 68 | # my ($self, $i) = @_; | ||||||||||
| 69 | # $i -= $self->i_start; | ||||||||||
| 70 | # my $value = $self->value_min - 1; | ||||||||||
| 71 | # while ($i >= 0) { | ||||||||||
| 72 | # $value++; | ||||||||||
| 73 | # if ($self->pred($value)) { | ||||||||||
| 74 | # $i--; | ||||||||||
| 75 | # } | ||||||||||
| 76 | # } | ||||||||||
| 77 | # return $value; | ||||||||||
| 78 | # } | ||||||||||
| 79 | |||||||||||
| 80 | |||||||||||
| 81 | 4 | 1; | |||||||||
| 82 | __END__ | ||||||||||