realroot_doc 0.1.1
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.

:_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().

                                       :_size(d._size){
        //    cout <<"Copy "<<d<<" ";
        if (_size) {
          _tab = dynamic_exp<E>::alloc(_size);
          memcpy(_tab,d._tab,sizeof(E)*_size);
        }
        else
          _tab = NULL;
        //    cout <<*this<<endl;
  }
dynamic_exp ( int  s) [inline]

Definition at line 51 of file dynamicexp.hpp.

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

                    : _size(s){
        //    cout <<"C "<<s<<endl;
        _tab = dynamic_exp<E>::alloc(s);
        for(int i=0;i<s;i++) _tab[i]=(exponent_t)0;
        //    cout <<*this<<endl;
  }
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.

                          : _size(s){
        assert(s <= sizeof(t)/sizeof(E));
        _tab = dynamic_exp<E>::alloc(_size);
        for(int i=0;i<s;i++) _tab[i]=t[i];
  }
~dynamic_exp ( ) [inline]

Definition at line 73 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

{if (_tab) delete [] _tab;}

Member Function Documentation

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

Definition at line 77 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

{return iterator(_tab); }
const_iterator begin ( ) const [inline]

Definition at line 78 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

{return const_iterator(_tab); }
void clear ( ) [inline]

Definition at line 185 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

Referenced by mmx::erase().

{delete[] _tab;}
iterator end ( ) [inline]

Definition at line 79 of file dynamicexp.hpp.

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

{return iterator(_tab+_size); }
const_iterator end ( ) const [inline]

Definition at line 80 of file dynamicexp.hpp.

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

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().

  {
        if (_size) { delete [] _tab; }
        _size= s;
        _tab = dynamic_exp<E>::alloc(s);
  }
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().

                                        {
        if (&A == this) { return *this; }
        if (_tab != NULL) {
          // cout << "sz = " << sizeof( _tab) << " " << _size << endl;
          // for (int kk = 0; kk < _size; ++kk) {
          //   cout << _tab[kk] << " ";
          // } cout << endl;
          delete [] _tab;
        }
        _size = A._size;
        if (_size) {
          _tab = dynamic_exp<E>::alloc(_size);
          memcpy(_tab,A._tab,sizeof(E)*_size);
        }
        else
          _tab = NULL;
        return *this;
  }
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.

                                      {
        //    if(i<0) cout <<"("<<*this<<"["<<i<<"])";
    return (i<_size?_tab[i]:0); 
  }
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.

{ assert(i<_size);return _tab[i];}
reverse_iterator rbegin ( ) [inline]

Definition at line 82 of file dynamicexp.hpp.

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

const_reverse_iterator rbegin ( ) const [inline]

Definition at line 83 of file dynamicexp.hpp.

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

reverse_iterator rend ( ) [inline]

Definition at line 84 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

{return reverse_iterator(_tab); }
const_reverse_iterator rend ( ) const [inline]

Definition at line 85 of file dynamicexp.hpp.

References dynamic_exp< E >::_tab.

{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().

  {
        if (!s) {
          if (_size) { delete [] _tab; }
          _size = 0;
          _tab = NULL;
        }
        else if(_tab==NULL) {
          _size = s;_tab = dynamic_exp<E>::alloc(s);
          //for(size_type i=0;i<s;i++) _tab[i]=(exponent_t)0;
        }
        else {
          delete [] _tab;
          _tab = dynamic_exp<E>::alloc(s);
          _size=s;
        }
  }
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().

  {
        if(s<=_size)
          _size = s;
        else{
          E* _tmp =_tab;
          _tab = dynamic_exp<E>::alloc(s);
          for(size_type i =0;i<_size;i++) _tab[i]=_tmp[i];
          for(size_type i =_size;i<s;i++) _tab[i]=0;
          delete [] _tmp;
          _size=s;
        }
  }
dynamic_exp< E > & set_expt ( size_type  i,
value_type  d 
)

Definition at line 217 of file dynamicexp.hpp.

References assert.

{
  assert(i<_size);
  (*this)[i]=d;

  //  while(_tab[_size-1]==0 && _size>0) _size--;

  //    if (i < 0);
  //    else if (i+1 < _size)
  //            _tab[i] = d;
  //    else if (i >= _size && d) {
  //            E* aux = dynamic_exp<E>::alloc(i+1);
  //            memset(aux,0,sizeof(E)*(i+1));
  //            memcpy(aux,_tab,sizeof(E)*_size);
  //            //memset(aux+size,0,i-size);
  //            aux[i] = d;
  //            delete [] _tab;
  //            _tab = aux;
  //            //realloc(_tab,sizeof(E)*(i+1));
  //            //memset(_tab+size,0,i-size);
  //            //_tab[i] = d;
  //            _size = i+1;
  //    }
  //    else if (i >= _size && !d);
  //    else if (d)
  //            _tab[i] = d;
  //    else {
  //            int j = i - 1;
  //            while (j >= 0 && !_tab[j]) --j;
  //            _size = j+1;
  //            if (j < 0) {
  //                    clear();
  //                    _tab = NULL;
  //            }
  //            else {
  //                    E * aux = dynamic_exp<E>::alloc(j+1);
  //                    memcpy(aux,_tab,sizeof(E)*(j+1));
  //                    clear();
  //                    _tab = aux;
  //            }
  //    }
  return *this;
}
size_type size ( void  ) const [inline]

Definition at line 75 of file dynamicexp.hpp.

References dynamic_exp< E >::_size.

Referenced by mmx::add().

{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.

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

Definition at line 156 of file dynamicexp.hpp.

                                                                         {
        int i,minsize=std::min(A._size,B._size);
        for(i=0;i<minsize;i++)
          if(A._tab[i]!=B._tab[i]) return 0;
        if(A._size>B._size)
        {
          for(;i<(int)A._size;i++)
                if(A._tab[i]) return 0;
        }
        else
        {
          for(;i<(int)B._size;i++)
                if(B._tab[i]) return 0;

        }
        //        if (A._size == B._size)
        //     return memcmp(A._tab,B._tab,sizeof(E)*A._size) == 0;
        return 1;
  }

Member Data Documentation


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