Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/magnus/back_end/NilpotentGroup/include/PolyWordRep.h

Go to the documentation of this file.
00001 // Copyright (C) 1994 The New York Group Theory Cooperative
00002 // See magnus/doc/COPYRIGHT for the full notice.
00003 
00004 // Contents: Definition of PolyWordRep class.
00005 //           
00006 //
00007 // Principal Author: Eugene Paderin
00008 //
00009 // Status: Experimental version
00010 //
00011 // Revision History:
00012 //
00013 // Special Notes:
00014 //
00015 //
00016 
00017 #ifndef _POLY_WORD_REP_H_
00018 #define _POLY_WORD_REP_H_
00019 
00020 #include "Letter.h"
00021 #include "PureRep.h"
00022 
00023 class PolyWord;
00024 
00025 //------------------ PolyWordNode ----------------------------
00026 
00027 struct PolyWordNode {
00028 
00029   //------------------------------------------------------------
00030   // Constructors
00031   //------------------------------------------------------------
00032 
00033   PolyWordNode(const Letter& e, PolyWordNode *prv = NULL, PolyWordNode *nxt = NULL)
00034     : value(e), prev(prv), next(nxt) {}
00035 
00036   PolyWordNode(PolyWordNode *prv = NULL, PolyWordNode *nxt = NULL)
00037     : prev(prv), next(nxt) {}
00038 
00039   // copy constructor and destructor provided by compiler
00040 
00041   //------------------------------------------------------------
00042   //    Data
00043   //------------------------------------------------------------
00044 
00045   Letter value;
00046   PolyWordNode *prev;
00047   PolyWordNode *next;
00048 };
00049 
00050 //--------------- PolyWordRep ----------------------------------
00051 
00052 class PolyWordRep : public PureRep {
00053 
00054   //--------------------------------------------------------
00055   //    Constructors
00056   //--------------------------------------------------------
00057 
00058 public:
00059   
00060   PolyWordRep() : first(NULL), last(NULL), theNumberOfNodes(0) {}
00061 
00062   PolyWordRep( const Letter& let) 
00063     : first(new PolyWordNode(let) ), last(first), theNumberOfNodes(1) {}
00064 
00065   PolyWordRep( const Word& w);
00066 
00067   PolyWordRep(const class AbelianWord& aw);
00068 
00069   // copy constructor
00070   PolyWordRep(const PolyWordRep& src)
00071     : theNumberOfNodes(src.theNumberOfNodes) {
00072       src.duplicate(first, last);
00073     }
00074 
00075   // destructor
00076   ~PolyWordRep()  { clear(); }
00077 
00078   //--------------------------------------------------------
00079   //    Accessors to word properties
00080   //--------------------------------------------------------
00081 
00082   int length() const;
00083   // length of the word (sum of absolute values of powers).
00084   // The word considered to be not freely reduced. So, the length of
00085   // a^2 a^-1 is 3, not 1.
00086 
00087   int numberOfLetters() const { return theNumberOfNodes; }
00088   // number of Letters (length of the list)
00089 
00090   bool isCollected() const;
00091   // returns true iff the word is collected
00092 
00093 
00094   const Letter& firstLetter() const {
00095     if( theNumberOfNodes == 0)
00096       error("Attempt to access NULL pointer in PolyWordRep::firstLetter()");
00097     return first->value;
00098   }
00099 
00100   const Letter& lastLetter() const {
00101     if( theNumberOfNodes == 0)
00102       error("Attempt to access NULL pointer in PolyWordRep::lastLetter()");
00103     return last->value;
00104   }
00105 
00106   //--------------------------------------------------------
00107   //    I/O
00108   //--------------------------------------------------------
00109 
00110   void printOn (ostream& s) const;
00111   // output
00112 
00113   ostream& write(ostream& s) const;
00114   // IPC output
00115 
00116   istream& read(istream& s);
00117   // IPC input
00118 
00119   void debugInfo() const;
00120   // Prints debug info to cout
00121 
00122   //--------------------------------------------------------
00123   //    General methods
00124   //--------------------------------------------------------
00125 
00126   Word toWord() const;
00127   // cast to common Word (not reduced)
00128 
00129   Chars toChars( const VectorOf<Chars>& name ) const;
00130   // outputs word to string using given Chars as names of generators
00131 
00132   void freelyReduce();
00133   // freely reduces the word
00134 
00135   PolyWord inverse() const;
00136   // returns the inverse word
00137 
00138   void append(const PolyWord& w);
00139   // appends w to the end of this word
00140 
00141   void append(const Letter& w);
00142   // appends w to the end of this word
00143 
00144   void clear();
00145   // clears the list
00146 
00147   void removeFirstLetter() {
00148     removeTheLetter(first);
00149   }
00150   // removes the first letter      
00151 
00152   PolyWord raiseToPower( int power ) const;
00153   // Raises the word to given power (can be negative or 0)
00154 
00155   Chars inTermsOf(const VectorOf<Chars>& v) const;
00156   //Writes the word in readable form replacing generator g by string v[g-1].
00157   
00158   //-----------------------------------------------------
00159   //  For internal use
00160   //-----------------------------------------------------
00161 
00162   void duplicate(PolyWordNode*& ptrToFirst, PolyWordNode*& ptrToLast) const;
00163   // Duplicates the list and writes addresses of the new copy's
00164   // first and last nodes to ptrToFirst and ptrToLast.
00165 
00166   // binds two nodes together
00167   static inline void bind(PolyWordNode *leftNode, PolyWordNode *rightNode) {
00168     if(leftNode != NULL)  leftNode->next = rightNode;
00169     if(rightNode != NULL) rightNode->prev = leftNode;
00170   }
00171 
00172   // PolyWordIterator is a friend of PolyWord and PolyWordRep
00173   friend class PolyWordIterator;
00174   friend class ConstPolyWordIterator;
00175 
00176   virtual PureRep *clone() const {
00177     return new PolyWordRep(*this);
00178   }
00179 
00180   void removeTheLetter( PolyWordNode *theLetter);
00181   // removes the letter the argument points to  
00182 
00183 
00184 private:
00185 
00186   PolyWordNode *first, *last;
00187   int theNumberOfNodes;
00188 
00189 };
00190 
00191 
00192 
00193 #endif
00194 

Generated at Tue Jun 19 09:49:37 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001