# HG changeset patch # User Shohei KOKUBO # Date 1447747188 -32400 # Node ID 7ad6d1502a03f5f7545dfee9d9254830f096c398 # Parent 97387904add94e7e77f65f1f82f7082caad85a96 refactoring diff -r 97387904add9 -r 7ad6d1502a03 src/llrb/llrb.c --- a/src/llrb/llrb.c Tue Nov 17 15:53:51 2015 +0900 +++ b/src/llrb/llrb.c Tue Nov 17 16:59:48 2015 +0900 @@ -14,14 +14,14 @@ stack_push(context->code_stack, &context->next); - if (tree->root == 0) { - goto meta(context, Insert); - } else { + if (tree->root) { tree->current = tree->root; compare(context, tree, tree->current->key, context->data[Node]->node.key); goto meta(context, Replace); } + + goto meta(context, Insert); } __code put_stub(struct Context* context) { @@ -48,14 +48,13 @@ allocator(context); - if (tree->current == 0) { - stack_pop(context->node_stack, &tree->current); - goto meta(context, Insert); - } else { + if (tree->current) { compare(context, tree, tree->current->key, context->data[Node]->node.key); - goto meta(context, Replace); } + + stack_pop(context->node_stack, &tree->current); + goto meta(context, Insert); } __code replaceNode_stub(struct Context* context) { @@ -63,7 +62,7 @@ } __code balance1(struct Context* context, struct Node* current) { - if (current->right != 0) + if (current->right) if (current->right->color == Red) { context->next = Balance2; @@ -79,8 +78,8 @@ } __code balance2(struct Context* context, struct Node* current) { - if (current->left != 0) - if (current->left->left != 0) + if (current->left) + if (current->left->left) if (current->left->color == Red && current->left->left->color == Red) { context->next = Balance3; @@ -96,7 +95,7 @@ } __code balance3(struct Context* context, struct Node* current){ - if (current->right != 0 && current->left != 0) + if (current->right && current->left) if (current->right->color == Red && current->left->color == Red) { context->next = FixUp; @@ -115,12 +114,11 @@ node->color = Red; *newNode = *node; - if (tree->root == 0) { - tree->current = newNode; - goto meta(context, SetRoot); - } - - goto meta(context, Balance1); + if (tree->root) + goto meta(context, Balance1); + + tree->current = newNode; + goto meta(context, SetRoot); } __code insertNode_stub(struct Context* context) { @@ -162,10 +160,10 @@ __code colorFlip(struct Context* context, struct Node* node) { node->color ^= 1; - if (node->left != 0) + if (node->left) node->left->color ^= 1; - if (node->right != 0) + if (node->right) node->right->color ^= 1; stack_pop(context->code_stack, &context->next); @@ -234,10 +232,10 @@ tree->current = tree->current->left; } - if (tree->current == 0) - goto meta(context, context->next); - - goto meta(context, Get); + if (tree->current) + goto meta(context, Get); + + goto meta(context, context->next); } __code get_stub(struct Context* context) { @@ -264,9 +262,9 @@ tree->current = newNode; if (tree->result == -1) { - if (tree->current->left != 0) { - - if (tree->current->left->left != 0) + if (tree->current->left) { + + if (tree->current->left->left) if (tree->current->left->color != Red && tree->current->left->left->color != Red) { context->next = MoveRedL1; @@ -285,7 +283,7 @@ goto meta(context, Replace_d1); } } else { - if (tree->current->left != 0) + if (tree->current->left) if (tree->current->left->color == Red) { allocator(context); context->data[context->dataNum]->node = *tree->current->left; @@ -330,8 +328,8 @@ } __code replaceNode_d3(struct Context* context, struct Tree* tree) { - if (tree->current->right != 0) { - if (tree->current->right->left != 0) + if (tree->current->right) { + if (tree->current->right->left) if (tree->current->right->color != Red && tree->current->right->left->color != Red) { context->next = MoveRedR1; stack_push(context->code_stack, &context->next); @@ -371,8 +369,8 @@ } __code moveRedLeft1(struct Context* context, struct Tree* tree, struct Node* node) { - if (tree->current->right != 0) - if (tree->current->right->left != 0) + if (tree->current->right) + if (tree->current->right->left) if (tree->current->right->left->color == Red) { allocator(context); context->data[context->dataNum]->node = *node->right; @@ -448,8 +446,8 @@ } __code moveRedRight1(struct Context* context, struct Tree* tree, struct Node* node) { - if (tree->current->left != 0) - if (tree->current->left->left != 0) + if (tree->current->left) + if (tree->current->left->left) if (tree->current->left->left->color == Red) { allocator(context); context->data[context->dataNum]->node = *node->left; @@ -485,30 +483,30 @@ } __code findMin(struct Context* context, struct Tree* tree, struct Node* tmp) { - if (tree->current->left == 0) { - tmp->key = tree->current->key; - tmp->value = tree->current->value; - - stack_pop(context->node_stack, &tree->current); - - tree->current->key = tmp->key; - tree->current->value = tmp->value; - - stack_push(context->node_stack, &tree->current); - - struct Node* next = tree->current->right; - - tree->current->right = context->heap; - tree->current = next; - - allocator(context); - - goto meta(context, DeleteMin1); - } else { + if (tree->current->left) { tree->current = tree->current->left; goto meta(context, FindMin); } + + tmp->key = tree->current->key; + tmp->value = tree->current->value; + + stack_pop(context->node_stack, &tree->current); + + tree->current->key = tmp->key; + tree->current->value = tmp->value; + + stack_push(context->node_stack, &tree->current); + + struct Node* next = tree->current->right; + + tree->current->right = context->heap; + tree->current = next; + + allocator(context); + + goto meta(context, DeleteMin1); } __code findMin_stub(struct Context* context) { @@ -535,8 +533,8 @@ goto meta(context, Balance1); } - if (tree->current->left != 0) - if (tree->current->left->left != 0) + if (tree->current->left) + if (tree->current->left->left) if (tree->current->left->color != Red && tree->current->left->left->color != Red) { context->next = DeleteMin2; stack_push(context->code_stack, &context->next);