Loading [MathJax]/extensions/tex2jax.js

Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
PQNode.h
Go to the documentation of this file.
1
38#pragma once
39
40#include <ogdf/basic/List.h>
42
43namespace ogdf {
44
45template<class T, class X, class Y>
46class PQTree;
47template<class T, class X, class Y>
48class PQLeafKey;
49template<class T, class X, class Y>
50class PQNodeKey;
51template<class T, class X, class Y>
52class PQInternalKey;
53
54template<class T, class X, class Y>
55class PQNode : public PQNodeRoot {
62 friend class PQTree<T, X, Y>;
63
64public:
71
72
77 explicit PQNode(int count);
78
88 virtual ~PQNode() {
89 delete fullChildren;
90 delete partialChildren;
91 }
92
104
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
151 return m_leftEndmost;
152 } else if (side == SibDirection::Right) {
153 return m_rightEndmost;
154 }
155
156 return nullptr;
157 }
158
161
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
204
212 PQNode<T, X, Y>* parent() const { return m_parent; }
213
222
225
231
233 int pertChildCount() const { return m_pertChildCount; }
234
237
252 if (m_sibLeft == nullptr) {
254 return SibDirection::Left;
255 }
256
257 OGDF_ASSERT(m_sibRight == nullptr);
259 return SibDirection::Right;
260 }
261
280 return putSibling(newSib);
281 }
282
284
285 if (m_sibRight == nullptr) {
287 return SibDirection::Right;
288 }
289
290 OGDF_ASSERT(m_sibLeft == nullptr);
292 return SibDirection::Left;
293 }
294
297
300
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
334
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 */
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
409protected:
410 // Stores the number of children of the node.
412
420
433
436
439
442
445
447
454
462
470
473
482
491
494
495
498
501};
502
503/*
504The function [[changeEndmost]] replaces the old endmost child [[oldEnd]] of
505the node by a new child [[newEnd]].
506If the node is a $Q$-node, then it must have two valid
507pointers to its endmost children. If one of the endmost children is [[oldEnd]],
508it is replaced by [[newEnd]].
509The function [[changeEndmost]] returns [[1]] if it succeeded in
510replacing [[oldEnd]] by [[newEnd]]. Otherwise the function returns
511[[0]], leaving with an error message.
512*/
513template<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/*
526The function [[changeSiblings]] replaces the old sibling [[oldSib]] of the
527node by a new sibling [[newSib]].
528
529If the node has [[oldSib]] as sibling, then it changes the
530sibling pointer that references to [[oldSib]] and places [[newSib]]
531at its position.
532
533The 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*/
537template<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/*
550The (first) constructor combines the node with its information and
551will automatically set the [[m_nodePointer]] (see \ref{basicKey}) of
552the element of type [[PQNodeKey]] (see \ref{PQNodeKey}).
553*/
554template<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/*
580The (second) constructor is called,
581if no information is available or neccessary.
582*/
583template<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}
Declaration of doubly linked lists and iterators.
Declaration and implementation of the class PQNodeRoot.
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
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:87
The class template PQBasicKey is an abstract base class.
Definition PQNode.h:55
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:302
PQNode< T, X, Y > * referenceParent() const
Returns the pointer to the parent if node is a reference child.
Definition PQNode.h:299
PQNodeKey< T, X, Y > * getNodeInfo() const
Returns the identification number of a node.
Definition PQNode.h:160
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
PQNodeType m_parentType
Stores the type of the parent which can be either a P- or Q-node.
Definition PQNode.h:435
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
PQNode(int count)
The (second) constructor is called, if no information is available or neccessary.
Definition PQNode.h:584
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
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:203
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
void pertChildCount(int count)
Sets the number of pertinent children of a node.
Definition PQNode.h:236
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
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
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
void parentType(PQNodeType newParentType)
Sets the type of the parent of a node.
Definition PQNode.h:230
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:432
PQNode< T, X, Y > * referenceChild() const
Returns a pointer to the reference child if node is a P-node.
Definition PQNode.h:296
PQNode< T, X, Y > * m_rightEndmost
Stores the right endmost child of a Q-node.
Definition PQNode.h:472
int childCount() const
Returns the number of children of a node.
Definition PQNode.h:200
PQNode< T, X, Y > * m_sibLeft
Stores a pointer ot the left sibling of PQNode.
Definition PQNode.h:481
PQNode< T, X, Y > * m_leftEndmost
Definition PQNode.h:446
virtual ~PQNode()
The destructor does not delete any accompanying information class as PQLeafKey, PQNodeKey and PQInter...
Definition PQNode.h:88
int identificationNumber() const
Returns the identification number of a node.
Definition PQNode.h:197
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
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:493
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
PQNode< T, X, Y > * m_firstFull
Stores a pointer to the first full child of a Q-node.
Definition PQNode.h:444
List< PQNode< T, X, Y > * > * fullChildren
Stores all full children of a node during a reduction.
Definition PQNode.h:497
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:441
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
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:453
PQNode< T, X, Y > * getSib(SibDirection side) const
The function getSib() returns one of the siblings of the node.
Definition PQNode.h:167
List< PQNode< T, X, Y > * > * partialChildren
Stores all partial children of a node during a reduction.
Definition PQNode.h:500
PQNodeType parentType() const
Returns the type of the parent of a node.
Definition PQNode.h:224
PQNode< T, X, Y > * m_sibRight
Stores a pointer ot the right sibling of PQNode.
Definition PQNode.h:490
int m_pertChildCount
Stores the number of pertinent children of the node.
Definition PQNode.h:438
int m_debugTreeNumber
Needed for debuging purposes.
Definition PQNode.h:419
int m_childCount
Definition PQNode.h:411
PQNode< T, X, Y > * parent() const
The function parent() returns a pointer to the parent of a node.
Definition PQNode.h:212
int pertChildCount() const
Returs the number of pertinent children of a node.
Definition PQNode.h:233
bool endmostChild() const
The function endmostChild() checks if a node is endmost child of a Q-node.
Definition PQNode.h:123
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:221
The class template PQNodeKey is a derived class of class template PQBasicKey.
Definition PQNodeKey.h:57
The class PQNodeRoot is used as a base class of the class PQNode.
Definition PQNodeRoot.h:44
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.