Loading...
Searching...
No Matches
fac_iterfor.cc
Go to the documentation of this file.
/* emacs edit mode for this file is -*- C++ -*- */
#include "config.h"
#include "cf_assert.h"
#include "cf_defs.h"
#include "fac_iterfor.h"
#ifndef HAVE_NTL
void
IteratedFor::fill ( int from, int max )
{
while ( from < N ) {
imax[from] = max;
index[from] = 0;
from++;
}
index[N] = max;
}
IteratedFor::IteratedFor( int from, int to, int max ) : MAX( max ), FROM( from ), TO( to ), N( TO-FROM ), last( false )
{
ASSERT( N >= 0 && max >= 0, "illegal iterated for" );
index = new int[N+1];
imax = new int[N+1];
fill( 0, max );
}
IteratedFor::IteratedFor( const IteratedFor & I ) : MAX( I.MAX ), FROM( I.FROM ), TO( I.TO ), N( I.N ), last( I.last )
{
index = new int[N+1];
imax = new int[N+1];
for ( int i = 0; i <= N; i++ ) {
index[i] = I.index[i];
imax[i] = I.imax[i];
}
}
IteratedFor::~IteratedFor()
{
delete [] index;
delete [] imax;
}
IteratedFor&
IteratedFor::operator= ( const IteratedFor & I )
{
if ( this != &I ) {
if ( N != I.N ) {
N = I.N;
delete [] index;
delete [] imax;
index = new int[N+1];
imax = new int[N+1];
}
FROM = I.FROM;
TO = I.TO;
MAX = I.MAX;
last = I.last;
for ( int i = 0; i<= N; i++ ) {
index[i] = I.index[i];
imax[i] = I.imax[i];
}
}
return *this;
}
void
IteratedFor::nextiteration()
{
ASSERT( ! last, "no more iterations" );
if ( index[0] == MAX )
last = true;
else {
if ( index[N-1] != imax[N-1] ) {
index[N-1]++;
index[N]--;
}
else {
int i = N-1, m = index[N];
while ( i > 0 && index[i] == imax[i] ) {
m += imax[i];
i--;
}
index[i]++; m--;
fill( i+1, m );
}
}
}
int
IteratedFor::operator[] ( int i ) const
{
ASSERT( i >= FROM && i <= TO, "illegal index" );
return index[i-FROM];
}
#ifndef NOSTREAMIO
OSTREAM& operator<< ( OSTREAM& os, const IteratedFor & I )
{
os << "( " << I[I.from()];
for ( int i = I.from()+1; i <= I.to(); i++ )
os << ", " << I[i];
os << " )";
return os;
}
#endif /* NOSTREAMIO */
#endif
OSTREAM
#define OSTREAM
Definition canonicalform.h:16
N
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
m
int m
Definition cfEzgcd.cc:128
i
int i
Definition cfEzgcd.cc:132
false
return false
Definition cfModGcd.cc:85
cf_assert.h
assertions for Factory
ASSERT
#define ASSERT(expression, message)
Definition cf_assert.h:99
cf_defs.h
factory switches.
IteratedFor
Definition fac_iterfor.h:19
IteratedFor::operator[]
int operator[](int) const
IteratedFor::imax
int * imax
Definition fac_iterfor.h:27
IteratedFor::FROM
int FROM
Definition fac_iterfor.h:22
IteratedFor::TO
int TO
Definition fac_iterfor.h:23
IteratedFor::IteratedFor
IteratedFor(int from, int to, int max)
IteratedFor::nextiteration
void nextiteration()
IteratedFor::max
int max() const
Definition fac_iterfor.h:37
IteratedFor::~IteratedFor
~IteratedFor()
IteratedFor::from
int from() const
Definition fac_iterfor.h:34
IteratedFor::MAX
int MAX
Definition fac_iterfor.h:21
IteratedFor::last
bool last
Definition fac_iterfor.h:25
IteratedFor::N
int N
Definition fac_iterfor.h:24
IteratedFor::fill
void fill(int from, int n)
IteratedFor::operator=
IteratedFor & operator=(const IteratedFor &)
IteratedFor::index
int * index
Definition fac_iterfor.h:26
fac_iterfor.h
max
static int max(int a, int b)
Definition fast_mult.cc:264
last
STATIC_VAR poly last
Definition hdegree.cc:1138
MAX
#define MAX(a, b)
Definition omDebug.c:100
index
static int index(p_Length length, p_Ord ord)
Definition p_Procs_Impl.h:592
operator<<
ostream & operator<<(ostream &s, const spectrum &spec)
Definition semic.cc:249