PowerWordRep.h

Go to the documentation of this file.
00001 // Copyright (C) 2005 Alexander Ushakov
00002 // Contents: Definition of class PowerWordRep
00003 //
00004 // Principal Authors: Alexander Ushakov
00005 //
00006 // Revision History:
00007 //
00008 
00009 #ifndef _PowerWordRep_H_
00010 #define _PowerWordRep_H_
00011 
00012 
00013 
00014 #include "RefCounter.h"
00015 
00016 #include "vector"
00017 #include "list"
00018 #include "iostream"
00019 using namespace std;
00020 
00021 
00022 
00023 //---------------------------------------------------------------------------//
00024 //------------------------------ PowerWordRep -------------------------------//
00025 //---------------------------------------------------------------------------//
00026 
00027 
00028 class PowerWordRep : public RefCounter
00029 {
00030   friend class PowerWord;
00031   typedef pair< int , int > PII;
00032 
00034   //                                                     //
00035   //  Constructors                                       //
00036   //                                                     //
00038 
00039 private:
00040 
00041   PowerWordRep( );
00042   PowerWordRep( const list< PII >& gens );
00043   PowerWordRep( const vector< PII >& gens );
00044   PowerWordRep( const PowerWordRep& wr );
00045 
00046   PowerWordRep( const list< int >& gens );
00047   PowerWordRep( const vector< int >& gens );
00048   // special constructors, here we assume that -x is the inverse of x
00049 
00050   PowerWordRep( int g , int p = 1 );
00051 
00052   PowerWordRep operator=( const PowerWordRep wr );
00053 
00054 public:
00055 
00056 
00058   //                                                     //
00059   //  Operators                                          //
00060   //                                                     //
00062 private:
00063 
00064   PowerWordRep& operator *= ( const PowerWordRep& w );
00065   bool     operator <  ( const PowerWordRep& wr ) const;
00066   bool     operator >  ( const PowerWordRep& wr ) const;
00067   bool     operator == ( const PowerWordRep& wr ) const;
00068 
00069   inline PowerWordRep  operator * ( const PowerWordRep& w ) const {
00070     PowerWordRep result( *this );
00071     result *= w;
00072     return result;
00073   }
00074         
00076   //                                                     //
00077   //  Accessors:                                         //
00078   //                                                     //
00080 
00081 public:
00082 
00083   PowerWordRep* clone( ) const { return new PowerWordRep( *this ); }
00084 
00085   const list< PII >& getList( ) const { return theElements; }
00086   list< PII >& getList( ) { return theElements; }
00087 
00088         
00089 private:
00090 
00091   bool doesContain( int gen ) const;
00092 
00093   inline int length( ) const { return theLength; }
00094 
00095   int exponentSum( int gen ) const;
00096   int isIn( int gen ) const;
00097 
00098   int getPower( PowerWordRep& base ) const;
00099 
00100 
00102   //                                        //
00103   //  Manipulators                          //
00104   //                                        //
00106         
00107 private:
00108 
00109   PowerWordRep inverse( ) const;
00110 
00111   void cyclicallyReduce( );
00112   void cyclicallyReduce( PowerWordRep& conjugator );
00113 
00114   void cyclicLeftShift( );
00115   // the leftmost symbol goes to the rightmost position
00116   void cyclicRightShift( );
00117   // the rightmost symbol goes to the leftmost position
00118 
00119   void cyclicallyPermute( int n );
00120   // n>0 => left-shift permute
00121   // n<0 => rigth-shift permute
00122 
00123   void segment( int from , int to );
00124   // cut [from, to) part of the word
00125   // whole word is [0,length) part of itself
00126   void  initialSegment( int to   );
00127   void terminalSegment( int from );
00128 
00129   void insert( const PowerWordRep& wr , int pos );
00130 
00131 
00133   //                                                     //
00134   //  I/O:                                               //
00135   //                                                     //
00137 
00138 public:
00139 
00140   // friend ostream& operator << ( ostream& os , const PowerWordRep& wr ) {
00141   ostream& printOn( ostream& os ) const {
00142     list< PII >::const_iterator w_it = theElements.begin( );
00143     for( ; w_it!=theElements.end( ) ; ++w_it ) {
00144                         int g = (*w_it).first;
00145                         int p = (*w_it).second;
00146       if( w_it!=theElements.begin( ) ) os << " ";
00147       os << 'x' << g;
00148                         if( p!=1 ) os << '^' << p;
00149     }
00150     return os;
00151   }
00152 
00153 
00155   //                                                     //
00156   //  Internal functions:                                //
00157   //                                                     //
00159 
00160 private:
00161 
00162         void pushGeneratorBack( int g , int p );
00163         void pushGeneratorFront( int g , int p );
00164 
00166   //                                                     //
00167   //  Data members                                       //
00168   //                                                     //
00170 
00171 private:
00172 
00173   list< PII > theElements;
00174         // list of pairs (gen#,power)
00175 
00176         int theLength;
00177         // the total length of the word (the total sum of power)
00178 };
00179 
00180 
00181 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Mon Sep 26 18:43:45 2011 for CRyptography And Groups (CRAG) by  doxygen 1.6.1