]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2750] Introduce getSibling() again as a static function
authorMukund Sivaraman <muks@isc.org>
Thu, 5 Sep 2013 14:25:41 +0000 (19:55 +0530)
committerMukund Sivaraman <muks@isc.org>
Thu, 5 Sep 2013 14:25:41 +0000 (19:55 +0530)
src/lib/datasrc/memory/domaintree.h

index add18fb0fc5114cbd8a5c5fc72cb2bafc4be367f..99607ca277160283e85509bdb7d3306ad650f7f6 100644 (file)
@@ -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<T>* getSibling(DomainTreeNode<T>* parent,
+                                         DomainTreeNode<T>* 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<T>::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<T>* sibling = (parent->getLeft() == child) ?
-            parent->getRight() : parent->getLeft();
+        DomainTreeNode<T>* sibling =
+            DomainTreeNode<T>::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<T>::removeRebalance
 
             // Re-compute child's sibling due to the tree adjustment
             // above.
-            sibling = (parent->getLeft() == child) ?
-                parent->getRight() : parent->getLeft();
+            sibling = DomainTreeNode<T>::getSibling(parent, child);
         }
 
         // NOTE #3: sibling still cannot be NULL here as parent--child
@@ -2767,8 +2784,7 @@ DomainTree<T>::removeRebalance
             }
             // Re-compute child's sibling due to the tree adjustment
             // above.
-            sibling = (parent->getLeft() == child) ?
-                parent->getRight() : parent->getLeft();
+            sibling = DomainTreeNode<T>::getSibling(parent, child);
         }
 
         // NOTE #7: sibling cannot be NULL here as even if the sibling