Mercurial > hg > GearsTemplate
changeset 44:a0a58875c93f
refactoring llrb
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 19 May 2015 06:08:38 +0900 |
parents | ec46ac3b0401 |
children | 2e7e66ccb3db 348148d8fdb1 |
files | src/llrb/llrb.c src/llrb/llrbContext.c src/llrb/llrbContext.h |
diffstat | 3 files changed, 25 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/llrb/llrb.c Tue May 19 05:07:22 2015 +0900 +++ b/src/llrb/llrb.c Tue May 19 06:08:38 2015 +0900 @@ -59,61 +59,57 @@ context->data[Next]->next = context->data[Allocate]->allocate.next; if (tree->root == 0) { - struct Node* node = &context->data[Node]->node; - node->color = Black; - node->left = 0; - node->right = 0; - context->data[Allocate]->allocate.next = InitNode; + context->data[Allocate]->allocate.next = Insert; goto meta(context, Allocator); } - context->data[Allocate]->allocate.next = Insert; + context->data[Allocate]->allocate.next = Create; tree->current = tree->root; goto meta(context, Compare); } -__code clone(struct Context* context) { - struct Node* node = &context->data[context->dataNum]->node; +__code replaceNode(struct Context* context) { + struct Node* newNode = &context->data[context->dataNum]->node; struct Tree* tree = &context->data[Tree]->tree; struct Node* persistentNode = tree->current; int result = context->data[Tree]->tree.result; - *node = *persistentNode; + *newNode = *persistentNode; if (result == 0) { stack_pop(pstack, &tree->current); goto meta(context, RotateL); } else if (result == 1) { tree->current = persistentNode->right; - node->right = context->heap; + newNode->right = context->heap; } else { tree->current = persistentNode->left; - node->left = context->heap; + newNode->left = context->heap; } if (tree->current == 0) { stack_pop(pstack, &tree->current); - context->data[Allocate]->allocate.next = InitNode; + context->data[Allocate]->allocate.next = Insert; goto meta(context, Allocator); } - context->data[Allocate]->allocate.next = Insert; + context->data[Allocate]->allocate.next = Create; goto meta(context, Compare); } -__code initNode(struct Context* context) { - struct Node* node = &context->data[context->dataNum]->node; +__code insertNode(struct Context* context) { + struct Node* newNode = &context->data[context->dataNum]->node; struct Node* temporalNode = &context->data[Node]->node; struct Tree* tree = &context->data[Tree]->tree; temporalNode->color = Red; - *node = *temporalNode; + *newNode = *temporalNode; if (tree->root == 0) { - node->color = Black; - tree->root = node; + newNode->color = Black; + tree->root = newNode; goto meta(context, context->data[Next]->next); } @@ -137,10 +133,10 @@ goto meta(context, context->data[Allocate]->allocate.next); } -__code insert(struct Context* context) { +__code createNode(struct Context* context) { stack_push(pstack, &context->heap); - context->data[Allocate]->allocate.next = Clone; + context->data[Allocate]->allocate.next = Replace; goto meta(context, Allocator); }
--- a/src/llrb/llrbContext.c Tue May 19 05:07:22 2015 +0900 +++ b/src/llrb/llrbContext.c Tue May 19 06:08:38 2015 +0900 @@ -10,10 +10,10 @@ extern __code meta(struct Context*); extern __code allocate(struct Context*); extern __code put(struct Context*); -extern __code clone(struct Context*); -extern __code initNode(struct Context*); +extern __code replaceNode(struct Context*); +extern __code insertNode(struct Context*); extern __code compare(struct Context*); -extern __code insert(struct Context*); +extern __code createNode(struct Context*); extern __code rotateLeft(struct Context*); extern __code rotateRight(struct Context*); extern __code colorFlip(struct Context*); @@ -35,10 +35,10 @@ context->code[Code5] = code5; context->code[Allocator] = allocate; context->code[Put] = put; - context->code[Clone] = clone; - context->code[InitNode] = initNode; + context->code[Replace] = replaceNode; + context->code[Insert] = insertNode; context->code[Compare] = compare; - context->code[Insert] = insert; + context->code[Create] = createNode; context->code[RotateL] = rotateLeft; context->code[RotateR] = rotateRight; context->code[ColorFlip] = colorFlip;