Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

PQNode.h
Go to the documentation of this file.
1 
38 #pragma once
39 
40 #include <ogdf/basic/List.h>
41 #include <ogdf/basic/basic.h>
43 
44 namespace ogdf {
45 
46 template<class T, class X, class Y>
47 class PQInternalKey;
48 template<class T, class X, class Y>
49 class PQLeafKey;
50 template<class T, class X, class Y>
51 class PQNodeKey;
52 template<class T, class X, class Y>
53 class PQTree;
54 
55 template<class T, class X, class Y>
56 class PQNode : public PQNodeRoot {
63  friend class PQTree<T, X, Y>;
64 
65 public:
71  PQNode(int count, PQNodeKey<T, X, Y>* infoPtr);
72 
73 
78  explicit PQNode(int count);
79 
89  virtual ~PQNode() {
90  delete fullChildren;
91  delete partialChildren;
92  }
93 
104  bool changeEndmost(PQNode<T, X, Y>* oldEnd, PQNode<T, X, Y>* newEnd);
105 
116  bool changeSiblings(PQNode<T, X, Y>* oldSib, PQNode<T, X, Y>* newSib);
117 
124  bool endmostChild() const { return m_sibLeft == nullptr || m_sibRight == nullptr; }
125 
136  if (m_leftEndmost != other) {
137  return m_leftEndmost;
138  } else if (m_rightEndmost != other) {
139  return m_rightEndmost;
140  }
141 
142  return nullptr;
143  }
144 
150  PQNode<T, X, Y>* getEndmost(SibDirection side) const {
151  if (side == SibDirection::Left || side == SibDirection::NoDir) {
152  return m_leftEndmost;
153  } else if (side == SibDirection::Right) {
154  return m_rightEndmost;
155  }
156 
157  return nullptr;
158  }
159 
162 
168  PQNode<T, X, Y>* getSib(SibDirection side) const {
169  if (side == SibDirection::Left) {
170  return m_sibLeft;
171  } else if (side == SibDirection::Right) {
172  return m_sibRight;
173  }
174 
175  return nullptr;
176  }
177 
188  if (m_sibLeft != other) {
189  return m_sibLeft;
190  } else if (m_sibRight != other) {
191  return m_sibRight;
192  }
193 
194  return nullptr;
195  }
196 
199 
201  int childCount() const { return m_childCount; }
202 
204  void childCount(int count) { m_childCount = count; }
205 
213  PQNode<T, X, Y>* parent() const { return m_parent; }
214 
222  PQNode<T, X, Y>* parent(PQNode<T, X, Y>* newParent) { return m_parent = newParent; }
223 
225  PQNodeType parentType() const { return m_parentType; }
226 
231  void parentType(PQNodeType newParentType) { m_parentType = newParentType; }
232 
234  int pertChildCount() const { return m_pertChildCount; }
235 
237  void pertChildCount(int count) { m_pertChildCount = count; }
238 
252  SibDirection putSibling(PQNode<T, X, Y>* newSib) {
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 
279  SibDirection putSibling(PQNode<T, X, Y>* newSib, SibDirection preference) {
280  if (preference == SibDirection::Left) {
281  return putSibling(newSib);
282  }
283 
284  OGDF_ASSERT(preference == SibDirection::Right);
285 
286  if (m_sibRight == nullptr) {
287  m_sibRight = newSib;
288  return SibDirection::Right;
289  }
290 
291  OGDF_ASSERT(m_sibLeft == nullptr);
292  m_sibLeft = newSib;
293  return SibDirection::Left;
294  }
295 
298 
301 
303  bool setNodeInfo(PQNodeKey<T, X, Y>* pointerToInfo) {
304  m_pointerToInfo = pointerToInfo;
305  if (pointerToInfo != nullptr) {
306  m_pointerToInfo->setNodePointer(this);
307  return true;
308  }
309 
310  return false;
311  }
312 
319  virtual PQLeafKey<T, X, Y>* getKey() const = 0;
320 
322 
334  virtual bool setKey(PQLeafKey<T, X, Y>* pointerToKey) = 0;
335 
343  virtual PQInternalKey<T, X, Y>* getInternal() const = 0;
344 
345  /*
346  * setInternal() sets a specified pointer variable in a derived class
347  * to the specified adress of \p pointerToInternal that is of type
348  * PQInternalKey.
349  *
350  * If a derived class, such as PQLeaf,
351  * is not supposed to store informations of type PQInternalKey,
352  * setInternal() ignores the informations as long as
353  * \p pointerToInternal = 0. The return value then is 1.
354  * In case that \p pointerToInternal != 0, the return value is 0.
355  *
356  * If a derived class, such as PQInternalNode is
357  * supposed to store informations of type PQInternalKey,
358  * \p pointerToInternal has to be instantiated by the client. The
359  * function setInternal() does
360  * not instantiate the corresponding variable in the derived class.
361  * The return value is always 1 unless \p pointerInternal was
362  * equal to 0.
363  */
364  virtual bool setInternal(PQInternalKey<T, X, Y>* pointerToInternal) = 0;
365 
373  virtual PQNodeMark mark() const = 0;
374 
376  virtual void mark(PQNodeMark) = 0;
377 
379 
389  virtual PQNodeStatus status() const = 0;
390 
392  virtual void status(PQNodeStatus) = 0;
393 
395 
404  virtual PQNodeType type() const = 0;
405 
407  virtual void type(PQNodeType) = 0;
408 
409 
410 protected:
411  // Stores the number of children of the node.
413 
421 
434 
436  PQNodeType m_parentType;
437 
440 
443 
446 
448 
455 
463 
471 
474 
483 
492 
495 
496 
499 
502 };
503 
504 /*
505 The function [[changeEndmost]] replaces the old endmost child [[oldEnd]] of
506 the node by a new child [[newEnd]].
507 If the node is a $Q$-node, then it must have two valid
508 pointers to its endmost children. If one of the endmost children is [[oldEnd]],
509 it is replaced by [[newEnd]].
510 The function [[changeEndmost]] returns [[1]] if it succeeded in
511 replacing [[oldEnd]] by [[newEnd]]. Otherwise the function returns
512 [[0]], leaving with an error message.
513 */
514 template<class T, class X, class Y>
516  if (m_leftEndmost == oldEnd) {
517  m_leftEndmost = newEnd;
518  return true;
519  } else if (m_rightEndmost == oldEnd) {
520  m_rightEndmost = newEnd;
521  return true;
522  }
523  return false;
524 }
525 
526 /*
527 The function [[changeSiblings]] replaces the old sibling [[oldSib]] of the
528 node by a new sibling [[newSib]].
529 
530 If the node has [[oldSib]] as sibling, then it changes the
531 sibling pointer that references to [[oldSib]] and places [[newSib]]
532 at its position.
533 
534 The function [[changeSiblings]] returns [[1]] if it succeeded in replacing
535 [[oldSib]] by [[newSib]]. Otherwise the function returns
536 [[0]], leaving with an error message.
537 */
538 template<class T, class X, class Y>
540  if (m_sibLeft == oldSib) {
541  m_sibLeft = newSib;
542  return true;
543  } else if (m_sibRight == oldSib) {
544  m_sibRight = newSib;
545  return true;
546  }
547  return false;
548 }
549 
550 /*
551 The (first) constructor combines the node with its information and
552 will automatically set the [[m_nodePointer]] (see \ref{basicKey}) of
553 the element of type [[PQNodeKey]] (see \ref{PQNodeKey}).
554 */
555 template<class T, class X, class Y>
557  m_identificationNumber = count;
558  m_childCount = 0;
559  m_pertChildCount = 0;
560  m_pertLeafCount = 0;
561  m_debugTreeNumber = 0;
562  m_parentType = PQNodeType::Undefined;
563 
564  m_parent = nullptr;
565  m_firstFull = nullptr;
566  m_sibLeft = nullptr;
567  m_sibRight = nullptr;
568  m_referenceChild = nullptr;
569  m_referenceParent = nullptr;
570  m_leftEndmost = nullptr;
571  m_rightEndmost = nullptr;
572 
573  fullChildren = new List<PQNode<T, X, Y>*>;
574  partialChildren = new List<PQNode<T, X, Y>*>;
575 
576  m_pointerToInfo = infoPtr;
577  infoPtr->setNodePointer(this);
578 }
579 
580 /*
581 The (second) constructor is called,
582 if no information is available or neccessary.
583 */
584 template<class T, class X, class Y>
586  m_identificationNumber = count;
587  m_childCount = 0;
588  m_pertChildCount = 0;
589  m_pertLeafCount = 0;
590  m_debugTreeNumber = 0;
591  m_parentType = PQNodeType::Undefined;
592 
593  m_parent = nullptr;
594  m_firstFull = nullptr;
595  m_sibLeft = nullptr;
596  m_sibRight = nullptr;
597  m_referenceChild = nullptr;
598  m_referenceParent = nullptr;
599  m_leftEndmost = nullptr;
600  m_rightEndmost = nullptr;
601 
602  fullChildren = new List<PQNode<T, X, Y>*>;
603  partialChildren = new List<PQNode<T, X, Y>*>;
604 
605  m_pointerToInfo = nullptr;
606 }
607 
608 }
ogdf::PQNode::referenceChild
PQNode< T, X, Y > * referenceChild() const
Returns a pointer to the reference child if node is a P-node.
Definition: PQNode.h:297
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::PQNode::parentType
void parentType(PQNodeType newParentType)
Sets the type of the parent of a node.
Definition: PQNode.h:231
ogdf::PQNode::m_identificationNumber
int m_identificationNumber
Each node that has been introduced once into the tree gets a unique number.
Definition: PQNode.h:433
ogdf::PQNode::m_referenceChild
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:462
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::PQNode::getSib
PQNode< T, X, Y > * getSib(SibDirection side) const
The function getSib() returns one of the siblings of the node.
Definition: PQNode.h:168
ogdf::PQNode::fullChildren
List< PQNode< T, X, Y > * > * fullChildren
Stores all full children of a node during a reduction.
Definition: PQNode.h:498
ogdf::PQLeafKey
The class template PQLeafKey is a derived class of class template PQBasicKey.
Definition: PQInternalNode.h:40
ogdf::PQNode::setNodeInfo
bool setNodeInfo(PQNodeKey< T, X, Y > *pointerToInfo)
Sets the pointer m_pointerToInfo to the specified adress of pointerToInfo.
Definition: PQNode.h:303
ogdf::PQNode::m_referenceParent
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:470
ogdf::PQNode::mark
virtual PQNodeMark mark() const =0
mark() returns the variable PQLeaf::m_mark in the derived class PQLeaf and PQInternalNode.
ogdf::PQTree
Definition: PQNode.h:53
PQNodeRoot.h
Declaration and implementation of the class PQNodeRoot.
ogdf::PQNode::setInternal
virtual bool setInternal(PQInternalKey< T, X, Y > *pointerToInternal)=0
ogdf::PQNode::m_rightEndmost
PQNode< T, X, Y > * m_rightEndmost
Stores the right endmost child of a Q-node.
Definition: PQNode.h:473
ogdf::PQNode::m_sibLeft
PQNode< T, X, Y > * m_sibLeft
Stores a pointer ot the left sibling of PQNode.
Definition: PQNode.h:482
ogdf::PQInternalKey
The class template PQInternalKey is a derived class of class template PQBasicKey.
Definition: PQInternalKey.h:55
ogdf::PQNode::getKey
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...
ogdf::PQNode::getInternal
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 ...
ogdf::PQNode::pertChildCount
int pertChildCount() const
Returs the number of pertinent children of a node.
Definition: PQNode.h:234
ogdf::PQNode::childCount
void childCount(int count)
Sets the number of children of a node.
Definition: PQNode.h:204
ogdf::PQNode::getEndmost
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:150
ogdf::PQNode::partialChildren
List< PQNode< T, X, Y > * > * partialChildren
Stores all partial children of a node during a reduction.
Definition: PQNode.h:501
ogdf::PQNode::m_parentType
PQNodeType m_parentType
Stores the type of the parent which can be either a P- or Q-node.
Definition: PQNode.h:436
ogdf::PQNode::status
virtual PQNodeStatus status() const =0
Returns the variable PQLeaf::m_status in the derived class PQLeaf and PQInternalNode.
ogdf::PQNode::getNextSib
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:187
ogdf::PQNode::m_debugTreeNumber
int m_debugTreeNumber
Needed for debuging purposes.
Definition: PQNode.h:420
ogdf::PQNode::changeSiblings
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:539
ogdf::PQNode::getEndmost
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:135
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: DfsMakeBiconnected.h:40
ogdf::PQNode::putSibling
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:252
ogdf::PQNode::type
virtual PQNodeType type() const =0
Returns the variable PQInternalNode::m_type in the derived class PQLeaf and PQInternalNode.
ogdf::PQNodeKey
The class template PQNodeKey is a derived class of class template PQBasicKey.
Definition: PQInternalNode.h:42
ogdf::PQNode::m_pointerToInfo
PQNodeKey< T, X, Y > * m_pointerToInfo
Stores a pointer to the corresponding information of the node.
Definition: PQNode.h:494
ogdf::PQNode::pertChildCount
void pertChildCount(int count)
Sets the number of pertinent children of a node.
Definition: PQNode.h:237
ogdf::PQNode::~PQNode
virtual ~PQNode()
The destructor does not delete any accompanying information class as PQLeafKey, PQNodeKey and PQInter...
Definition: PQNode.h:89
ogdf::PQNode::getNodeInfo
PQNodeKey< T, X, Y > * getNodeInfo() const
Returns the identification number of a node.
Definition: PQNode.h:161
ogdf::PQNode::m_pertChildCount
int m_pertChildCount
Stores the number of pertinent children of the node.
Definition: PQNode.h:439
basic.h
Basic declarations, included by all source files.
ogdf::PQNode::m_pertLeafCount
int m_pertLeafCount
Stores the number of pertinent leaves in the frontier of the node.
Definition: PQNode.h:442
ogdf::PQNode::m_childCount
int m_childCount
Definition: PQNode.h:412
ogdf::PQNode::referenceParent
PQNode< T, X, Y > * referenceParent() const
Returns the pointer to the parent if node is a reference child.
Definition: PQNode.h:300
ogdf::PQNode::PQNode
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:556
ogdf::PQNode::setKey
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 ...
List.h
Declaration of doubly linked lists and iterators.
ogdf::PQNode::putSibling
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
ogdf::PQNode::identificationNumber
int identificationNumber() const
Returns the identification number of a node.
Definition: PQNode.h:198
ogdf::PQNode::parent
PQNode< T, X, Y > * parent(PQNode< T, X, Y > *newParent)
Sets the parent pointer of a node.
Definition: PQNode.h:222
ogdf::PQNode::m_leftEndmost
PQNode< T, X, Y > * m_leftEndmost
Definition: PQNode.h:447
ogdf::PQNode::endmostChild
bool endmostChild() const
The function endmostChild() checks if a node is endmost child of a Q-node.
Definition: PQNode.h:124
ogdf::PQNode::parentType
PQNodeType parentType() const
Returns the type of the parent of a node.
Definition: PQNode.h:225
ogdf::PQNode::m_firstFull
PQNode< T, X, Y > * m_firstFull
Stores a pointer to the first full child of a Q-node.
Definition: PQNode.h:445
ogdf::PQNode::childCount
int childCount() const
Returns the number of children of a node.
Definition: PQNode.h:201
ogdf::PQNode::m_sibRight
PQNode< T, X, Y > * m_sibRight
Stores a pointer ot the right sibling of PQNode.
Definition: PQNode.h:491
ogdf::PQNode::parent
PQNode< T, X, Y > * parent() const
The function parent() returns a pointer to the parent of a node.
Definition: PQNode.h:213
ogdf::PQNode::m_parent
PQNode< T, X, Y > * m_parent
Is a pointer to the parent.
Definition: PQNode.h:454
ogdf::PQNode::changeEndmost
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:515
ogdf::PQNode
The class template PQBasicKey is an abstract base class.
Definition: PQBasicKey.h:111
ogdf::PQNodeRoot
The class PQNodeRoot is used as a base class of the class PQNode.
Definition: PQNodeRoot.h:43