# HG changeset patch # User Shohei KOKUBO # Date 1447743231 -32400 # Node ID 97387904add94e7e77f65f1f82f7082caad85a96 # Parent 724b65b1cfaf13f528db2945001b3d2ff5d7a7a4 refactoring diff -r 724b65b1cfaf -r 97387904add9 src/llrb/llrb.c --- a/src/llrb/llrb.c Tue Nov 10 17:14:46 2015 +0900 +++ b/src/llrb/llrb.c Tue Nov 17 15:53:51 2015 +0900 @@ -116,14 +116,10 @@ *newNode = *node; if (tree->root == 0) { - newNode->color = Black; - tree->root = newNode; - tree->current = 0; - - stack_pop(context->code_stack, &context->next); - goto meta(context, context->next); + tree->current = newNode; + goto meta(context, SetRoot); } - + goto meta(context, Balance1); } @@ -188,17 +184,25 @@ compare(context, tree, tree->current->key, node->key); goto meta(context, ChangeRef); } - - newNode->color = Black; - tree->root = newNode; + + goto meta(context, SetRoot); +} + +__code fixUp_stub(struct Context* context) { + goto fixUp(context, &context->data[Tree]->tree, &context->data[Node]->node, context->data[Tree]->tree.current); +} + +__code setRoot(struct Context* context, struct Tree* tree, struct Node* node) { + tree->root = node; + tree->root->color = Black; tree->current = 0; stack_pop(context->code_stack, &context->next); goto meta(context, context->next); } -__code fixUp_stub(struct Context* context) { - goto fixUp(context, &context->data[Tree]->tree, &context->data[Node]->node, context->data[Tree]->tree.current); +__code setRoot_stub(struct Context* context) { + goto setRoot(context, &context->data[Tree]->tree, context->data[Tree]->tree.current); } __code changeReference(struct Context* context, struct Tree* tree, struct Node* node, int result) { diff -r 724b65b1cfaf -r 97387904add9 src/llrb/llrbContext.c --- a/src/llrb/llrbContext.c Tue Nov 10 17:14:46 2015 +0900 +++ b/src/llrb/llrbContext.c Tue Nov 17 15:53:51 2015 +0900 @@ -22,6 +22,7 @@ extern __code balance1_stub(struct Context*); extern __code balance2_stub(struct Context*); extern __code balance3_stub(struct Context*); +extern __code setRoot_stub(struct Context*); extern __code get_stub(struct Context*); extern __code findMin_stub(struct Context*); extern __code delete_stub(struct Context*); @@ -65,6 +66,7 @@ context->code[Balance1] = balance1_stub; context->code[Balance2] = balance2_stub; context->code[Balance3] = balance3_stub; + context->code[SetRoot] = setRoot_stub; context->code[Get] = get_stub; context->code[Delete] = delete_stub; context->code[FindMin] = findMin_stub; diff -r 724b65b1cfaf -r 97387904add9 src/llrb/llrbContext.h --- a/src/llrb/llrbContext.h Tue Nov 10 17:14:46 2015 +0900 +++ b/src/llrb/llrbContext.h Tue Nov 17 15:53:51 2015 +0900 @@ -22,6 +22,7 @@ RotateR, ColorFlip, FixUp, + SetRoot, ChangeRef, Balance1, Balance2,