ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/math/Polynomial.hpp
(Generate patch)

Comparing trunk/src/math/Polynomial.hpp (file contents):
Revision 963 by tim, Wed May 17 21:51:42 2006 UTC vs.
Revision 1290 by cli2, Wed Sep 10 19:51:45 2008 UTC

# Line 129 | Line 129 | namespace oopse {
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      /**
# Line 149 | Line 149 | namespace oopse {
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
# Line 189 | Line 188 | namespace oopse {
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  
# Line 210 | Line 225 | namespace oopse {
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          
# Line 252 | Line 284 | namespace oopse {
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;
# Line 264 | Line 296 | namespace oopse {
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines