Mercurial > hg > Members > innparusu > Gears
diff src/llrb/llrb.c @ 44:a0a58875c93f
refactoring llrb
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 19 May 2015 06:08:38 +0900 |
parents | 44914699ee9b |
children | 348148d8fdb1 |
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); }