From: Mukund Sivaraman Date: Thu, 5 Sep 2013 14:25:41 +0000 (+0530) Subject: [2750] Introduce getSibling() again as a static function X-Git-Tag: bind10-1.2.0beta1-release~193^2~4^2~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=05b3886971fb003b0bbd735975bbbf0c38a1970c;p=thirdparty%2Fkea.git [2750] Introduce getSibling() again as a static function --- diff --git a/src/lib/datasrc/memory/domaintree.h b/src/lib/datasrc/memory/domaintree.h index add18fb0fc..99607ca277 100644 --- a/src/lib/datasrc/memory/domaintree.h +++ b/src/lib/datasrc/memory/domaintree.h @@ -584,6 +584,24 @@ private: } } + /// \brief Access sibling node as bare pointer. + /// + /// A sibling node is defined as the parent's other child. It exists + /// at the same level as child. Note that child can be NULL here, + /// which is why this is a static function. + /// + /// \return the sibling node if one exists, NULL otherwise. + static DomainTreeNode* getSibling(DomainTreeNode* parent, + DomainTreeNode* child) + { + if (!parent) { + return (NULL); + } + + return ((parent->getLeft() == child) ? + parent->getRight() : parent->getLeft()); + } + /// \brief Access uncle node as bare pointer. /// /// An uncle node is defined as the parent node's sibling. It exists @@ -2582,8 +2600,8 @@ DomainTree::removeRebalance // A sibling node is defined as the parent's other child. It // exists at the same level as child. Note that child can be // NULL here. - DomainTreeNode* sibling = (parent->getLeft() == child) ? - parent->getRight() : parent->getLeft(); + DomainTreeNode* sibling = + DomainTreeNode::getSibling(parent, child); // NOTE #1: Understand this clearly. We are here only because in // the path through parent--child, a BLACK node was removed, @@ -2629,8 +2647,7 @@ DomainTree::removeRebalance // Re-compute child's sibling due to the tree adjustment // above. - sibling = (parent->getLeft() == child) ? - parent->getRight() : parent->getLeft(); + sibling = DomainTreeNode::getSibling(parent, child); } // NOTE #3: sibling still cannot be NULL here as parent--child @@ -2767,8 +2784,7 @@ DomainTree::removeRebalance } // Re-compute child's sibling due to the tree adjustment // above. - sibling = (parent->getLeft() == child) ? - parent->getRight() : parent->getLeft(); + sibling = DomainTreeNode::getSibling(parent, child); } // NOTE #7: sibling cannot be NULL here as even if the sibling