]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2092] Use isSubTreeRoot() instead of comparing with NULLNODE
authorMukund Sivaraman <muks@isc.org>
Tue, 24 Jul 2012 06:03:34 +0000 (11:33 +0530)
committerMukund Sivaraman <muks@isc.org>
Tue, 24 Jul 2012 06:03:34 +0000 (11:33 +0530)
src/lib/datasrc/rbtree.h

index 2ea63442f29501f7652b722734ddf68ed58d0bb4..6768b5939d97afd65f3008395df06fd0ef1c39de 100644 (file)
@@ -466,12 +466,17 @@ RBNode<T>::abstractSuccessor(typename RBNode<T>::RBNodePtr RBNode<T>::*left,
     // root.  If found, the parent of the branch is the successor.
     // Otherwise, we return the null node
     const RBNode<T>* parent = current->getParent();
-    while (parent != RBNode<T>::NULL_NODE() &&
-           current == (parent->*right).get()) {
+    while ((!current->isSubTreeRoot()) &&
+           (current == (parent->*right).get())) {
         current = parent;
         parent = parent->getParent();
     }
-    return (parent);
+
+    if (!current->isSubTreeRoot()) {
+        return (parent);
+    } else {
+        return (RBNode<T>::NULL_NODE());
+    }
 }
 
 template <typename T>
@@ -1596,7 +1601,7 @@ RBTree<T>::leftRotate(typename RBNode<T>::RBNodePtr* root, RBNode<T>* node) {
     RBNode<T>* const parent = node->getParent();
     right->parent_ = parent;
 
-    if (parent != NULLNODE) {
+    if (!node->isSubTreeRoot()) {
         right->setSubTreeRoot(false);
         if (node == parent->getLeft()) {
             parent->left_ = right;
@@ -1627,7 +1632,7 @@ RBTree<T>::rightRotate(typename RBNode<T>::RBNodePtr* root, RBNode<T>* node) {
     RBNode<T>* const parent = node->getParent();
     left->parent_ = parent;
 
-    if (node->getParent() != NULLNODE) {
+    if (!node->isSubTreeRoot()) {
         left->setSubTreeRoot(false);
         if (node == parent->getRight()) {
             parent->right_ = left;