Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
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
44namespace ogdf {
45
46template<class T, class X, class Y>
47class PQInternalKey;
48template<class T, class X, class Y>
49class PQLeafKey;
50template<class T, class X, class Y>
51class PQNodeKey;
52template<class T, class X, class Y>
53class PQTree;
54
55template<class T, class X, class Y>
56class PQNode : public PQNodeRoot {
63 friend class PQTree<T, X, Y>;
64
65public:
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
105
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
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
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
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
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 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) {
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
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
410protected:
411 // Stores the number of children of the node.
413
421
434
437
440
443
446
448
455
463
471
474
483
492
495
496
499
502};
503
504/*
505The function [[changeEndmost]] replaces the old endmost child [[oldEnd]] of
506the node by a new child [[newEnd]].
507If the node is a $Q$-node, then it must have two valid
508pointers to its endmost children. If one of the endmost children is [[oldEnd]],
509it is replaced by [[newEnd]].
510The function [[changeEndmost]] returns [[1]] if it succeeded in
511replacing [[oldEnd]] by [[newEnd]]. Otherwise the function returns
512[[0]], leaving with an error message.
513*/
514template<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/*
527The function [[changeSiblings]] replaces the old sibling [[oldSib]] of the
528node by a new sibling [[newSib]].
529
530If the node has [[oldSib]] as sibling, then it changes the
531sibling pointer that references to [[oldSib]] and places [[newSib]]
532at its position.
533
534The 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*/
538template<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/*
551The (first) constructor combines the node with its information and
552will automatically set the [[m_nodePointer]] (see \ref{basicKey}) of
553the element of type [[PQNodeKey]] (see \ref{PQNodeKey}).
554*/
555template<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/*
581The (second) constructor is called,
582if no information is available or neccessary.
583*/
584template<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}
Declaration of doubly linked lists and iterators.
Declaration and implementation of the class PQNodeRoot.
Basic declarations, included by all source files.
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
void setNodePointer(PQNode< T, X, Y > *pqNode)
The function setNodePointer() sets the private member m_nodePointer.
Definition PQBasicKey.h:156
The class template PQInternalKey is a derived class of class template PQBasicKey.
The class template PQLeafKey is a derived class of class template PQBasicKey.
Definition PQLeafKey.h:84
The class template PQBasicKey is an abstract base class.
Definition PQNode.h:56
virtual void mark(PQNodeMark)=0
mark() sets the variable PQLeaf::m_mark in the derived class PQLeaf and PQInternalNode.
virtual PQNodeType type() const =0
Returns the variable PQInternalNode::m_type in the derived class PQLeaf and PQInternalNode.
bool setNodeInfo(PQNodeKey< T, X, Y > *pointerToInfo)
Sets the pointer m_pointerToInfo to the specified adress of pointerToInfo.
Definition PQNode.h:303
PQNode< T, X, Y > * referenceParent() const
Returns the pointer to the parent if node is a reference child.
Definition PQNode.h:300
PQNodeKey< T, X, Y > * getNodeInfo() const
Returns the identification number of a node.
Definition PQNode.h:161
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
PQNodeType m_parentType
Stores the type of the parent which can be either a P- or Q-node.
Definition PQNode.h:436
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
PQNode(int count)
The (second) constructor is called, if no information is available or neccessary.
Definition PQNode.h:585
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
virtual PQNodeStatus status() const =0
Returns the variable PQLeaf::m_status in the derived class PQLeaf and PQInternalNode.
void childCount(int count)
Sets the number of children of a node.
Definition PQNode.h:204
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
void pertChildCount(int count)
Sets the number of pertinent children of a node.
Definition PQNode.h:237
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
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
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
void parentType(PQNodeType newParentType)
Sets the type of the parent of a node.
Definition PQNode.h:231
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_identificationNumber
Each node that has been introduced once into the tree gets a unique number.
Definition PQNode.h:433
PQNode< T, X, Y > * referenceChild() const
Returns a pointer to the reference child if node is a P-node.
Definition PQNode.h:297
PQNode< T, X, Y > * m_rightEndmost
Stores the right endmost child of a Q-node.
Definition PQNode.h:473
int childCount() const
Returns the number of children of a node.
Definition PQNode.h:201
PQNode< T, X, Y > * m_sibLeft
Stores a pointer ot the left sibling of PQNode.
Definition PQNode.h:482
PQNode< T, X, Y > * m_leftEndmost
Definition PQNode.h:447
virtual ~PQNode()
The destructor does not delete any accompanying information class as PQLeafKey, PQNodeKey and PQInter...
Definition PQNode.h:89
int identificationNumber() const
Returns the identification number of a node.
Definition PQNode.h:198
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
virtual bool setInternal(PQInternalKey< T, X, Y > *pointerToInternal)=0
PQNodeKey< T, X, Y > * m_pointerToInfo
Stores a pointer to the corresponding information of the node.
Definition PQNode.h:494
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
PQNode< T, X, Y > * m_firstFull
Stores a pointer to the first full child of a Q-node.
Definition PQNode.h:445
List< PQNode< T, X, Y > * > * fullChildren
Stores all full children of a node during a reduction.
Definition PQNode.h:498
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.
virtual void status(PQNodeStatus)=0
Sets the variable PQLeaf::m_status in the derived class PQLeaf and PQInternalNode.
int m_pertLeafCount
Stores the number of pertinent leaves in the frontier of the node.
Definition PQNode.h:442
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
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 ...
PQNode< T, X, Y > * m_parent
Is a pointer to the parent.
Definition PQNode.h:454
PQNode< T, X, Y > * getSib(SibDirection side) const
The function getSib() returns one of the siblings of the node.
Definition PQNode.h:168
List< PQNode< T, X, Y > * > * partialChildren
Stores all partial children of a node during a reduction.
Definition PQNode.h:501
PQNodeType parentType() const
Returns the type of the parent of a node.
Definition PQNode.h:225
PQNode< T, X, Y > * m_sibRight
Stores a pointer ot the right sibling of PQNode.
Definition PQNode.h:491
int m_pertChildCount
Stores the number of pertinent children of the node.
Definition PQNode.h:439
int m_debugTreeNumber
Needed for debuging purposes.
Definition PQNode.h:420
int m_childCount
Definition PQNode.h:412
PQNode< T, X, Y > * parent() const
The function parent() returns a pointer to the parent of a node.
Definition PQNode.h:213
int pertChildCount() const
Returs the number of pertinent children of a node.
Definition PQNode.h:234
bool endmostChild() const
The function endmostChild() checks if a node is endmost child of a Q-node.
Definition PQNode.h:124
virtual void type(PQNodeType)=0
Sets the variable PQInternalNode::m_type in the derived class PQLeaf and PQInternalNode.
PQNode< T, X, Y > * parent(PQNode< T, X, Y > *newParent)
Sets the parent pointer of a node.
Definition PQNode.h:222
The class template PQNodeKey is a derived class of class template PQBasicKey.
Definition PQNodeKey.h:54
The class PQNodeRoot is used as a base class of the class PQNode.
Definition PQNodeRoot.h:43
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.