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

/magnus/back_end/NilpotentGroup/include/PolyWordIterator.h

Go to the documentation of this file.
00001 
00002 // Copyright (C) 1994 The New York Group Theory Cooperative
00003 // See magnus/doc/COPYRIGHT for the full notice.
00004 
00005 // Contents: Definition of PolyWordIterator class.
00006 //           
00007 //
00008 // Principal Author: Eugene Paderin
00009 //
00010 // Status: Experimental version
00011 //
00012 // Revision History:
00013 //
00014 // Special Notes:
00015 //
00016 //
00017 
00018 #ifndef _POLYWORD_ITERATOR_H_
00019 #define _POLYWORD_ITERATOR_H_
00020 
00021 #include "PolyWord.h"
00022 
00023 class PolyWordIterator {
00024 
00025 public:
00026 
00027   //////////////////////////////////////////////////////////
00028   //
00029   //  Constructors
00030   //
00031   //////////////////////////////////////////////////////////
00032   
00033   PolyWordIterator(PolyWord& w) 
00034     : theRep( *w.change() ), iter(0) {}
00035 
00036   PolyWordIterator(PolyWordRep& w) 
00037     : theRep(w), iter(0) {}
00038 
00039   // copy constructor and destructor supplied by compiler
00040 
00041   //////////////////////////////////////////////////////////
00042   //
00043   //  Walking thru the word
00044   //
00045   //////////////////////////////////////////////////////////
00046 
00047   void startFromLeft() { iter = theRep.first; }
00048   // initialize iterator to point to the first letter
00049 
00050   void startFromRight() { iter = theRep.last; }
00051   // initialize iterator to point to the last letter
00052 
00053   void stepRight() { if(iter) iter = iter->next; }
00054   // move one step right
00055 
00056   void stepLeft() { if(iter) iter = iter->prev; }
00057   // move one step left
00058 
00059   bool done() const { return (iter == 0); }
00060   // True iff one of the ends was reached (collection is done)
00061 
00062   bool searchToLeft( Generator g );
00063   // Starting from the current position and moving left
00064   // searches a node containing g and makes it current.
00065   // Returns true iff the node is found.
00066 
00067   int position() const;
00068   // Returns the number of current letter, 1-based.
00069   // 0 means done().
00070   // This is a long running procedure, since the pointer travels to
00071   // the beginning of the word.
00072 
00073   ///////////////////////////////////////////////////////////
00074   //
00075   //  Fetching a Letter
00076   //
00077   ///////////////////////////////////////////////////////////
00078 
00079   // Error if a letter cannot be fetched
00080 
00081   Letter& thisLetter() const { 
00082     if( iter ) return iter->value;
00083     else error("Out-of-bound access at PolyWordIterator");
00084   }
00085   // The current letter
00086 
00087   Letter& leftLetter() const { 
00088     if( iter && iter->prev ) return iter->prev->value;
00089     else error("Out-of-bound access at PolyWordIterator");
00090   }
00091   // The letter left to the current one
00092 
00093   Letter& rightLetter() const { 
00094     if( iter && iter->next ) return iter->next->value;
00095     else error("Out-of-bound access at PolyWordIterator");
00096   }
00097   // The letter right to the current one
00098 
00099   bool isFirst() const { return iter == theRep.first; }
00100   // True iff the current letter is the first one
00101 
00102   bool isLast() const { return iter == theRep.last; }
00103   // True iff the current letter is the last one
00104 
00105   ///////////////////////////////////////////////////////////
00106   //
00107   //  PolyWord transformations
00108   //
00109   ///////////////////////////////////////////////////////////
00110 
00111   bool collectToRight();
00112   // collects the current letter with its right neighbors. If resulting
00113   // power is zero then the node is removed from chain and the iterator
00114   // points to the left neighbor (if exists; otherwise, points to the 
00115   // right one).
00116   // Returns true iff collection was performed.
00117 
00118   void splitToLeft();
00119   // "Splits" the current letter a^p into a * a^{p-1} if p>0, or
00120   // a^-1 * a^{p+1} if p<0. Iterator points to the right part.
00121   // If p is 1 or -1, nothing happens.
00122 
00123   void insertRight(const PolyWord& w);
00124   // Inserts w between the current letter and its right neighbor.
00125   // The iterator is not moved.
00126 
00127   void insertLeft(const PolyWord& w);
00128   // Inserts w between the current letter and its left neighbor.
00129   // The iterator is not moved.
00130 
00131   void insertRight(const Letter& let);
00132   // Inserts let between the current letter and its right neighbor.
00133   // The iterator is not moved.
00134 
00135   void insertLeft(const Letter& let);
00136   // Inserts let between the current letter and its left neighbor.
00137   // The iterator is not moved.
00138 
00139   void removeThisLetter();
00140   // removes the current letter. The iterator points to its right neighbor.
00141 
00142   void removeLeftLetter();
00143   // removes the left neighbor of the current letter.
00144 
00145   void removeRightLetter();
00146   // removes the right neighbor of the current letter.
00147 
00148   void decreaseLeftLetter();
00149   // decreases the abs( leftLetter.power ) by 1.
00150   // If the result is 0, removes the letter
00151 
00152   void exchangeToLeft();
00153   // Exchanges the current letter and its left neighbor. The iterator
00154   // points to the same letter as before.
00155 
00156 private:
00157 
00158   PolyWordRep& theRep;
00159   PolyWordNode *iter;
00160 };
00161 
00162 
00163 class ConstPolyWordIterator : private PolyWordIterator {
00164 
00165 public:
00166 
00167   //////////////////////////////////////////////////////////
00168   //
00169   //  Constructors
00170   //
00171   //////////////////////////////////////////////////////////
00172   
00173   ConstPolyWordIterator(const PolyWord& w) 
00174     : PolyWordIterator( (PolyWordRep&)*w.look() ) {}
00175 
00176   ConstPolyWordIterator(const PolyWordRep& w) 
00177     : PolyWordIterator( (PolyWordRep&)w ) {}
00178 
00179   // copy constructor and destructor supplied by compiler
00180 
00181   //////////////////////////////////////////////////////////
00182   //
00183   //  Walking thru the word
00184   //
00185   //////////////////////////////////////////////////////////
00186 
00187   PolyWordIterator::startFromLeft;
00188   // initialize iterator to point to the first letter
00189 
00190   PolyWordIterator::startFromRight;
00191   // initialize iterator to point to the last letter
00192 
00193   PolyWordIterator::stepRight;
00194   // move one step right
00195 
00196   PolyWordIterator::stepLeft;
00197   // move one step left
00198 
00199   PolyWordIterator::done;
00200   // True iff one of the ends was reached (collection is done)
00201 
00202   PolyWordIterator::searchToLeft;
00203   // Starting from the current position and moving left
00204   // searches a node containing g and makes it current.
00205   // Returns true iff the node is found.
00206 
00207   PolyWordIterator::position;
00208   // Returns the number of current letter, 1-based.
00209   // 0 means done().
00210   // This is a long procedure, since the pointer travels to
00211   // the beginning of the word.
00212 
00213   ///////////////////////////////////////////////////////////
00214   //
00215   //  Fetching a Letter
00216   //
00217   ///////////////////////////////////////////////////////////
00218 
00219   // Error if a letter cannot be fetched
00220 
00221   const Letter& thisLetter() const { 
00222     return PolyWordIterator::thisLetter(); 
00223   }
00224   // The current letter
00225 
00226   const Letter& leftLetter() const { 
00227     return PolyWordIterator::leftLetter(); 
00228   }
00229   // The letter left to the current one
00230 
00231   const Letter& rightLetter() const { 
00232     return PolyWordIterator::rightLetter(); 
00233   }
00234   // The letter right to the current one
00235 
00236   PolyWordIterator::isFirst;
00237   // True iff the current letter is the first one
00238 
00239   PolyWordIterator::isLast;
00240   // True iff the current letter is the last one
00241 
00242 };
00243 
00244 #endif
00245 

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