Mercurial > hg > Members > Moririn
changeset 75:97387904add9
refactoring
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 17 Nov 2015 15:53:51 +0900 |
parents | 724b65b1cfaf |
children | 7ad6d1502a03 |
files | src/llrb/llrb.c src/llrb/llrbContext.c src/llrb/llrbContext.h |
diffstat | 3 files changed, 19 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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) {
--- 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;