My Project
Loading...
Searching...
No Matches
fac_iterfor.cc
Go to the documentation of this file.
1/* emacs edit mode for this file is -*- C++ -*- */
2
3
4#include "config.h"
5
6
7#include "cf_assert.h"
8
9#include "cf_defs.h"
10#include "fac_iterfor.h"
11
12#ifndef HAVE_NTL
13
14void
15IteratedFor::fill ( int from, int max )
16{
17 while ( from < N ) {
18 imax[from] = max;
19 index[from] = 0;
20 from++;
21 }
22 index[N] = max;
23}
24
25IteratedFor::IteratedFor( int from, int to, int max ) : MAX( max ), FROM( from ), TO( to ), N( TO-FROM ), last( false )
26{
27 ASSERT( N >= 0 && max >= 0, "illegal iterated for" );
28 index = new int[N+1];
29 imax = new int[N+1];
30 fill( 0, max );
31}
32
33IteratedFor::IteratedFor( const IteratedFor & I ) : MAX( I.MAX ), FROM( I.FROM ), TO( I.TO ), N( I.N ), last( I.last )
34{
35 index = new int[N+1];
36 imax = new int[N+1];
37 for ( int i = 0; i <= N; i++ ) {
38 index[i] = I.index[i];
39 imax[i] = I.imax[i];
40 }
41}
42
44{
45 delete [] index;
46 delete [] imax;
47}
48
51{
52 if ( this != &I ) {
53 if ( N != I.N ) {
54 N = I.N;
55 delete [] index;
56 delete [] imax;
57 index = new int[N+1];
58 imax = new int[N+1];
59 }
60 FROM = I.FROM;
61 TO = I.TO;
62 MAX = I.MAX;
63 last = I.last;
64 for ( int i = 0; i<= N; i++ ) {
65 index[i] = I.index[i];
66 imax[i] = I.imax[i];
67 }
68 }
69 return *this;
70}
71
72void
74{
75 ASSERT( ! last, "no more iterations" );
76 if ( index[0] == MAX )
77 last = true;
78 else {
79 if ( index[N-1] != imax[N-1] ) {
80 index[N-1]++;
81 index[N]--;
82 }
83 else {
84 int i = N-1, m = index[N];
85 while ( i > 0 && index[i] == imax[i] ) {
86 m += imax[i];
87 i--;
88 }
89 index[i]++; m--;
90 fill( i+1, m );
91 }
92 }
93}
94
95int
96IteratedFor::operator[] ( int i ) const
97{
98 ASSERT( i >= FROM && i <= TO, "illegal index" );
99 return index[i-FROM];
100}
101
102#ifndef NOSTREAMIO
103OSTREAM& operator<< ( OSTREAM& os, const IteratedFor & I )
104{
105 os << "( " << I[I.from()];
106 for ( int i = I.from()+1; i <= I.to(); i++ )
107 os << ", " << I[i];
108 os << " )";
109 return os;
110}
111#endif /* NOSTREAMIO */
112#endif
#define OSTREAM
Definition: canonicalform.h:16
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:56
int m
Definition: cfEzgcd.cc:128
int i
Definition: cfEzgcd.cc:132
return false
Definition: cfModGcd.cc:84
assertions for Factory
#define ASSERT(expression, message)
Definition: cf_assert.h:99
factory switches.
int operator[](int) const
int * imax
Definition: fac_iterfor.h:27
IteratedFor(int from, int to, int max)
void nextiteration()
int max() const
Definition: fac_iterfor.h:37
int from() const
Definition: fac_iterfor.h:34
void fill(int from, int n)
IteratedFor & operator=(const IteratedFor &)
int * index
Definition: fac_iterfor.h:26
static int max(int a, int b)
Definition: fast_mult.cc:264
STATIC_VAR poly last
Definition: hdegree.cc:1173
#define MAX(a, b)
Definition: omDebug.c:100
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
ostream & operator<<(ostream &s, const spectrum &spec)
Definition: semic.cc:249