Open
Graph Drawing
Framework

 v.2012.05
 

PQNode.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00049 #ifdef _MSC_VER
00050 #pragma once
00051 #endif
00052 
00053 
00054 #ifndef OGDF_PQ_NODE_H
00055 #define OGDF_PQ_NODE_H
00056 
00057 
00058 #include <ogdf/basic/List.h>
00059 #include <ogdf/internal/planarity/PQNodeRoot.h>
00060 
00061 
00062 namespace ogdf {
00063 
00064 
00065 //Status Definitions
00066 #define EMPTY          1
00067 #define PARTIAL        2
00068 #define FULL           3
00069 #define PERTINENT      4
00070 #define TO_BE_DELETED  5
00071 
00072 //Mark Definitions for Bubble Phase
00073 #define UNMARKED       0
00074 #define QUEUED         1
00075 #define BLOCKED        2
00076 #define UNBLOCKED      3
00077 
00078 enum SibDirection {
00079     NODIR, LEFT, RIGHT
00080 };
00081 
00082 template<class T,class X,class Y> class PQTree;
00083 template<class T,class X,class Y> class PQLeafKey;
00084 template<class T,class X,class Y> class PQNodeKey;
00085 template<class T,class X,class Y> class PQInternalKey;
00086 
00087 
00088 template<class T,class X,class Y> class PQNode: public PQNodeRoot
00089 {
00096     friend class PQTree<T,X,Y>;
00097 
00098 public:
00099 
00105     PQNode(int count, PQNodeKey<T,X,Y>* infoPtr);
00106 
00107     
00112     PQNode(int count);
00113       
00123     virtual ~PQNode()
00124     {
00125         delete fullChildren;
00126         delete partialChildren;
00127     }
00128 
00139     bool changeEndmost(PQNode<T,X,Y>* oldEnd,
00140                        PQNode<T,X,Y>* newEnd);
00141 
00152     bool changeSiblings(PQNode<T,X,Y>* oldSib,
00153                         PQNode<T,X,Y>* newSib);
00154 
00161     bool endmostChild() {
00162         return (m_sibLeft == 0 || m_sibRight == 0);
00163     }
00164  
00174     PQNode<T,X,Y>* getEndmost(PQNode<T,X,Y>* other) const {
00175         if (m_leftEndmost != other)
00176             return m_leftEndmost;
00177         else if (m_rightEndmost != other)
00178             return m_rightEndmost;
00179 
00180         return 0;
00181     }
00182 
00188     PQNode<T,X,Y>* getEndmost(int side) const {
00189         if (side == LEFT || side == 0)
00190             return m_leftEndmost;
00191         else if(side == RIGHT) 
00192             return m_rightEndmost;
00193         
00194         return 0;
00195     }
00196 
00198     PQNodeKey<T,X,Y>* getNodeInfo() const {return m_pointerToInfo;};
00199 
00205     PQNode<T,X,Y>* getSib(int side) const {
00206         if (side == LEFT)
00207             return m_sibLeft;
00208         else if (side == RIGHT) 
00209             return m_sibRight;
00210         
00211         return 0;
00212     };
00213 
00223     PQNode<T,X,Y>* getNextSib(PQNode<T,X,Y>* other) const {
00224         if (m_sibLeft != other)
00225             return m_sibLeft;
00226         else if (m_sibRight != other)
00227             return m_sibRight;
00228         
00229         return 0;
00230     }
00231 
00232 
00234     int  identificationNumber() const { return m_identificationNumber; }
00235 
00237     int  childCount() const { return m_childCount; }
00238 
00240     void childCount(int count) { m_childCount = count; }
00241 
00249     PQNode<T,X,Y>* parent() const { return m_parent; }
00250 
00258     PQNode<T,X,Y>* parent(PQNode<T,X,Y>* newParent) 
00259     {
00260         return m_parent = newParent;
00261     }
00262 
00264     int parentType() const { return m_parentType; }
00265 
00270     void parentType(int newParentType) { m_parentType = newParentType; }
00271 
00273     int pertChildCount() const { return m_pertChildCount; }
00274 
00276     void pertChildCount(int count) { m_pertChildCount = count; }
00277 
00291     SibDirection putSibling(PQNode<T,X,Y>* newSib)
00292     {
00293         if (m_sibLeft == 0) {
00294             m_sibLeft = newSib;
00295             return LEFT;
00296         }
00297         
00298         OGDF_ASSERT(m_sibRight == 0);
00299         m_sibRight = newSib;
00300         return RIGHT;
00301     }
00302 
00319     SibDirection putSibling(PQNode<T,X,Y>* newSib,
00320                     int preference)
00321     {
00322         if (preference == LEFT)
00323             return putSibling(newSib);
00324 
00325         OGDF_ASSERT(preference == RIGHT);
00326         
00327         if (m_sibRight == 0)
00328         {
00329             m_sibRight = newSib;
00330             return RIGHT;
00331         }
00332 
00333         OGDF_ASSERT(m_sibLeft == 0);
00334         m_sibLeft = newSib;
00335         return LEFT;
00336     }
00337 
00339     PQNode<T,X,Y>* referenceChild() const { return m_referenceChild; } 
00340 
00342     PQNode<T,X,Y>* referenceParent() const { return m_referenceParent; }
00343 
00345     bool  setNodeInfo(PQNodeKey<T,X,Y>* pointerToInfo) {
00346         m_pointerToInfo = pointerToInfo;
00347         if (pointerToInfo != 0)
00348         {    
00349             m_pointerToInfo->setNodePointer(this);
00350             return true;
00351         }
00352         
00353         return false;
00354     }
00355 
00362     virtual PQLeafKey<T,X,Y>* getKey() const = 0;
00363 
00365 
00377     virtual bool setKey(PQLeafKey<T,X,Y>* pointerToKey) = 0;
00378 
00386     virtual PQInternalKey<T,X,Y>* getInternal() const = 0;
00387     
00388     /*
00389      * setInternal() sets a specified pointer variable in a derived class
00390      * to the specified adress of \a pointerToInternal that is of type
00391      * PQInternalKey.
00392      *
00393      * If a derived class, such as PQLeaf,
00394      * is not supposed to store informations of type PQInternalKey,
00395      * setInternal() ignores the informations as long as
00396      * \a pointerToInternal = 0. The return value then is 1.
00397      * In case that \a pointerToInternal != 0, the return value is 0.
00398      *
00399      * If a derived class, such as PQInternalNode is 
00400      * supposed to store informations of type PQInternalKey,
00401      * \a pointerToInternal has to be instantiated by the client. The
00402      * function setInternal() does
00403      * not instantiate the corresponding variable in the derived class.
00404      * The return value is always 1 unless \a pointerInternal was
00405      * equal to 0.
00406      */
00407     virtual bool setInternal(PQInternalKey<T,X,Y>* pointerToInternal) = 0;
00408 
00416     virtual int mark() const = 0;          
00417     
00419     virtual void mark(int) = 0;
00420 
00422 
00432     virtual int status() const = 0;        
00433     
00435     virtual void status(int) = 0;
00436 
00438 
00447     virtual PQNodeType type() const = 0;          
00448 
00450     virtual void type(PQNodeType) = 0;
00451       
00452 
00453 protected:
00454 
00455    
00457     int m_childCount;
00458     
00465     int m_debugTreeNumber;
00466     
00478     int m_identificationNumber;
00479 
00481     int m_parentType;    
00482     
00484     int m_pertChildCount; 
00485 
00487     int m_pertLeafCount; 
00488 
00490     PQNode<T,X,Y> *m_firstFull;
00491 
00492     PQNode<T,X,Y> *m_leftEndmost;       
00493 
00499     PQNode<T,X,Y> *m_parent; 
00500     
00507     PQNode<T,X,Y> *m_referenceChild;
00508 
00515     PQNode<T,X,Y> *m_referenceParent;
00516 
00518     PQNode<T,X,Y> *m_rightEndmost;    
00519 
00527     PQNode<T,X,Y> *m_sibLeft;
00528 
00536     PQNode<T,X,Y> *m_sibRight;
00537     
00539     PQNodeKey<T,X,Y> *m_pointerToInfo;
00540 
00541 
00543     List<PQNode<T,X,Y>*> *fullChildren; 
00544 
00546     List<PQNode<T,X,Y>*> *partialChildren;
00547 
00548 };
00549 
00550 
00551 /*
00552 The function [[changeEndmost]] replaces the old endmost child [[oldEnd]] of
00553 the node by a new child [[newEnd]].
00554 If the node is a $Q$-node, then it must have two valid
00555 pointers to its endmost children. If one of the endmost children is [[oldEnd]],
00556 it is replaced by [[newEnd]].
00557 The function [[changeEndmost]] returns [[1]] if it succeeded in
00558 replacing [[oldEnd]] by [[newEnd]]. Otherwise the function returns
00559 [[0]], leaving with an error message.
00560 */
00561 template<class T,class X,class Y> 
00562 bool PQNode<T,X,Y>::changeEndmost(PQNode<T,X,Y>* oldEnd,
00563                                PQNode<T,X,Y>* newEnd)
00564 {
00565     if (m_leftEndmost == oldEnd)
00566     {
00567         m_leftEndmost = newEnd;
00568         return true;
00569     }
00570     else if (m_rightEndmost == oldEnd)
00571     {
00572         m_rightEndmost = newEnd;
00573         return true;
00574     }
00575     return false;
00576 }
00577 
00578 /*
00579 The function [[changeSiblings]] replaces the old sibling [[oldSib]] of the
00580 node by a new sibling [[newSib]]. 
00581 
00582 If the node has [[oldSib]] as sibling, then it changes the
00583 sibling pointer that references to [[oldSib]] and places [[newSib]]
00584 at its position.
00585 
00586 The function [[changeSiblings]] returns [[1]] if it succeeded in replacing
00587 [[oldSib]] by [[newSib]]. Otherwise the function returns
00588 [[0]], leaving with an error message.
00589 */
00590 template<class T,class X,class Y> 
00591 bool PQNode<T,X,Y>::changeSiblings(PQNode<T,X,Y>* oldSib,
00592                                 PQNode<T,X,Y>* newSib)
00593 {
00594     if (m_sibLeft == oldSib)
00595     {
00596         m_sibLeft = newSib;
00597         return true;
00598     }
00599     else if (m_sibRight == oldSib)
00600     {
00601         m_sibRight = newSib;
00602         return true;
00603     }
00604     return false;
00605 }
00606    
00607 
00608 /*
00609 The (first) constructor combines the node with its information and 
00610 will automatically set the [[m_nodePointer]] (see \ref{basicKey}) of 
00611 the element of type [[PQNodeKey]] (see \ref{PQNodeKey}).
00612 */
00613 template<class T,class X,class Y>
00614 PQNode<T,X,Y>::PQNode(int count,PQNodeKey<T,X,Y>* infoPtr)
00615 {
00616 
00617    m_identificationNumber = count;
00618    m_childCount = 0;
00619    m_pertChildCount = 0;
00620    m_pertLeafCount = 0;
00621    m_debugTreeNumber = 0;
00622    m_parentType = 0;
00623 
00624    m_parent = 0;
00625    m_firstFull = 0;
00626    m_sibLeft = 0;
00627    m_sibRight = 0;
00628    m_referenceChild = 0;
00629    m_referenceParent = 0;
00630    m_leftEndmost = 0;
00631    m_rightEndmost = 0;   
00632 
00633    fullChildren = OGDF_NEW List<PQNode<T,X,Y>*>;
00634    partialChildren = OGDF_NEW List<PQNode<T,X,Y>*>;
00635 
00636    m_pointerToInfo = infoPtr;
00637    infoPtr->setNodePointer(this);
00638 }
00639 
00640 
00641 /*
00642 The (second) constructor is called, 
00643 if no information is available or neccessary.
00644 */
00645 template<class T,class X,class Y>
00646 PQNode<T,X,Y>::PQNode(int count)
00647 {
00648    m_identificationNumber = count;
00649    m_childCount = 0;
00650    m_pertChildCount = 0;
00651    m_pertLeafCount = 0;
00652    m_debugTreeNumber = 0;
00653    m_parentType = 0;
00654 
00655    m_parent = 0;
00656    m_firstFull = 0;
00657    m_sibLeft = 0;
00658    m_sibRight = 0;
00659    m_referenceChild = 0;
00660    m_referenceParent = 0;
00661    m_leftEndmost = 0;
00662    m_rightEndmost = 0;   
00663 
00664    fullChildren = OGDF_NEW List<PQNode<T,X,Y>*>;
00665    partialChildren = OGDF_NEW List<PQNode<T,X,Y>*>;
00666 
00667    m_pointerToInfo = 0;
00668 }
00669 
00670 }
00671 
00672 #endif
00673