Mercurial > hg > GearsTemplate
changeset 121:f708b271a7b8
node stack rewrite
author | ikkun |
---|---|
date | Tue, 27 Sep 2016 17:48:17 +0900 |
parents | 2493f4226ca6 |
children | 73a679a85c04 |
files | src/parallel_execution/rb_tree.c |
diffstat | 1 files changed, 47 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/rb_tree.c Mon Sep 26 20:43:18 2016 +0900 +++ b/src/parallel_execution/rb_tree.c Tue Sep 27 17:48:17 2016 +0900 @@ -8,21 +8,12 @@ extern int num; -__code put(struct Context* context, struct Tree* tree, struct Traverse* traverse, struct Node* root, struct Allocate* allocate) { - // tree->root=allocator(context,struct Node); - allocate->size = sizeof(struct Node); - allocator(context); - - // we don't need this push - stack_push(context->code_stack, &context->next); - - tree->root = &context->data[context->dataNum]->node; - +__code put(struct Context* context, struct Tree* tree, struct Traverse* traverse, struct Node* root, struct Node* node) { if (root) { traverse->current = root; // traverse->result=compare(...) - compare(context, traverse, traverse->current->key, context->data[Node]->node.key); - + compare(context, traverse, traverse->current->key, node->key); + // goto replaceNode(traverse->current, newNode, traverse->result); goto meta(context, Replace); } @@ -30,46 +21,75 @@ } __code put_stub(struct Context* context) { + struct Allocate* allocate = &context->data[Allocate]->allocate; + allocate->size = sizeof(struct Node); + allocator(context); + + context->data[Tree]->tree->root = &context->data[context->dataNum]->node; + goto put(context, &context->data[Tree]->tree, &context->data[Traverse]->traverse, context->data[Tree]->tree.root, - &context->data[Allocate]->allocate); + &context->data[Node]->node); +} + +__code replaceNode(struct Context* context, struct Traverse* traverse, struct Node* oldNode, struct Node* newNode, struct Element* element) { + *newNode = *oldNode; + element->next = traverse->stack; + element->data = (struct Data* )newNode; + traverse->stack = element; + goto meta(context, Replace1); } -__code replaceNode(struct Context* context, struct Traverse* traverse, struct Node* oldNode, struct Node* newNode, int result) { - *newNode = *oldNode; - stack_push(context->node_stack, &newNode); +__code replaceNode_stub(struct Context* context) { + struct Allocate* allocate = &context->data[Allocate]->allocate; + allocate->size = sizeof(struct Node); + allocator(context); + struct Node* newNode = &context->data[context->dataNum]->node; + allocate->size = sizeof(struct Element); + allocator(context); + struct Element* element = &context->data[context->dataNum]->node; + goto replaceNode(context, + &context->data[Traverse]->traverse, + context->data[Traverse]->traverse.current, + newNode, + element); +} + +__code replaceNode1(struct Context* context, struct Traverse* traverse, struct Node* node, struct Node* oldNode, struct Node* newNode, struct Node* newnewNode, int result) { if (result == EQ) { - newNode->value = context->data[Node]->node.value; - + newNode->value = node->value; // go to stack clear - stack_pop(context->code_stack, &context->next); goto meta(context, context->next); } else if (result == GT) { traverse->current = oldNode->right; - newNode->right = context->heap; // allocator(context,struct Node) + newNode->right = newnewNode; } else { traverse->current = oldNode->left; - newNode->left = context->heap; + newNode->left = newnewNode; } - allocator(context); - if (traverse->current) { - compare(context, traverse, traverse->current->key, context->data[Node]->node.key); + compare(context, traverse, traverse->current->key, node->key); goto meta(context, Replace); } goto meta(context, Insert); + } -__code replaceNode_stub(struct Context* context) { - goto replaceNode(context, +__code replaceNode1_stub(struct Context* context) { + struct Allocate* allocate = &context->data[Allocate]->allocate; + allocate->size = sizeof(struct Node); + allocator(context); + struct Node* newnewNode = &context->data[context->dataNum]->node; + goto replaceNode1(context, &context->data[Traverse]->traverse, + context->data[Node]->node, context->data[Traverse]->traverse.current, - &context->data[context->dataNum]->node, // new Node + (struct Node*)context->data[traverse]->traverse->stack->data, context->data[Traverse]->traverse.result); }