| 53 | 
  | 
#include <list> | 
| 54 | 
  | 
#include <map> | 
| 55 | 
  | 
#include <utility> | 
| 56 | 
< | 
 | 
| 56 | 
> | 
#include "config.h" | 
| 57 | 
  | 
namespace oopse { | 
| 58 | 
  | 
 | 
| 59 | 
  | 
  template<typename ElemType> ElemType pow(ElemType x, int N) { | 
| 129 | 
  | 
     */ | 
| 130 | 
  | 
         | 
| 131 | 
  | 
    void setCoefficient(int exponent, const ElemType& coefficient) { | 
| 132 | 
< | 
      polyPairMap_.insert(typename PolynomialPairMap::value_type(exponent, coefficient)); | 
| 132 | 
> | 
      polyPairMap_[exponent] = coefficient; | 
| 133 | 
  | 
    } | 
| 134 | 
  | 
 | 
| 135 | 
  | 
    /** | 
| 149 | 
  | 
      } | 
| 150 | 
  | 
    } | 
| 151 | 
  | 
 | 
| 152 | 
– | 
 | 
| 152 | 
  | 
    /** | 
| 153 | 
  | 
     * Returns the coefficient associated with the given power for this Polynomial. | 
| 154 | 
  | 
     * @return the coefficient associated with the given power for this Polynomial | 
| 188 | 
  | 
      return polyPairMap_.size(); | 
| 189 | 
  | 
    } | 
| 190 | 
  | 
 | 
| 191 | 
+ | 
    PolynomialType& operator = (const PolynomialType& p) { | 
| 192 | 
+ | 
 | 
| 193 | 
+ | 
      if (this != &p)  // protect against invalid self-assignment | 
| 194 | 
+ | 
      { | 
| 195 | 
+ | 
        typename Polynomial<ElemType>::const_iterator i; | 
| 196 | 
+ | 
 | 
| 197 | 
+ | 
        polyPairMap_.clear();  // clear out the old map | 
| 198 | 
+ | 
       | 
| 199 | 
+ | 
        for (i =  p.begin(); i != p.end(); ++i) { | 
| 200 | 
+ | 
          this->setCoefficient(i->first, i->second); | 
| 201 | 
+ | 
        } | 
| 202 | 
+ | 
      } | 
| 203 | 
+ | 
      // by convention, always return *this | 
| 204 | 
+ | 
      return *this;  | 
| 205 | 
+ | 
    } | 
| 206 | 
+ | 
 | 
| 207 | 
  | 
    PolynomialType& operator += (const PolynomialType& p) { | 
| 208 | 
  | 
        typename Polynomial<ElemType>::const_iterator i; | 
| 209 | 
  | 
 | 
| 225 | 
  | 
    PolynomialType& operator *= (const PolynomialType& p) { | 
| 226 | 
  | 
    typename Polynomial<ElemType>::const_iterator i; | 
| 227 | 
  | 
    typename Polynomial<ElemType>::const_iterator j; | 
| 228 | 
< | 
     | 
| 229 | 
< | 
    for (i = this->begin(); i !=this->end(); ++i) { | 
| 228 | 
> | 
    Polynomial<ElemType> p2(*this); | 
| 229 | 
> | 
    | 
| 230 | 
> | 
    polyPairMap_.clear();  // clear out old map | 
| 231 | 
> | 
    for (i = p2.begin(); i !=p2.end(); ++i) { | 
| 232 | 
  | 
      for (j = p.begin(); j !=p.end(); ++j) { | 
| 233 | 
  | 
        this->addCoefficient( i->first + j->first, i->second * j->second); | 
| 234 | 
  | 
      } | 
| 235 | 
  | 
    } | 
| 236 | 
+ | 
    return *this; | 
| 237 | 
+ | 
    } | 
| 238 | 
  | 
 | 
| 239 | 
+ | 
    //PolynomialType& operator *= (const ElemType v) | 
| 240 | 
+ | 
    PolynomialType& operator *= (const ElemType v) { | 
| 241 | 
+ | 
    typename Polynomial<ElemType>::const_iterator i; | 
| 242 | 
+ | 
    //Polynomial<ElemType> result; | 
| 243 | 
+ | 
 | 
| 244 | 
+ | 
    for (i = this->begin(); i != this->end(); ++i) { | 
| 245 | 
+ | 
        this->setCoefficient( i->first, i->second*v); | 
| 246 | 
+ | 
    } | 
| 247 | 
+ | 
 | 
| 248 | 
  | 
    return *this; | 
| 249 | 
  | 
    } | 
| 250 | 
  | 
 | 
| 251 | 
+ | 
    PolynomialType& operator += (const ElemType v) {     | 
| 252 | 
+ | 
    this->addCoefficient( 0, v); | 
| 253 | 
+ | 
    return *this; | 
| 254 | 
+ | 
    } | 
| 255 | 
  | 
    | 
| 256 | 
  | 
  private: | 
| 257 | 
  | 
         | 
| 284 | 
  | 
    Polynomial<ElemType> result; | 
| 285 | 
  | 
     | 
| 286 | 
  | 
    for (i = p.begin(); i !=p.end(); ++i) { | 
| 287 | 
< | 
        result.addCoefficient( i->first , i->second * v); | 
| 287 | 
> | 
        result.setCoefficient( i->first , i->second * v); | 
| 288 | 
  | 
    } | 
| 289 | 
  | 
 | 
| 290 | 
  | 
    return result; | 
| 296 | 
  | 
    Polynomial<ElemType> result; | 
| 297 | 
  | 
     | 
| 298 | 
  | 
    for (i = p.begin(); i !=p.end(); ++i) { | 
| 299 | 
< | 
        result.addCoefficient( i->first , i->second * v); | 
| 299 | 
> | 
        result.setCoefficient( i->first , i->second * v); | 
| 300 | 
  | 
    } | 
| 301 | 
  | 
 | 
| 302 | 
  | 
    return result; | 
| 367 | 
  | 
    return true; | 
| 368 | 
  | 
  } | 
| 369 | 
  | 
 | 
| 370 | 
< | 
  typedef Polynomial<double> DoublePolynomial; | 
| 370 | 
> | 
  typedef Polynomial<RealType> DoublePolynomial; | 
| 371 | 
  | 
 | 
| 372 | 
  | 
} //end namespace oopse | 
| 373 | 
  | 
#endif //MATH_POLYNOMIAL_HPP |