line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2011, 2012, 2013, 2014 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 . |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Math::NumSeq::Base::IteratePred; |
19
|
4
|
|
|
4
|
|
58
|
use 5.004; |
|
4
|
|
|
|
|
11
|
|
20
|
4
|
|
|
4
|
|
14
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
91
|
|
21
|
4
|
|
|
4
|
|
15
|
use List::Util 'max'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
282
|
|
22
|
|
|
|
|
|
|
|
23
|
4
|
|
|
4
|
|
20
|
use vars '$VERSION'; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
169
|
|
24
|
|
|
|
|
|
|
$VERSION = 72; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
27
|
|
|
|
|
|
|
# use Smart::Comments; |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
4
|
|
16
|
use constant characteristic_increasing => 1; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
243
|
|
30
|
4
|
|
|
4
|
|
27
|
use constant characteristic_integer => 1; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
165
|
|
31
|
4
|
|
|
4
|
|
16
|
use constant characteristic_smaller => 0; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
692
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub rewind { |
34
|
29
|
|
|
29
|
0
|
3552
|
my ($self) = @_; |
35
|
|
|
|
|
|
|
### IteratePred rewind() ... |
36
|
|
|
|
|
|
|
|
37
|
29
|
|
|
|
|
122
|
$self->{'i'} = $self->i_start; |
38
|
29
|
|
|
|
|
73
|
my $value = $self->values_min; |
39
|
29
|
100
|
|
|
|
179
|
if (! defined $value) { die "Oops, no values_min() for predicate start"; } |
|
1
|
|
|
|
|
7
|
|
40
|
28
|
|
|
|
|
76
|
$self->{'value'} = $value; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
### i: $self->{'i'} |
43
|
|
|
|
|
|
|
### $value |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub next { |
47
|
202
|
|
|
202
|
0
|
3014
|
my ($self) = @_; |
48
|
|
|
|
|
|
|
### IteratePred next() at value: $self->{'value'} |
49
|
|
|
|
|
|
|
|
50
|
202
|
|
|
|
|
208
|
for (my $value = $self->{'value'}; ; $value++) { |
51
|
1110
|
100
|
|
|
|
1496
|
if ($self->pred($value)) { |
52
|
202
|
|
|
|
|
193
|
$self->{'value'} = $value+1; |
53
|
202
|
|
|
|
|
277
|
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
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
__END__ |