74 |
|
class Polynomial { |
75 |
|
|
76 |
|
public: |
77 |
< |
|
77 |
> |
typedef Polynomial<ElemType> PolynomialType; |
78 |
|
typedef int ExponentType; |
79 |
|
typedef ElemType CoefficientType; |
80 |
|
typedef std::map<ExponentType, CoefficientType> PolynomialPairMap; |
81 |
|
typedef typename PolynomialPairMap::iterator iterator; |
82 |
|
typedef typename PolynomialPairMap::const_iterator const_iterator; |
83 |
+ |
|
84 |
+ |
Polynomial() {} |
85 |
+ |
Polynomial(ElemType v) {setCoefficient(0, v);} |
86 |
|
/** |
87 |
|
* Calculates the value of this Polynomial evaluated at the given x value. |
88 |
|
* @return The value of this Polynomial evaluates at the given x value |
188 |
|
size_t size() { |
189 |
|
return polyPairMap_.size(); |
190 |
|
} |
191 |
< |
|
191 |
> |
|
192 |
> |
PolynomialType& operator += (const PolynomialType& p) { |
193 |
> |
typename Polynomial<ElemType>::const_iterator i; |
194 |
> |
|
195 |
> |
for (i = p.begin(); i != p.end(); ++i) { |
196 |
> |
this->addCoefficient(i->first, i->second); |
197 |
> |
} |
198 |
> |
|
199 |
> |
return *this; |
200 |
> |
} |
201 |
> |
|
202 |
> |
PolynomialType& operator -= (const PolynomialType& p) { |
203 |
> |
typename Polynomial<ElemType>::const_iterator i; |
204 |
> |
for (i = p.begin(); i != p.end(); ++i) { |
205 |
> |
this->addCoefficient(i->first, -i->second); |
206 |
> |
} |
207 |
> |
} |
208 |
> |
|
209 |
> |
PolynomialType& operator *= (const PolynomialType& p) { |
210 |
> |
typename Polynomial<ElemType>::const_iterator i; |
211 |
> |
typename Polynomial<ElemType>::const_iterator j; |
212 |
> |
|
213 |
> |
for (i = this->begin(); i !=this->end(); ++i) { |
214 |
> |
for (j = p.begin(); j !=p.end(); ++j) { |
215 |
> |
this->addCoefficient( i->first + j->first, i->second * j->second); |
216 |
> |
} |
217 |
> |
} |
218 |
> |
|
219 |
> |
return *this; |
220 |
> |
} |
221 |
> |
|
222 |
> |
|
223 |
|
private: |
224 |
|
|
225 |
|
PolynomialPairMap polyPairMap_; |