Loading...
Searching...
No Matches
DegreePattern.h
Go to the documentation of this file.
/*****************************************************************************\
* Computer Algebra System SINGULAR
\*****************************************************************************/
/** @file DegreePattern.h
*
* This file provides a class to handle degree patterns.
*
* @author Martin Lee
*
**/
/*****************************************************************************/
#ifndef DEGREE_PATTERN_H
#define DEGREE_PATTERN_H
// #include "config.h"
#include "cf_assert.h"
#include "canonicalform.h"
#include "cf_iter.h"
#include "templates/ftmpl_functions.h"
#include "gfops.h"
/** @class DegreePattern DegreePattern.h "factory/DegreePattern.h"
*
* DegreePattern provides a functionality to create, intersect and refine
* degree patterns.
*
*
*/
class DegreePattern
{
private:
struct Pattern
{
int m_refCounter; ///< reference counter
int m_length; ///< length of m_pattern
int* m_pattern; ///< some array containing the degree pattern
/// construct a Pattern from an int
Pattern(int n): m_refCounter(1), m_length(n), m_pattern( new int[n]) {};
/// default constructor
Pattern(): m_refCounter(1), m_length(0), m_pattern(NULL) {};
}* m_data;
/// clear m_data
void release()
{
ASSERT ( m_data != NULL, "non-null pointer expected");
ASSERT ( m_data->m_refCounter == 0, "ref count of 0 expected");
if( m_data->m_pattern != NULL )
delete[] m_data->m_pattern;
m_data->m_pattern = NULL;
delete m_data;
m_data = NULL;
}
/// initialise a DegreePattern
void init( int n )
{
ASSERT ( m_data != NULL, "non-null pointer expected" );
ASSERT( m_data->m_refCounter > 0, "ref count > 0 expected" );
if( (--m_data->m_refCounter) < 1 )
release();
m_data = new Pattern(n);
}
/// getter
///
/// @return @a getPattern returns a degree pattern
inline int* getPattern() const
{
ASSERT( m_data != NULL, "non-null pointer expected" );
ASSERT( m_data->m_pattern != NULL, "non-null pointer expected" );
return m_data->m_pattern;
}
public:
/// getter
///
/// @return @a getLength returns the length of the degree pattern
inline int getLength() const
{
ASSERT( m_data != NULL, "non-null pointer expected" );
return m_data->m_length;
}
/// operator []
///
/// @return @a operator[] returns the element at @a index
inline int operator[] (const int index ///< [in] some int >= 0, < getLength()
) const
{
ASSERT( m_data != NULL, "non-null pointer expected" );
ASSERT( index >= 0 && index < getLength(), "bad index" );
ASSERT( getPattern() != NULL, "non-null pointer expected" );
return getPattern()[index];
}
/// operator []
///
/// @return @a operator[] sets the element at @a index
inline int& operator[] (const int index ///< [in] some int >= 0, < getLength()
)
{
ASSERT( m_data != NULL, "non-null pointer expected" );
ASSERT( index >= 0 && index < getLength(), "bad index" );
ASSERT( getPattern() != NULL, "non-null pointer expected" );
return getPattern()[index];
}
/// default constructor
DegreePattern(): m_data( new Pattern() ){}
/// copy constructor
DegreePattern (const DegreePattern& degPat ///< [in] some degree pattern
): m_data( degPat.m_data )
{
ASSERT( degPat.m_data != NULL, "non-null pointer expected" );
m_data->m_refCounter++;
};
/// construct a degree pattern from a list of (univariate) polys
DegreePattern (const CFList& l ///< [in] some list of (univariate) polys
);
/// assignment
DegreePattern& operator= (const DegreePattern& degPat ///< [in] some degree
///< pattern
)
{
ASSERT( m_data != NULL, "non-null pointer expected" );
ASSERT( degPat.m_data != NULL, "non-null pointer expected" );
if( m_data != degPat.m_data )
{
m_data = degPat.m_data;
m_data->m_refCounter++;
}
return *this;
}
/// destructor
~DegreePattern ()
{
ASSERT( m_data != NULL, "non-null pointer expected" );
if( (--m_data->m_refCounter) < 1 )
release();
}
/// find an element @a x
///
/// @return @a find returns the index + 1 of @a x, if @a x is an element of
/// the degree pattern, 0 otherwise
int find (const int x ///< [in] some int
) const
{
if (getLength() == 0) return 0;
for (int i= 0; i < getLength(); i++)
if ((*this)[i] == x) return i + 1;
return 0;
};
/// intersect two degree patterns
void intersect (const DegreePattern& degPat ///< [in] some degree pattern
);
/// Refine a degree pattern. Assumes that (*this)[0]:= @a d is the degree
/// of the poly to be factored. Now for every other entry @a a there should be
/// some entry @a b such that @a a+b= d. Elements which do not satisfy this
/// relation are removed.
void refine ();
};
#endif
/* DEGREE_PATTERN_H */
canonicalform.h
Header for factory's main class CanonicalForm.
CFList
List< CanonicalForm > CFList
Definition canonicalform.h:395
l
int l
Definition cfEzgcd.cc:100
i
int i
Definition cfEzgcd.cc:132
x
Variable x
Definition cfModGcd.cc:4090
cf_assert.h
assertions for Factory
ASSERT
#define ASSERT(expression, message)
Definition cf_assert.h:99
cf_iter.h
Iterators for CanonicalForm's.
DegreePattern
DegreePattern provides a functionality to create, intersect and refine degree patterns.
Definition DegreePattern.h:32
DegreePattern::m_data
struct DegreePattern::Pattern * m_data
DegreePattern::operator=
DegreePattern & operator=(const DegreePattern &degPat)
assignment
Definition DegreePattern.h:132
DegreePattern::release
void release()
clear m_data
Definition DegreePattern.h:48
DegreePattern::~DegreePattern
~DegreePattern()
destructor
Definition DegreePattern.h:148
DegreePattern::find
int find(const int x) const
find an element x
Definition DegreePattern.h:159
DegreePattern::intersect
void intersect(const DegreePattern &degPat)
intersect two degree patterns
Definition DegreePattern.cc:68
DegreePattern::getLength
int getLength() const
getter
Definition DegreePattern.h:86
DegreePattern::DegreePattern
DegreePattern(const DegreePattern &degPat)
copy constructor
Definition DegreePattern.h:120
DegreePattern::getPattern
int * getPattern() const
getter
Definition DegreePattern.h:74
DegreePattern::refine
void refine()
Refine a degree pattern. Assumes that (*this)[0]:= d is the degree of the poly to be factored....
Definition DegreePattern.cc:105
DegreePattern::init
void init(int n)
initialise a DegreePattern
Definition DegreePattern.h:60
DegreePattern::operator[]
int operator[](const int index) const
operator []
Definition DegreePattern.h:95
DegreePattern::DegreePattern
DegreePattern()
default constructor
Definition DegreePattern.h:117
ftmpl_functions.h
some useful template functions.
gfops.h
Operations in GF, where GF is a finite field of size less than 2^16 represented by a root of Conway p...
NULL
#define NULL
Definition omList.c:12
index
static int index(p_Length length, p_Ord ord)
Definition p_Procs_Impl.h:592
DegreePattern::Pattern
Definition DegreePattern.h:35
DegreePattern::Pattern::m_refCounter
int m_refCounter
reference counter
Definition DegreePattern.h:36
DegreePattern::Pattern::m_pattern
int * m_pattern
some array containing the degree pattern
Definition DegreePattern.h:38
DegreePattern::Pattern::Pattern
Pattern()
default constructor
Definition DegreePattern.h:43
DegreePattern::Pattern::m_length
int m_length
length of m_pattern
Definition DegreePattern.h:37
DegreePattern::Pattern::Pattern
Pattern(int n)
construct a Pattern from an int
Definition DegreePattern.h:41