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>
42 
43 namespace ogdf {
44 
45 template<class T, class X, class Y>
46 class PQTree;
47 template<class T, class X, class Y>
48 class PQLeafKey;
49 template<class T, class X, class Y>
50 class PQNodeKey;
51 template<class T, class X, class Y>
52 class PQInternalKey;
53 
54 template<class T, class X, class Y>
55 class PQNode : public PQNodeRoot {
62  friend class PQTree<T, X, Y>;
63 
64 public:
70  PQNode(int count, PQNodeKey<T, X, Y>* infoPtr);
71 
72 
77  explicit PQNode(int count);
78 
88  virtual ~PQNode() {
89  delete fullChildren;
90  delete partialChildren;
91  }
92 
103  bool changeEndmost(PQNode<T, X, Y>* oldEnd, PQNode<T, X, Y>* newEnd);
104 
115  bool changeSiblings(PQNode<T, X, Y>* oldSib, PQNode<T, X, Y>* newSib);
116 
123  bool endmostChild() const { return m_sibLeft == nullptr || m_sibRight == nullptr; }
124 
135  if (m_leftEndmost != other) {
136  return m_leftEndmost;
137  } else if (m_rightEndmost != other) {
138  return m_rightEndmost;
139  }
140 
141  return nullptr;
142  }
143 
149  PQNode<T, X, Y>* getEndmost(SibDirection side) const {
150  if (side == SibDirection::Left || side == SibDirection::NoDir) {
151  return m_leftEndmost;
152  } else if (side == SibDirection::Right) {
153  return m_rightEndmost;
154  }
155 
156  return nullptr;
157  }
158 
161 
167  PQNode<T, X, Y>* getSib(SibDirection side) const {
168  if (side == SibDirection::Left) {
169  return m_sibLeft;
170  } else if (side == SibDirection::Right) {
171  return m_sibRight;
172  }
173 
174  return nullptr;
175  }
176 
187  if (m_sibLeft != other) {
188  return m_sibLeft;
189  } else if (m_sibRight != other) {
190  return m_sibRight;
191  }
192 
193  return nullptr;
194  }
195 
198 
200  int childCount() const { return m_childCount; }
201 
203  void childCount(int count) { m_childCount = count; }
204 
212  PQNode<T, X, Y>* parent() const { return m_parent; }
213 
221  PQNode<T, X, Y>* parent(PQNode<T, X, Y>* newParent) { return m_parent = newParent; }
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 
251  SibDirection putSibling(PQNode<T, X, Y>* newSib) {
252  if (m_sibLeft == nullptr) {
253  m_sibLeft = newSib;
254  return SibDirection::Left;
255  }
256 
257  OGDF_ASSERT(m_sibRight == nullptr);
258  m_sibRight = newSib;
259  return SibDirection::Right;
260  }
261 
278  SibDirection putSibling(PQNode<T, X, Y>* newSib, SibDirection preference) {
279  if (preference == SibDirection::Left) {
280  return putSibling(newSib);
281  }
282 
283  OGDF_ASSERT(preference == SibDirection::Right);
284 
285  if (m_sibRight == nullptr) {
286  m_sibRight = newSib;
287  return SibDirection::Right;
288  }
289 
290  OGDF_ASSERT(m_sibLeft == nullptr);
291  m_sibLeft = newSib;
292  return SibDirection::Left;
293  }
294 
297 
300 
302  bool setNodeInfo(PQNodeKey<T, X, Y>* pointerToInfo) {
303  m_pointerToInfo = pointerToInfo;
304  if (pointerToInfo != nullptr) {
305  m_pointerToInfo->setNodePointer(this);
306  return true;
307  }
308 
309  return false;
310  }
311 
318  virtual PQLeafKey<T, X, Y>* getKey() const = 0;
319 
321 
333  virtual bool setKey(PQLeafKey<T, X, Y>* pointerToKey) = 0;
334 
342  virtual PQInternalKey<T, X, Y>* getInternal() const = 0;
343 
344  /*
345  * setInternal() sets a specified pointer variable in a derived class
346  * to the specified adress of \p pointerToInternal that is of type
347  * PQInternalKey.
348  *
349  * If a derived class, such as PQLeaf,
350  * is not supposed to store informations of type PQInternalKey,
351  * setInternal() ignores the informations as long as
352  * \p pointerToInternal = 0. The return value then is 1.
353  * In case that \p pointerToInternal != 0, the return value is 0.
354  *
355  * If a derived class, such as PQInternalNode is
356  * supposed to store informations of type PQInternalKey,
357  * \p pointerToInternal has to be instantiated by the client. The
358  * function setInternal() does
359  * not instantiate the corresponding variable in the derived class.
360  * The return value is always 1 unless \p pointerInternal was
361  * equal to 0.
362  */
363  virtual bool setInternal(PQInternalKey<T, X, Y>* pointerToInternal) = 0;
364 
372  virtual PQNodeMark mark() const = 0;
373 
375  virtual void mark(PQNodeMark) = 0;
376 
378 
388  virtual PQNodeStatus status() const = 0;
389 
391  virtual void status(PQNodeStatus) = 0;
392 
394 
403  virtual PQNodeType type() const = 0;
404 
406  virtual void type(PQNodeType) = 0;
407 
408 
409 protected:
410  // Stores the number of children of the node.
412 
420 
433 
435  PQNodeType m_parentType;
436 
439 
442 
445 
447 
454 
462 
470 
473 
482 
491 
494 
495 
498 
501 };
502 
503 /*
504 The function [[changeEndmost]] replaces the old endmost child [[oldEnd]] of
505 the node by a new child [[newEnd]].
506 If the node is a $Q$-node, then it must have two valid
507 pointers to its endmost children. If one of the endmost children is [[oldEnd]],
508 it is replaced by [[newEnd]].
509 The function [[changeEndmost]] returns [[1]] if it succeeded in
510 replacing [[oldEnd]] by [[newEnd]]. Otherwise the function returns
511 [[0]], leaving with an error message.
512 */
513 template<class T, class X, class Y>
515  if (m_leftEndmost == oldEnd) {
516  m_leftEndmost = newEnd;
517  return true;
518  } else if (m_rightEndmost == oldEnd) {
519  m_rightEndmost = newEnd;
520  return true;
521  }
522  return false;
523 }
524 
525 /*
526 The function [[changeSiblings]] replaces the old sibling [[oldSib]] of the
527 node by a new sibling [[newSib]].
528 
529 If the node has [[oldSib]] as sibling, then it changes the
530 sibling pointer that references to [[oldSib]] and places [[newSib]]
531 at its position.
532 
533 The function [[changeSiblings]] returns [[1]] if it succeeded in replacing
534 [[oldSib]] by [[newSib]]. Otherwise the function returns
535 [[0]], leaving with an error message.
536 */
537 template<class T, class X, class Y>
539  if (m_sibLeft == oldSib) {
540  m_sibLeft = newSib;
541  return true;
542  } else if (m_sibRight == oldSib) {
543  m_sibRight = newSib;
544  return true;
545  }
546  return false;
547 }
548 
549 /*
550 The (first) constructor combines the node with its information and
551 will automatically set the [[m_nodePointer]] (see \ref{basicKey}) of
552 the element of type [[PQNodeKey]] (see \ref{PQNodeKey}).
553 */
554 template<class T, class X, class Y>
556  m_identificationNumber = count;
557  m_childCount = 0;
558  m_pertChildCount = 0;
559  m_pertLeafCount = 0;
560  m_debugTreeNumber = 0;
561  m_parentType = PQNodeType::Undefined;
562 
563  m_parent = nullptr;
564  m_firstFull = nullptr;
565  m_sibLeft = nullptr;
566  m_sibRight = nullptr;
567  m_referenceChild = nullptr;
568  m_referenceParent = nullptr;
569  m_leftEndmost = nullptr;
570  m_rightEndmost = nullptr;
571 
572  fullChildren = new List<PQNode<T, X, Y>*>;
573  partialChildren = new List<PQNode<T, X, Y>*>;
574 
575  m_pointerToInfo = infoPtr;
576  infoPtr->setNodePointer(this);
577 }
578 
579 /*
580 The (second) constructor is called,
581 if no information is available or neccessary.
582 */
583 template<class T, class X, class Y>
585  m_identificationNumber = count;
586  m_childCount = 0;
587  m_pertChildCount = 0;
588  m_pertLeafCount = 0;
589  m_debugTreeNumber = 0;
590  m_parentType = PQNodeType::Undefined;
591 
592  m_parent = nullptr;
593  m_firstFull = nullptr;
594  m_sibLeft = nullptr;
595  m_sibRight = nullptr;
596  m_referenceChild = nullptr;
597  m_referenceParent = nullptr;
598  m_leftEndmost = nullptr;
599  m_rightEndmost = nullptr;
600 
601  fullChildren = new List<PQNode<T, X, Y>*>;
602  partialChildren = new List<PQNode<T, X, Y>*>;
603 
604  m_pointerToInfo = nullptr;
605 }
606 
607 }
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:296
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::PQNode::parentType
void parentType(PQNodeType newParentType)
Sets the type of the parent of a node.
Definition: PQNode.h:230
ogdf::PQNode::m_identificationNumber
int m_identificationNumber
Each node that has been introduced once into the tree gets a unique number.
Definition: PQNode.h:432
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:461
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
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:167
ogdf::PQNode::fullChildren
List< PQNode< T, X, Y > * > * fullChildren
Stores all full children of a node during a reduction.
Definition: PQNode.h:497
ogdf::PQLeafKey
The class template PQLeafKey is a derived class of class template PQBasicKey.
Definition: PQLeafKey.h:87
ogdf::PQNode::setNodeInfo
bool setNodeInfo(PQNodeKey< T, X, Y > *pointerToInfo)
Sets the pointer m_pointerToInfo to the specified adress of pointerToInfo.
Definition: PQNode.h:302
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:469
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:46
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:472
ogdf::PQNode::m_sibLeft
PQNode< T, X, Y > * m_sibLeft
Stores a pointer ot the left sibling of PQNode.
Definition: PQNode.h:481
ogdf::PQInternalKey
The class template PQInternalKey is a derived class of class template PQBasicKey.
Definition: PQInternalKey.h:58
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:233
ogdf::PQNode::childCount
void childCount(int count)
Sets the number of children of a node.
Definition: PQNode.h:203
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:149
ogdf::PQNode::partialChildren
List< PQNode< T, X, Y > * > * partialChildren
Stores all partial children of a node during a reduction.
Definition: PQNode.h:500
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:435
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:186
ogdf::PQNode::m_debugTreeNumber
int m_debugTreeNumber
Needed for debuging purposes.
Definition: PQNode.h:419
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:538
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:134
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: List.h:42
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:251
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: PQNode.h:50
ogdf::PQNode::m_pointerToInfo
PQNodeKey< T, X, Y > * m_pointerToInfo
Stores a pointer to the corresponding information of the node.
Definition: PQNode.h:493
ogdf::PQNode::pertChildCount
void pertChildCount(int count)
Sets the number of pertinent children of a node.
Definition: PQNode.h:236
ogdf::PQNode::~PQNode
virtual ~PQNode()
The destructor does not delete any accompanying information class as PQLeafKey, PQNodeKey and PQInter...
Definition: PQNode.h:88
ogdf::PQNode::getNodeInfo
PQNodeKey< T, X, Y > * getNodeInfo() const
Returns the identification number of a node.
Definition: PQNode.h:160
ogdf::PQNode::m_pertChildCount
int m_pertChildCount
Stores the number of pertinent children of the node.
Definition: PQNode.h:438
ogdf::PQNode::m_pertLeafCount
int m_pertLeafCount
Stores the number of pertinent leaves in the frontier of the node.
Definition: PQNode.h:441
ogdf::PQNode::m_childCount
int m_childCount
Definition: PQNode.h:411
ogdf::PQNode::referenceParent
PQNode< T, X, Y > * referenceParent() const
Returns the pointer to the parent if node is a reference child.
Definition: PQNode.h:299
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:555
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:278
ogdf::PQNode::identificationNumber
int identificationNumber() const
Returns the identification number of a node.
Definition: PQNode.h:197
ogdf::PQNode::parent
PQNode< T, X, Y > * parent(PQNode< T, X, Y > *newParent)
Sets the parent pointer of a node.
Definition: PQNode.h:221
ogdf::PQNode::m_leftEndmost
PQNode< T, X, Y > * m_leftEndmost
Definition: PQNode.h:446
ogdf::PQNode::endmostChild
bool endmostChild() const
The function endmostChild() checks if a node is endmost child of a Q-node.
Definition: PQNode.h:123
ogdf::PQNode::parentType
PQNodeType parentType() const
Returns the type of the parent of a node.
Definition: PQNode.h:224
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:444
ogdf::PQNode::childCount
int childCount() const
Returns the number of children of a node.
Definition: PQNode.h:200
ogdf::PQNode::m_sibRight
PQNode< T, X, Y > * m_sibRight
Stores a pointer ot the right sibling of PQNode.
Definition: PQNode.h:490
ogdf::PQNode::parent
PQNode< T, X, Y > * parent() const
The function parent() returns a pointer to the parent of a node.
Definition: PQNode.h:212
ogdf::PQNode::m_parent
PQNode< T, X, Y > * m_parent
Is a pointer to the parent.
Definition: PQNode.h:453
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:514
ogdf::PQNode
The class template PQBasicKey is an abstract base class.
Definition: PQBasicKey.h:109
ogdf::PQNodeRoot
The class PQNodeRoot is used as a base class of the class PQNode.
Definition: PQNodeRoot.h:44