synaps/mpol/sequence_mon.h

00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS kernel.        *
00003 *      Author(s): B. Mourrain, GALAAD, INRIA                         *
00004 **********************************************************************
00005 $Id: sequence_mon.h,v 1.1 2005/07/11 11:17:56 mourrain Exp $
00006 **********************************************************************/
00007 #ifndef SYNAPS_MPOL_LISTMONOM_H
00008 #define SYNAPS_MPOL_LISTMONOM_H
00009 
00010 #include <list>
00011 #include <vector>
00012 #include <synaps/init.h>
00013 #include <synaps/arithm/GENERIC.h>
00014 
00015 
00016 __BEGIN_NAMESPACE_SYNAPS
00017 
00018 //----------------------------------------------------------------------------
00019 // Representation des polynomes par des listes tries par monomes decroissants.
00020 //----------------------------------------------------------------------------
00021 // template <class M>  inline
00022 // bool IsNull (const list<M> & l) {
00023 //   if (l.empty()) return true;
00024 //   else return (IsNull((l.begin()->GetCoeff())));
00025 // }
00026 
00027 // //template <class M> vector;
00028 // template <class M>  inline
00029 // bool IsNull (const vector<M> & l) {
00030 //   if (l.empty()) return true;
00031 //   else return (IsNull((l.begin()->GetCoeff())));
00032 // }
00033 
00034 // template <class M>  inline
00035 // bool operator == (const list<M > & l, ZERO z ) {
00036 //   if (l.empty()) return true;
00037 //   else return (IsNull((l.begin()->GetCoeff())));
00038 // }
00039 //template <class R,class S> inline
00040 //bool IsNull (const list<MPol<R,S> > & l) {
00041 //   if (l.empty()) return true;
00042 //   else return (IsNull((l.begin()->GetCoeff())));
00043 // }
00044 //{ return (l.empty() || (IsNull((l.begin()->GetCoeff()))));}
00045 
00046 // template <class M> inline
00047 // void build (list<M > & p, const M & m)       { p.push_back(m); }
00048 
00049 // template<class T> inline 
00050 // void copy  (T & p, const T & q) 
00051 // {
00052 //   if (&p==&q) return;
00053 //   p.erase(p.begin(),p.end());
00054 //   typename T::const_iterator iter;
00055 //   for(iter=q.begin();iter!=q.end();iter++)
00056 //     p.push_back(*iter);
00057 // }
00058 //p = r; }
00059 
00060 template<class R> inline
00061 typename R::iterator insert (R & p, 
00062                              typename R::iterator i, 
00063                              const typename R::value_type & m) 
00064 {
00065   p.insert(i,m); return p.begin();
00066 }
00067 
00068 template<class M> inline
00069 typename list<M>::iterator insert (list<M> & p, 
00070                              typename list<M>::iterator i, 
00071                              const M & m) 
00072 {
00073   p.insert(i,m); return i;
00074 }
00075 template <class R, class O>
00076 typename R::iterator addition (R & p, 
00077                                typename R::iterator i, 
00078                                const typename R::value_type & m) {
00079   
00080   //  typename R::iterator it;
00081   if (p.empty())
00082     {
00083       p.push_back(m);
00084       return p.begin();
00085     }
00086   for (; i != p.end(); i++)
00087     {
00088       if (O::less(*i,m)) // *i plus petit que m on insere
00089         {
00090           // Inserting a new monomial
00091           p.insert(i,m);//swap((*--i),(*m));
00092           i=find(p.begin(),p.end(),m);return i;
00093           //return insert(p,i,m);
00094         }
00095       else if (O::less(m, *i)) ;
00096         // *i plus grand que m on incremente
00097       else                       
00098         // m et *i sont comparables on ajoute les monomes
00099         {
00100           *i += m;
00101           if (i->GetCoeff()==0) {
00102             typename R::iterator aux = i++;
00103             i=p.erase(aux);
00104           }
00105           return i;
00106         }
00107     }
00108   
00109   // The for loop reaches its end;
00110   p.push_back(m);i=p.end();
00111   return (--i); //xxx p.begin();
00112 }
00113 
00114 __END_NAMESPACE_SYNAPS
00115 
00116 #endif // SYNAPS_MPOL_LISTMONOM_H
00117 

SYNAPS DOCUMENTATION
logo