|
@@ -53,7 +53,7 @@ RBNode*
|
|
RBNode::successor() {
|
|
RBNode::successor() {
|
|
RBNode* current = this;
|
|
RBNode* current = this;
|
|
|
|
|
|
- /// if has right node, the successor is the left-most node
|
|
|
|
|
|
+ // if it has right node, the successor is the left-most node
|
|
if (right_ != right_->right_) {
|
|
if (right_ != right_->right_) {
|
|
current = right_;
|
|
current = right_;
|
|
while (current->left_ != current->left_->left_) {
|
|
while (current->left_ != current->left_->left_) {
|
|
@@ -62,8 +62,8 @@ RBNode::successor() {
|
|
return (current);
|
|
return (current);
|
|
}
|
|
}
|
|
|
|
|
|
- /// otherwise return the parent without left child or
|
|
|
|
- /// current node isnot its right child
|
|
|
|
|
|
+ // otherwise return the parent without left child or
|
|
|
|
+ // current node is not its right child
|
|
RBNode* s = current->parent_;
|
|
RBNode* s = current->parent_;
|
|
while (s != s->left_ && current == s->right_) {
|
|
while (s != s->left_ && current == s->right_) {
|
|
current = s;
|
|
current = s;
|
|
@@ -96,8 +96,9 @@ RBNode::cloneDNSData(RBNode& node) {
|
|
void
|
|
void
|
|
RBNode::setDownTree(RBTree* down) {
|
|
RBNode::setDownTree(RBTree* down) {
|
|
down_ = down;
|
|
down_ = down;
|
|
- if (down)
|
|
|
|
|
|
+ if (down) {
|
|
down->up_ = this;
|
|
down->up_ = this;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -176,8 +177,7 @@ RBTree::findHelper(const Name& name, RBTree** tree, RBNode** ret) const {
|
|
*tree = (RBTree*)this;
|
|
*tree = (RBTree*)this;
|
|
*ret = node;
|
|
*ret = node;
|
|
return (RBTree::EXACTMATCH);
|
|
return (RBTree::EXACTMATCH);
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
int common_label_count = compare_result.getCommonLabels();
|
|
int common_label_count = compare_result.getCommonLabels();
|
|
// common label count equal one means, there is no common between
|
|
// common label count equal one means, there is no common between
|
|
// two names
|
|
// two names
|
|
@@ -417,13 +417,13 @@ RBTree::erase(const Name& name) {
|
|
return (1);
|
|
return (1);
|
|
}
|
|
}
|
|
|
|
|
|
- /// cannot delete non terminal
|
|
|
|
|
|
+ // cannot delete non terminal
|
|
if (node->down_ != NULL) {
|
|
if (node->down_ != NULL) {
|
|
return (1);
|
|
return (1);
|
|
}
|
|
}
|
|
|
|
|
|
tree->eraseNode(node);
|
|
tree->eraseNode(node);
|
|
- /// merge down to up
|
|
|
|
|
|
+ // merge down to up
|
|
if (tree->node_count_ == 1 && tree->up_ != NULL &&
|
|
if (tree->node_count_ == 1 && tree->up_ != NULL &&
|
|
tree->up_->isNonterminal()) {
|
|
tree->up_->isNonterminal()) {
|
|
RBNode* up = tree->up_;
|
|
RBNode* up = tree->up_;
|
|
@@ -464,7 +464,7 @@ RBTree::eraseNode(RBNode *node) {
|
|
|
|
|
|
if (y->parent_ == NULLNODE) {
|
|
if (y->parent_ == NULLNODE) {
|
|
root_ = x;
|
|
root_ = x;
|
|
- } else if ( y == y->parent_->left_ ) {
|
|
|
|
|
|
+ } else if (y == y->parent_->left_) {
|
|
y->parent_->left_ = x;
|
|
y->parent_->left_ = x;
|
|
} else {
|
|
} else {
|
|
y->parent_->right_ = x;
|
|
y->parent_->right_ = x;
|
|
@@ -549,11 +549,12 @@ RBTree::deleteRebalance(RBNode* node) {
|
|
node->color_ = BLACK;
|
|
node->color_ = BLACK;
|
|
}
|
|
}
|
|
|
|
|
|
-#define INDNET(depth) do{\
|
|
|
|
- int i = 0;\
|
|
|
|
- for (; i < (depth) * 5; ++i)\
|
|
|
|
- std::cout << " ";\
|
|
|
|
-}while(0)
|
|
|
|
|
|
+#define INDNET(depth) do { \
|
|
|
|
+ int i = 0; \
|
|
|
|
+ for (; i < (depth) * 5; ++i) { \
|
|
|
|
+ std::cout << " "; \
|
|
|
|
+ } \
|
|
|
|
+} while(0)
|
|
|
|
|
|
void
|
|
void
|
|
RBTree::printTree(int depth) const {
|
|
RBTree::printTree(int depth) const {
|