dynamic_exp< E > Struct Template Reference

Dynamic exponent. More...

#include <dynamicexp.hpp>

List of all members.

Public Types

Public Member Functions

Static Public Member Functions

Public Attributes

Friends


Detailed Description

template<class E = int>
struct mmx::dynamic_exp< E >

Dynamic exponent.

Definition at line 25 of file dynamicexp.hpp.


Member Typedef Documentation

Definition at line 30 of file dynamicexp.hpp.

typedef std::reverse_iterator<const_iterator> const_reverse_iterator

Definition at line 31 of file dynamicexp.hpp.

typedef int degree_t

Definition at line 35 of file dynamicexp.hpp.

typedef E exponent_t

Definition at line 34 of file dynamicexp.hpp.

typedef E* iterator

Definition at line 29 of file dynamicexp.hpp.

typedef std::reverse_iterator<iterator> reverse_iterator

Definition at line 32 of file dynamicexp.hpp.

typedef dynamic_exp<E> self_t

Definition at line 36 of file dynamicexp.hpp.

typedef unsigned int size_type

Definition at line 28 of file dynamicexp.hpp.

typedef E value_type

Definition at line 27 of file dynamicexp.hpp.


Constructor & Destructor Documentation

dynamic_exp (  )  [inline]

Definition at line 39 of file dynamicexp.hpp.

00039 :_size(0),_tab(NULL){}

dynamic_exp ( const dynamic_exp< E > &  d  )  [inline]

Definition at line 40 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, dynamic_exp< E >::_tab, and dynamic_exp< E >::alloc().

00040                                        :_size(d._size){
00041         //    cout <<"Copy "<<d<<" ";
00042         if (_size) {
00043           _tab = dynamic_exp<E>::alloc(_size);
00044           memcpy(_tab,d._tab,sizeof(E)*_size);
00045         }
00046         else
00047           _tab = NULL;
00048         //    cout <<*this<<endl;
00049   }

dynamic_exp ( int  s  )  [inline]

Definition at line 51 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab, and dynamic_exp< E >::alloc().

00051                     : _size(s){
00052         //    cout <<"C "<<s<<endl;
00053         _tab = dynamic_exp<E>::alloc(s);
00054         for(int i=0;i<s;i++) _tab[i]=(exponent_t)0;
00055         //    cout <<*this<<endl;
00056   }

dynamic_exp ( int  s,
E *  t 
) [inline]

Definition at line 58 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, dynamic_exp< E >::_tab, dynamic_exp< E >::alloc(), and assert.

00058                           : _size(s){
00059         assert(s <= sizeof(t)/sizeof(E));
00060         _tab = dynamic_exp<E>::alloc(_size);
00061         for(int i=0;i<s;i++) _tab[i]=t[i];
00062   }

~dynamic_exp (  )  [inline]

Definition at line 73 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

00073 {if (_tab) delete [] _tab;}


Member Function Documentation

static E* alloc ( unsigned int  N  )  [inline, static]
const_iterator begin (  )  const [inline]

Definition at line 78 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

00078 {return const_iterator(_tab); }

iterator begin (  )  [inline]

Definition at line 77 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

00077 {return iterator(_tab); }

void clear (  )  [inline]

Definition at line 185 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

Referenced by mmx::erase().

00185 {delete[] _tab;}

const_iterator end (  )  const [inline]

Definition at line 80 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, and dynamic_exp< E >::_tab.

00080 {return const_iterator(_tab+_size); }

iterator end (  )  [inline]

Definition at line 79 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, and dynamic_exp< E >::_tab.

00079 {return iterator(_tab+_size); }

void init ( int  s  )  [inline]

Definition at line 147 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, dynamic_exp< E >::_tab, and dynamic_exp< E >::alloc().

Referenced by mmx::add().

00148   {
00149         if (_size) { delete [] _tab; }
00150         _size= s;
00151         _tab = dynamic_exp<E>::alloc(s);
00152   }

self_t& operator= ( const self_t A  )  [inline]

Definition at line 94 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, dynamic_exp< E >::_tab, and dynamic_exp< E >::alloc().

00094                                         {
00095         if (&A == this) { return *this; }
00096         if (_tab != NULL) {
00097           // cout << "sz = " << sizeof( _tab) << " " << _size << endl;
00098           // for (int kk = 0; kk < _size; ++kk) {
00099           //   cout << _tab[kk] << " ";
00100           // } cout << endl;
00101           delete [] _tab;
00102         }
00103         _size = A._size;
00104         if (_size) {
00105           _tab = dynamic_exp<E>::alloc(_size);
00106           memcpy(_tab,A._tab,sizeof(E)*_size);
00107         }
00108         else
00109           _tab = NULL;
00110         return *this;
00111   }

E& operator[] ( size_type  i  )  [inline]

Definition at line 91 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, dynamic_exp< E >::_tab, and assert.

00091 { assert(i<_size);return _tab[i];}

E operator[] ( size_type  i  )  const [inline]

Definition at line 87 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, and dynamic_exp< E >::_tab.

00087                                       {
00088         //    if(i<0) cout <<"("<<*this<<"["<<i<<"])";
00089     return (i<_size?_tab[i]:0); 
00090   }

const_reverse_iterator rbegin (  )  const [inline]

Definition at line 83 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, and dynamic_exp< E >::_tab.

00083 {return reverse_iterator(_tab+_size); }

reverse_iterator rbegin (  )  [inline]

Definition at line 82 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, and dynamic_exp< E >::_tab.

00082 {return reverse_iterator(_tab+_size); }

const_reverse_iterator rend (  )  const [inline]

Definition at line 85 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

00085 {return reverse_iterator(_tab); }

reverse_iterator rend (  )  [inline]

Definition at line 84 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

00084 {return reverse_iterator(_tab); }

void reserve ( size_type  s  )  [inline]

Definition at line 115 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, dynamic_exp< E >::_tab, and dynamic_exp< E >::alloc().

00116   {
00117         if (!s) {
00118           if (_size) { delete [] _tab; }
00119           _size = 0;
00120           _tab = NULL;
00121         }
00122         else if(_tab==NULL) {
00123           _size = s;_tab = dynamic_exp<E>::alloc(s);
00124           //for(size_type i=0;i<s;i++) _tab[i]=(exponent_t)0;
00125         }
00126         else {
00127           delete [] _tab;
00128           _tab = dynamic_exp<E>::alloc(s);
00129           _size=s;
00130         }
00131   }

void resize ( size_type  s  )  [inline]

Definition at line 132 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, dynamic_exp< E >::_tab, and dynamic_exp< E >::alloc().

00133   {
00134         if(s<=_size)
00135           _size = s;
00136         else{
00137           E* _tmp =_tab;
00138           _tab = dynamic_exp<E>::alloc(s);
00139           for(size_type i =0;i<_size;i++) _tab[i]=_tmp[i];
00140           for(size_type i =_size;i<s;i++) _tab[i]=0;
00141           delete [] _tmp;
00142           _size=s;
00143         }
00144   }

dynamic_exp< E > & set_expt ( size_type  i,
value_type  d 
) [inline]

Definition at line 217 of file dynamicexp.hpp.

References dynamic_exp< E >::_size, and assert.

00218 {
00219   assert(i<_size);
00220   (*this)[i]=d;
00221 
00222   //  while(_tab[_size-1]==0 && _size>0) _size--;
00223 
00224   //    if (i < 0);
00225   //    else if (i+1 < _size)
00226   //            _tab[i] = d;
00227   //    else if (i >= _size && d) {
00228   //            E* aux = dynamic_exp<E>::alloc(i+1);
00229   //            memset(aux,0,sizeof(E)*(i+1));
00230   //            memcpy(aux,_tab,sizeof(E)*_size);
00231   //            //memset(aux+size,0,i-size);
00232   //            aux[i] = d;
00233   //            delete [] _tab;
00234   //            _tab = aux;
00235   //            //realloc(_tab,sizeof(E)*(i+1));
00236   //            //memset(_tab+size,0,i-size);
00237   //            //_tab[i] = d;
00238   //            _size = i+1;
00239   //    }
00240   //    else if (i >= _size && !d);
00241   //    else if (d)
00242   //            _tab[i] = d;
00243   //    else {
00244   //            int j = i - 1;
00245   //            while (j >= 0 && !_tab[j]) --j;
00246   //            _size = j+1;
00247   //            if (j < 0) {
00248   //                    clear();
00249   //                    _tab = NULL;
00250   //            }
00251   //            else {
00252   //                    E * aux = dynamic_exp<E>::alloc(j+1);
00253   //                    memcpy(aux,_tab,sizeof(E)*(j+1));
00254   //                    clear();
00255   //                    _tab = aux;
00256   //            }
00257   //    }
00258   return *this;
00259 }

size_type size ( void   )  const [inline]

Definition at line 75 of file dynamicexp.hpp.

References dynamic_exp< E >::_size.

Referenced by mmx::add().

00075 {return _size;}


Friends And Related Function Documentation

bool operator!= ( const dynamic_exp< E > &  A,
const dynamic_exp< E > &  B 
) [friend]

Definition at line 175 of file dynamicexp.hpp.

00175                                                                          {
00176         return !(A==B);
00177   }

bool operator== ( const dynamic_exp< E > &  A,
const dynamic_exp< E > &  B 
) [friend]

Definition at line 156 of file dynamicexp.hpp.

00156                                                                          {
00157         int i,minsize=std::min(A._size,B._size);
00158         for(i=0;i<minsize;i++)
00159           if(A._tab[i]!=B._tab[i]) return 0;
00160         if(A._size>B._size)
00161         {
00162           for(;i<(int)A._size;i++)
00163                 if(A._tab[i]) return 0;
00164         }
00165         else
00166         {
00167           for(;i<(int)B._size;i++)
00168                 if(B._tab[i]) return 0;
00169 
00170         }
00171         //        if (A._size == B._size)
00172         //     return memcmp(A._tab,B._tab,sizeof(E)*A._size) == 0;
00173         return 1;
00174   }


Member Data Documentation

E* _tab

The documentation for this struct was generated from the following file:

Generated on 6 Dec 2012 for realroot by  doxygen 1.6.1