My Project
Loading...
Searching...
No Matches
DegreePattern.h
Go to the documentation of this file.
1/*****************************************************************************\
2 * Computer Algebra System SINGULAR
3\*****************************************************************************/
4/** @file DegreePattern.h
5 *
6 * This file provides a class to handle degree patterns.
7 *
8 * @author Martin Lee
9 *
10 **/
11/*****************************************************************************/
12#ifndef DEGREE_PATTERN_H
13#define DEGREE_PATTERN_H
14
15// #include "config.h"
16
17#include "cf_assert.h"
18
19#include "canonicalform.h"
20#include "cf_iter.h"
22#include "gfops.h"
23
24/** @class DegreePattern DegreePattern.h "factory/DegreePattern.h"
25 *
26 * DegreePattern provides a functionality to create, intersect and refine
27 * degree patterns.
28 *
29 *
30 */
32{
33private:
34 struct Pattern
35 {
36 int m_refCounter; ///< reference counter
37 int m_length; ///< length of m_pattern
38 int* m_pattern; ///< some array containing the degree pattern
39
40 /// construct a Pattern from an int
41 Pattern(int n): m_refCounter(1), m_length(n), m_pattern( new int[n]) {};
42 /// default constructor
44
46
47 /// clear m_data
48 void release()
49 {
50 ASSERT ( m_data != NULL, "non-null pointer expected");
51 ASSERT ( m_data->m_refCounter == 0, "ref count of 0 expected");
52 if( m_data->m_pattern != NULL )
53 delete[] m_data->m_pattern;
55
56 delete m_data;
57 m_data = NULL;
58 }
59 /// initialise a DegreePattern
60 void init( int n )
61 {
62 ASSERT ( m_data != NULL, "non-null pointer expected" );
63 ASSERT( m_data->m_refCounter > 0, "ref count > 0 expected" );
64
65 if( (--m_data->m_refCounter) < 1 )
66 release();
67
68 m_data = new Pattern(n);
69 }
70
71 /// getter
72 ///
73 /// @return @a getPattern returns a degree pattern
74 inline int* getPattern() const
75 {
76 ASSERT( m_data != NULL, "non-null pointer expected" );
77 ASSERT( m_data->m_pattern != NULL, "non-null pointer expected" );
78 return m_data->m_pattern;
79 }
80
81
82public:
83 /// getter
84 ///
85 /// @return @a getLength returns the length of the degree pattern
86 inline int getLength() const
87 {
88 ASSERT( m_data != NULL, "non-null pointer expected" );
89 return m_data->m_length;
90 }
91
92 /// operator []
93 ///
94 /// @return @a operator[] returns the element at @a index
95 inline int operator[] (const int index ///< [in] some int >= 0, < getLength()
96 ) const
97 {
98 ASSERT( m_data != NULL, "non-null pointer expected" );
99 ASSERT( index >= 0 && index < getLength(), "bad index" );
100 ASSERT( getPattern() != NULL, "non-null pointer expected" );
101 return getPattern()[index];
102 }
103
104 /// operator []
105 ///
106 /// @return @a operator[] sets the element at @a index
107 inline int& operator[] (const int index ///< [in] some int >= 0, < getLength()
108 )
109 {
110 ASSERT( m_data != NULL, "non-null pointer expected" );
111 ASSERT( index >= 0 && index < getLength(), "bad index" );
112 ASSERT( getPattern() != NULL, "non-null pointer expected" );
113 return getPattern()[index];
114 }
115
116 /// default constructor
118
119 /// copy constructor
120 DegreePattern (const DegreePattern& degPat ///< [in] some degree pattern
121 ): m_data( degPat.m_data )
122 {
123 ASSERT( degPat.m_data != NULL, "non-null pointer expected" );
125 };
126
127 /// construct a degree pattern from a list of (univariate) polys
128 DegreePattern (const CFList& l ///< [in] some list of (univariate) polys
129 );
130
131 /// assignment
132 DegreePattern& operator= (const DegreePattern& degPat ///< [in] some degree
133 ///< pattern
134 )
135 {
136 ASSERT( m_data != NULL, "non-null pointer expected" );
137 ASSERT( degPat.m_data != NULL, "non-null pointer expected" );
138 if( m_data != degPat.m_data )
139 {
140 m_data = degPat.m_data;
142 }
143
144 return *this;
145 }
146
147 /// destructor
149 {
150 ASSERT( m_data != NULL, "non-null pointer expected" );
151 if( (--m_data->m_refCounter) < 1 )
152 release();
153 }
154
155 /// find an element @a x
156 ///
157 /// @return @a find returns the index + 1 of @a x, if @a x is an element of
158 /// the degree pattern, 0 otherwise
159 int find (const int x ///< [in] some int
160 ) const
161 {
162 if (getLength() == 0) return 0;
163 for (int i= 0; i < getLength(); i++)
164 if ((*this)[i] == x) return i + 1;
165 return 0;
166 };
167
168 /// intersect two degree patterns
169 void intersect (const DegreePattern& degPat ///< [in] some degree pattern
170 );
171 /// Refine a degree pattern. Assumes that (*this)[0]:= @a d is the degree
172 /// of the poly to be factored. Now for every other entry @a a there should be
173 /// some entry @a b such that @a a+b= d. Elements which do not satisfy this
174 /// relation are removed.
175 void refine ();
176};
177
178#endif
179/* DEGREE_PATTERN_H */
180
Header for factory's main class CanonicalForm.
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
Variable x
Definition: cfModGcd.cc:4082
assertions for Factory
#define ASSERT(expression, message)
Definition: cf_assert.h:99
Iterators for CanonicalForm's.
DegreePattern provides a functionality to create, intersect and refine degree patterns.
Definition: DegreePattern.h:32
struct DegreePattern::Pattern * m_data
DegreePattern & operator=(const DegreePattern &degPat)
assignment
void release()
clear m_data
Definition: DegreePattern.h:48
~DegreePattern()
destructor
int find(const int x) const
find an element x
void intersect(const DegreePattern &degPat)
intersect two degree patterns
int getLength() const
getter
Definition: DegreePattern.h:86
DegreePattern(const DegreePattern &degPat)
copy constructor
int * getPattern() const
getter
Definition: DegreePattern.h:74
void refine()
Refine a degree pattern. Assumes that (*this)[0]:= d is the degree of the poly to be factored....
void init(int n)
initialise a DegreePattern
Definition: DegreePattern.h:60
int operator[](const int index) const
operator []
Definition: DegreePattern.h:95
DegreePattern()
default constructor
some useful template functions.
Operations in GF, where GF is a finite field of size less than 2^16 represented by a root of Conway p...
#define NULL
Definition: omList.c:12
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
int m_refCounter
reference counter
Definition: DegreePattern.h:36
int * m_pattern
some array containing the degree pattern
Definition: DegreePattern.h:38
Pattern()
default constructor
Definition: DegreePattern.h:43
int m_length
length of m_pattern
Definition: DegreePattern.h:37
Pattern(int n)
construct a Pattern from an int
Definition: DegreePattern.h:41