Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

PQNode.h
Go to the documentation of this file.
1 
38 #pragma once
39 
40 #include <ogdf/basic/List.h>
42 
43 namespace ogdf {
44 
45 template<class T,class X,class Y> class PQTree;
46 template<class T,class X,class Y> class PQLeafKey;
47 template<class T,class X,class Y> class PQNodeKey;
48 template<class T,class X,class Y> class PQInternalKey;
49 
50 template<class T,class X,class Y> class PQNode: public PQNodeRoot
51 {
58  friend class PQTree<T,X,Y>;
59 
60 public:
61 
67  PQNode(int count, PQNodeKey<T,X,Y>* infoPtr);
68 
69 
74  explicit PQNode(int count);
75 
85  virtual ~PQNode()
86  {
87  delete fullChildren;
88  delete partialChildren;
89  }
90 
101  bool changeEndmost(PQNode<T,X,Y>* oldEnd, PQNode<T,X,Y>* newEnd);
102 
113  bool changeSiblings(PQNode<T,X,Y>* oldSib, PQNode<T,X,Y>* newSib);
114 
121  bool endmostChild() const {
122  return m_sibLeft == nullptr || m_sibRight == nullptr;
123  }
124 
135  if (m_leftEndmost != other)
136  return m_leftEndmost;
137  else if (m_rightEndmost != other)
138  return m_rightEndmost;
139 
140  return nullptr;
141  }
142 
149  if (side == SibDirection::Left || side == SibDirection::NoDir)
150  return m_leftEndmost;
151  else if(side == SibDirection::Right)
152  return m_rightEndmost;
153 
154  return nullptr;
155  }
156 
159 
166  if (side == SibDirection::Left)
167  return m_sibLeft;
168  else if (side == SibDirection::Right)
169  return m_sibRight;
170 
171  return nullptr;
172  }
173 
184  if (m_sibLeft != other)
185  return m_sibLeft;
186  else if (m_sibRight != other)
187  return m_sibRight;
188 
189  return nullptr;
190  }
191 
192 
195 
197  int childCount() const { return m_childCount; }
198 
200  void childCount(int count) { m_childCount = count; }
201 
209  PQNode<T,X,Y>* parent() const { return m_parent; }
210 
219  {
220  return m_parent = newParent;
221  }
222 
224  PQNodeType parentType() const { return m_parentType; }
225 
230  void parentType(PQNodeType newParentType) { m_parentType = newParentType; }
231 
233  int pertChildCount() const { return m_pertChildCount; }
234 
236  void pertChildCount(int count) { m_pertChildCount = count; }
237 
252  {
253  if (m_sibLeft == nullptr) {
254  m_sibLeft = newSib;
255  return SibDirection::Left;
256  }
257 
258  OGDF_ASSERT(m_sibRight == nullptr);
259  m_sibRight = newSib;
260  return SibDirection::Right;
261  }
262 
280  {
281  if (preference == SibDirection::Left)
282  return putSibling(newSib);
283 
284  OGDF_ASSERT(preference == SibDirection::Right);
285 
286  if (m_sibRight == nullptr)
287  {
288  m_sibRight = newSib;
289  return SibDirection::Right;
290  }
291 
292  OGDF_ASSERT(m_sibLeft == nullptr);
293  m_sibLeft = newSib;
294  return SibDirection::Left;
295  }
296 
299 
302 
304  bool setNodeInfo(PQNodeKey<T,X,Y>* pointerToInfo) {
305  m_pointerToInfo = pointerToInfo;
306  if (pointerToInfo != nullptr)
307  {
308  m_pointerToInfo->setNodePointer(this);
309  return true;
310  }
311 
312  return false;
313  }
314 
321  virtual PQLeafKey<T,X,Y>* getKey() const = 0;
322 
324 
336  virtual bool setKey(PQLeafKey<T,X,Y>* pointerToKey) = 0;
337 
345  virtual PQInternalKey<T,X,Y>* getInternal() const = 0;
346 
347  /*
348  * setInternal() sets a specified pointer variable in a derived class
349  * to the specified adress of \p pointerToInternal that is of type
350  * PQInternalKey.
351  *
352  * If a derived class, such as PQLeaf,
353  * is not supposed to store informations of type PQInternalKey,
354  * setInternal() ignores the informations as long as
355  * \p pointerToInternal = 0. The return value then is 1.
356  * In case that \p pointerToInternal != 0, the return value is 0.
357  *
358  * If a derived class, such as PQInternalNode is
359  * supposed to store informations of type PQInternalKey,
360  * \p pointerToInternal has to be instantiated by the client. The
361  * function setInternal() does
362  * not instantiate the corresponding variable in the derived class.
363  * The return value is always 1 unless \p pointerInternal was
364  * equal to 0.
365  */
366  virtual bool setInternal(PQInternalKey<T,X,Y>* pointerToInternal) = 0;
367 
375  virtual PQNodeMark mark() const = 0;
376 
378  virtual void mark(PQNodeMark) = 0;
379 
381 
391  virtual PQNodeStatus status() const = 0;
392 
394  virtual void status(PQNodeStatus) = 0;
395 
397 
406  virtual PQNodeType type() const = 0;
407 
409  virtual void type(PQNodeType) = 0;
410 
411 
412 protected:
413 
414 
415  // Stores the number of children of the node.
417 
425 
438 
441 
444 
447 
450 
452 
459 
467 
475 
478 
487 
496 
499 
500 
503 
506 
507 };
508 
509 
510 /*
511 The function [[changeEndmost]] replaces the old endmost child [[oldEnd]] of
512 the node by a new child [[newEnd]].
513 If the node is a $Q$-node, then it must have two valid
514 pointers to its endmost children. If one of the endmost children is [[oldEnd]],
515 it is replaced by [[newEnd]].
516 The function [[changeEndmost]] returns [[1]] if it succeeded in
517 replacing [[oldEnd]] by [[newEnd]]. Otherwise the function returns
518 [[0]], leaving with an error message.
519 */
520 template<class T,class X,class Y>
522 {
523  if (m_leftEndmost == oldEnd)
524  {
525  m_leftEndmost = newEnd;
526  return true;
527  }
528  else if (m_rightEndmost == oldEnd)
529  {
530  m_rightEndmost = newEnd;
531  return true;
532  }
533  return false;
534 }
535 
536 /*
537 The function [[changeSiblings]] replaces the old sibling [[oldSib]] of the
538 node by a new sibling [[newSib]].
539 
540 If the node has [[oldSib]] as sibling, then it changes the
541 sibling pointer that references to [[oldSib]] and places [[newSib]]
542 at its position.
543 
544 The function [[changeSiblings]] returns [[1]] if it succeeded in replacing
545 [[oldSib]] by [[newSib]]. Otherwise the function returns
546 [[0]], leaving with an error message.
547 */
548 template<class T,class X,class Y>
550 {
551  if (m_sibLeft == oldSib)
552  {
553  m_sibLeft = newSib;
554  return true;
555  }
556  else if (m_sibRight == oldSib)
557  {
558  m_sibRight = newSib;
559  return true;
560  }
561  return false;
562 }
563 
564 
565 /*
566 The (first) constructor combines the node with its information and
567 will automatically set the [[m_nodePointer]] (see \ref{basicKey}) of
568 the element of type [[PQNodeKey]] (see \ref{PQNodeKey}).
569 */
570 template<class T,class X,class Y>
572 {
573  m_identificationNumber = count;
574  m_childCount = 0;
575  m_pertChildCount = 0;
576  m_pertLeafCount = 0;
577  m_debugTreeNumber = 0;
579 
580  m_parent = nullptr;
581  m_firstFull = nullptr;
582  m_sibLeft = nullptr;
583  m_sibRight = nullptr;
584  m_referenceChild = nullptr;
585  m_referenceParent = nullptr;
586  m_leftEndmost = nullptr;
587  m_rightEndmost = nullptr;
588 
591 
592  m_pointerToInfo = infoPtr;
593  infoPtr->setNodePointer(this);
594 }
595 
596 
597 /*
598 The (second) constructor is called,
599 if no information is available or neccessary.
600 */
601 template<class T,class X,class Y>
603 {
604  m_identificationNumber = count;
605  m_childCount = 0;
606  m_pertChildCount = 0;
607  m_pertLeafCount = 0;
608  m_debugTreeNumber = 0;
610 
611  m_parent = nullptr;
612  m_firstFull = nullptr;
613  m_sibLeft = nullptr;
614  m_sibRight = nullptr;
615  m_referenceChild = nullptr;
616  m_referenceParent = nullptr;
617  m_leftEndmost = nullptr;
618  m_rightEndmost = nullptr;
619 
622 
623  m_pointerToInfo = nullptr;
624 }
625 
626 }
The class template PQNodeKey is a derived class of class template PQBasicKey.
Definition: PQNode.h:47
int m_pertChildCount
Stores the number of pertinent children of the node.
Definition: PQNode.h:443
List< PQNode< T, X, Y > * > * partialChildren
Stores all partial children of a node during a reduction.
Definition: PQNode.h:505
int pertChildCount() const
Returs the number of pertinent children of a node.
Definition: PQNode.h:233
SibDirection putSibling(PQNode< T, X, Y > *newSib, SibDirection preference)
The function putSibling() with preference stores a new sibling at a free sibling pointer of the node...
Definition: PQNode.h:279
int m_pertLeafCount
Stores the number of pertinent leaves in the frontier of the node.
Definition: PQNode.h:446
List< PQNode< T, X, Y > * > * fullChildren
Stores all full children of a node during a reduction.
Definition: PQNode.h:502
PQNode< T, X, Y > * referenceParent() const
Returns the pointer to the parent if node is a reference child.
Definition: PQNode.h:301
Declaration and implementation of the class PQNodeRoot.
PQNode< T, X, Y > * getEndmost(SibDirection side) const
Returns one of the endmost children of node, if node is a Q-node.
Definition: PQNode.h:148
PQNode< T, X, Y > * m_referenceParent
Is a pointer to the parent, in case that the parent is a P-node and the node itself is its reference ...
Definition: PQNode.h:474
PQNode(int count, PQNodeKey< T, X, Y > *infoPtr)
The (first) constructor combines the node with its information and will automatically set the PQBasic...
Definition: PQNode.h:571
PQNodeType parentType() const
Returns the type of the parent of a node.
Definition: PQNode.h:224
PQNodeKey< T, X, Y > * m_pointerToInfo
Stores a pointer to the corresponding information of the node.
Definition: PQNode.h:498
virtual ~PQNode()
The destructor does not delete any accompanying information class as PQLeafKey, PQNodeKey and PQInter...
Definition: PQNode.h:85
virtual bool setKey(PQLeafKey< T, X, Y > *pointerToKey)=0
Sets a specified pointer variable in a derived class to the specified adress of pointerToKey that is ...
int m_childCount
Definition: PQNode.h:416
PQNodeType m_parentType
Stores the type of the parent which can be either a P- or Q-node.
Definition: PQNode.h:440
virtual PQLeafKey< T, X, Y > * getKey() const =0
getKey() returns a pointer to the PQLeafKeyof a node, in case that the node is supposed to have a key...
virtual PQNodeMark mark() const =0
mark() returns the variable PQLeaf::m_mark in the derived class PQLeaf and PQInternalNode.
int m_debugTreeNumber
Needed for debuging purposes.
Definition: PQNode.h:424
bool endmostChild() const
The function endmostChild() checks if a node is endmost child of a Q-node.
Definition: PQNode.h:121
SibDirection putSibling(PQNode< T, X, Y > *newSib)
The default function putSibling() stores a new sibling at a free sibling pointer of the node...
Definition: PQNode.h:251
virtual PQNodeStatus status() const =0
Returns the variable PQLeaf::m_status in the derived class PQLeaf and PQInternalNode.
PQNode< T, X, Y > * m_rightEndmost
Stores the right endmost child of a Q-node.
Definition: PQNode.h:477
PQNode< T, X, Y > * referenceChild() const
Returns a pointer to the reference child if node is a P-node.
Definition: PQNode.h:298
bool changeSiblings(PQNode< T, X, Y > *oldSib, PQNode< T, X, Y > *newSib)
The function changeSiblings() replaces the old sibling oldSib of the node by a new sibling newSib...
Definition: PQNode.h:549
void parentType(PQNodeType newParentType)
Sets the type of the parent of a node.
Definition: PQNode.h:230
int m_identificationNumber
Each node that has been introduced once into the tree gets a unique number.
Definition: PQNode.h:437
PQNode< T, X, Y > * getSib(SibDirection side) const
The function getSib() returns one of the siblings of the node.
Definition: PQNode.h:165
Doubly linked lists (maintaining the length of the list).
Definition: List.h:40
PQNode< T, X, Y > * m_referenceChild
Stores a pointer to one child, the reference child of the doubly linked cirkular list of children of ...
Definition: PQNode.h:466
PQNode< T, X, Y > * getNextSib(PQNode< T, X, Y > *other) const
The function getNextSib() returns one of the siblings of the node.
Definition: PQNode.h:183
bool setNodeInfo(PQNodeKey< T, X, Y > *pointerToInfo)
Sets the pointer m_pointerToInfo to the specified adress of pointerToInfo.
Definition: PQNode.h:304
virtual bool setInternal(PQInternalKey< T, X, Y > *pointerToInternal)=0
int identificationNumber() const
Returns the identification number of a node.
Definition: PQNode.h:194
PQNodeKey< T, X, Y > * getNodeInfo() const
Returns the identification number of a node.
Definition: PQNode.h:158
void childCount(int count)
Sets the number of children of a node.
Definition: PQNode.h:200
PQNode< T, X, Y > * m_leftEndmost
Definition: PQNode.h:451
PQNode< T, X, Y > * parent(PQNode< T, X, Y > *newParent)
Sets the parent pointer of a node.
Definition: PQNode.h:218
PQNode< T, X, Y > * m_parent
Is a pointer to the parent.
Definition: PQNode.h:458
virtual PQInternalKey< T, X, Y > * getInternal() const =0
getInternal() returns a pointer to the PQInternalKey information of a node, in case that the node is ...
The class template PQInternalKey is a derived class of class template PQBasicKey. ...
Definition: PQInternalKey.h:57
PQNode< T, X, Y > * parent() const
The function parent() returns a pointer to the parent of a node.
Definition: PQNode.h:209
The class template PQLeafKey is a derived class of class template PQBasicKey.
Definition: PQLeafKey.h:86
The class template PQBasicKey is an abstract base class.
Definition: PQBasicKey.h:108
int childCount() const
Returns the number of children of a node.
Definition: PQNode.h:197
PQNode< T, X, Y > * m_sibRight
Stores a pointer ot the right sibling of PQNode.
Definition: PQNode.h:495
PQNode< T, X, Y > * getEndmost(PQNode< T, X, Y > *other) const
Returns one of the endmost children of node, if node is a Q-node.
Definition: PQNode.h:134
void setNodePointer(PQNode< T, X, Y > *pqNode)
The function setNodePointer() sets the private member m_nodePointer.
Definition: PQBasicKey.h:153
The namespace for all OGDF objects.
The class PQNodeRoot is used as a base class of the class PQNode.
Definition: PQNodeRoot.h:44
void pertChildCount(int count)
Sets the number of pertinent children of a node.
Definition: PQNode.h:236
PQNode< T, X, Y > * m_sibLeft
Stores a pointer ot the left sibling of PQNode.
Definition: PQNode.h:486
PQNode< T, X, Y > * m_firstFull
Stores a pointer to the first full child of a Q-node.
Definition: PQNode.h:449
bool changeEndmost(PQNode< T, X, Y > *oldEnd, PQNode< T, X, Y > *newEnd)
The function changeEndmost() replaces the old endmost child oldEnd of the node by a new child newEnd...
Definition: PQNode.h:521
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
Declaration of doubly linked lists and iterators.
virtual PQNodeType type() const =0
Returns the variable PQInternalNode::m_type in the derived class PQLeaf and PQInternalNode.