Version 4.0.0
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

Coder.h

Go to the documentation of this file.
00001 /* seqpp/Coder.h
00002  *
00003  * Copyright (C) 2003 Laboratoire Statistique & Génome
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or (at
00008  * your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  */
00028 #ifndef CODER_H
00029 #define CODER_H
00030 
00031 #include <vector>
00032 #include <iostream>
00033 
00034 using namespace std;
00035 
00046 class Coder
00047 {
00048  private:
00049 
00051   short _order;
00053   short _size;
00054 
00056   long * _pow;
00058   long * _jump;
00060   long ** _pow_r;
00061   
00063   vector<long> _vect;
00064   
00066   short compute_length() const;
00067   
00068  public:
00070   long _code;
00072   short _sizeword;
00073   
00075   Coder( short order, short size );
00076 
00079   Coder( short order, short size,
00080          long first_code, short sizeword );
00081   
00083   Coder( )
00084   {
00085     _order = -1; _size = 0; 
00086     _pow = NULL; _jump = NULL; 
00087     _pow_r = NULL;
00088   }  
00089   
00091   Coder( const Coder& c );
00092   
00094   ~Coder( );  
00095   
00096     
00098   void init( long code, short sizeword ){
00099     _code = code;
00100     _sizeword = sizeword;
00101   }
00102 
00104   void init( long code ){
00105     _code = code;
00106     _sizeword = this->compute_length();
00107   }
00108   
00110   void init( const vector<short>& X );
00111 
00113   void init( const short * X );
00114 
00116   void restrict_init( const short * X,  short pseudo_order );
00117 
00119   void clear(){
00120     _code = -1;
00121     _sizeword = 0;
00122   }
00123 
00124   
00126   void push_back( short i ){
00127     _code = (_code+1)*_size + i;
00128     _sizeword++;
00129   }
00131   long virtual_push_back( short i ) const{
00132     return (_code+1)*_size + i;
00133   }
00134 
00135 
00137   void push_front( short i ){
00138     _code += _pow[_sizeword] + _pow_r[i][_order-_sizeword];
00139     _sizeword++;
00140   }
00142   long virtual_push_front( short i ) const{
00143     return (_code + _pow[_sizeword] + _pow_r[i][_order-_sizeword]);
00144   }
00145 
00147   void erase_back(){
00148     _code = _code/_size - 1;
00149     _sizeword--;
00150   }
00152   short pop_back();
00153    
00154           
00156   void erase_front(){
00157     _sizeword--;
00158     _code = _code - _pow_r[  (_code-_jump[_sizeword])/_pow[_sizeword]  ][ _order-_sizeword ] - _pow[_sizeword];
00159   }
00161   short pop_front();
00162 
00164   bool empty() const{
00165     return (_code==-1);
00166   }
00167 
00169   short length() const{
00170     return _sizeword;
00171   }
00172 
00174   long tell_nbvalue() const{
00175     return _jump[_order+1];
00176   }
00177 
00179   long tell_jump( short i ) const{
00180     return _jump[i];
00181   }
00183   long tell_jump( ) const{
00184     return _jump[_order];
00185   }
00186   
00188   long * get_jump() const{
00189     return _jump;
00190   }
00191 
00193   vector<long> & list_suffixed( short sizeprefix );
00195   vector<long> & list_suffixed( ){
00196     return list_suffixed( _order+1 - _sizeword );
00197   }
00198 
00200   vector<long> & bound_prefixed( short sizesuffix );
00202   vector<long> & bound_prefixed( ){
00203     return bound_prefixed( _order+1 - _sizeword );
00204   }
00205 };
00206 #endif



Download seq++ 4.0.0
Download previous versions
Statistique & Genome Home


Generated on Sun Apr 3 14:16:10 2005 for seqpp by doxygen 1.3.9.1