BIND 10 master, updated. 862b15fc77654a9baf86106b26932335a50e22c4 [2182] Simplify code further
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Aug 3 13:47:58 UTC 2012
The branch, master has been updated
via 862b15fc77654a9baf86106b26932335a50e22c4 (commit)
via 823c4a966326683eb0065cffe8fa2e219662d6a7 (commit)
from b76e8206e2589ddda552c8162be4beca5b390059 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 862b15fc77654a9baf86106b26932335a50e22c4
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Aug 3 12:35:13 2012 +0530
[2182] Simplify code further
commit 823c4a966326683eb0065cffe8fa2e219662d6a7
Author: Mukund Sivaraman <muks at isc.org>
Date: Fri Aug 3 12:18:15 2012 +0530
[2182] Simplify RBTree::deleteHelper() and also make it non-recursive
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/rbtree.h | 47 +++++++++++++++++++++-------------------------
1 file changed, 21 insertions(+), 26 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/rbtree.h b/src/lib/datasrc/rbtree.h
index 4f15b0e..2ec5347 100644
--- a/src/lib/datasrc/rbtree.h
+++ b/src/lib/datasrc/rbtree.h
@@ -1345,35 +1345,30 @@ RBTree<T>::~RBTree() {
template <typename T>
void
RBTree<T>::deleteHelper(util::MemorySegment& mem_sgmt, RBNode<T>* root) {
- if (root == NULL) {
- return;
- }
-
- RBNode<T>* node = root;
- while (root->getLeft() != NULL || root->getRight() != NULL) {
- RBNode<T>* left(NULL);
- RBNode<T>* right(NULL);
- while ((left = node->getLeft()) != NULL ||
- (right = node->getRight()) != NULL) {
- node = (left != NULL) ? left : right;
- }
-
- RBNode<T>* parent = node->getParent();
- if (parent->getLeft() == node) {
- parent->left_ = NULL;
+ while (root != NULL) {
+ // If there is a left, right or down node, walk into it and
+ // iterate.
+ if (root->getLeft() != NULL) {
+ RBNode<T>* node = root;
+ root = root->getLeft();
+ node->left_ = NULL;
+ } else if (root->getRight() != NULL) {
+ RBNode<T>* node = root;
+ root = root->getRight();
+ node->right_ = NULL;
+ } else if (root->getDown() != NULL) {
+ RBNode<T>* node = root;
+ root = root->getDown();
+ node->down_ = NULL;
} else {
- parent->right_ = NULL;
+ // There are no left, right or down nodes, so we can
+ // free this one and go back to its parent.
+ RBNode<T>* node = root;
+ root = root->getParent();
+ RBNode<T>::destroy(mem_sgmt, node);
+ --node_count_;
}
-
- deleteHelper(mem_sgmt, node->getDown());
- RBNode<T>::destroy(mem_sgmt, node);
- --node_count_;
- node = parent;
}
-
- deleteHelper(mem_sgmt, root->getDown());
- RBNode<T>::destroy(mem_sgmt, root);
- --node_count_;
}
template <typename T>
More information about the bind10-changes
mailing list