Mercurial > hg > Members > Moririn
changeset 65:025fd6e90597
to the function call(allocate and compare)
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 14 Jul 2015 15:59:41 +0900 |
parents | 89d760486188 |
children | a870c84acd0e |
files | src/include/origin_cs.h src/llrb/CMakeLists.txt src/llrb/llrb.c src/llrb/llrbContext.c src/llrb/llrbContext.h |
diffstat | 5 files changed, 23 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/src/include/origin_cs.h Mon Jul 13 23:22:12 2015 +0900 +++ b/src/include/origin_cs.h Tue Jul 14 15:59:41 2015 +0900 @@ -1,5 +1,6 @@ __code start_code(); __code exit_code(); +extern __code meta(); __code start_code(struct Context* context, enum Code next) { goto meta(context, next);
--- a/src/llrb/CMakeLists.txt Mon Jul 13 23:22:12 2015 +0900 +++ b/src/llrb/CMakeLists.txt Tue Jul 14 15:59:41 2015 +0900 @@ -3,4 +3,6 @@ add_executable(llrb llrb.c llrbContext.c + allocate.c + compare.c )
--- a/src/llrb/llrb.c Mon Jul 13 23:22:12 2015 +0900 +++ b/src/llrb/llrb.c Tue Jul 14 15:59:41 2015 +0900 @@ -4,7 +4,6 @@ #include "llrbContext.h" -#include "allocate.h" #include "origin_cs.h" #include "stack.h" @@ -12,6 +11,8 @@ #define NUM 100 extern __code initLLRBContext(struct Context* context); +extern void allocator(struct Context* context); +extern void compare(struct Context* context, struct Tree* tree, int key1, int key2); /* __code code1(Allocate allocate) { @@ -46,8 +47,8 @@ __code code1(struct Context* context, struct Allocate *allocate) { allocate->size = sizeof(struct Count); - context->next[context->current++] = Code2; - goto meta(context, Allocator); + allocator(context); + goto meta(context, Code2); } __code code1_stub(struct Context* context) { @@ -76,7 +77,7 @@ goto meta(context, Code4); } - context->next[context->current++] = Code3; + context->next = Code3; node->key = count->i; node->value = count->i; @@ -94,15 +95,15 @@ __code put(struct Context* context, struct Tree* tree, struct Allocate* allocate) { allocate->size = sizeof(struct Node); + allocator(context); if (tree->root == 0) { - context->next[context->current++] = Insert; + goto meta(context, Insert); } else { - context->next[context->current++] = Replace; - context->next[context->current++] = Compare; tree->current = tree->root; + compare(context, tree, tree->current->key, context->data[Node]->node.key); + goto meta(context, Replace); } - goto meta(context, Allocator); } __code put_stub(struct Context* context) { @@ -125,15 +126,15 @@ newNode->left = context->heap; } + allocator(context); + if (tree->current == 0) { stack_pop(pstack, &tree->current); - context->next[context->current++] = Insert; + goto meta(context, Insert); } else { - context->next[context->current++] = Replace; - context->next[context->current++] = Compare; + compare(context, tree, tree->current->key, context->data[Node]->node.key); + goto meta(context, Replace); } - - goto meta(context, Allocator); } __code replaceNode_stub(struct Context* context) { @@ -147,7 +148,7 @@ if (tree->root == 0) { newNode->color = Black; tree->root = newNode; - goto meta(context, context->next[--context->current]); + goto meta(context, context->next); } goto meta(context, RotateL); @@ -157,22 +158,6 @@ goto insertNode(context, &context->data[Tree]->tree, &context->data[Node]->node, &context->data[context->dataNum]->node); } -__code compare(struct Context* context, struct Tree* tree, int key1, int key2) { - if (key1 == key2) { - tree->result = 0; - } else if (key1 < key2) { - tree->result = 1; - } else { - tree->result = -1; - } - - goto meta(context, context->next[--context->current]); -} - -__code compare_stub(struct Context* context) { - goto compare(context, &context->data[Tree]->tree, context->data[Tree]->tree.current->key, context->data[Node]->node.key); -} - __code rotateLeft(struct Context* context, struct Node* node) { if (node->right != 0) { if (node->right->color == Red) { @@ -234,13 +219,13 @@ tree->prev = newNode; if (stack_pop(pstack, &tree->current) == 0) { - context->next[context->current++] = ChangeRef; - goto meta(context, Compare); + compare(context, tree, tree->current->key, node->key); + goto meta(context, ChangeRef); } tree->root = newNode; - goto meta(context, context->next[--context->current]); + goto meta(context, context->next); } __code fixUp_stub(struct Context* context) { @@ -302,7 +287,7 @@ node->key = 0; node->value = 0; - context->next[context->current++] = Code5; + context->next = Code5; goto meta(context, Put); }
--- a/src/llrb/llrbContext.c Mon Jul 13 23:22:12 2015 +0900 +++ b/src/llrb/llrbContext.c Tue Jul 14 15:59:41 2015 +0900 @@ -9,11 +9,9 @@ extern __code code5(struct Context*); extern __code code6_stub(struct Context*); extern __code meta(struct Context*); -extern __code allocate(struct Context*); extern __code put_stub(struct Context*); extern __code replaceNode_stub(struct Context*); extern __code insertNode_stub(struct Context*); -extern __code compare_stub(struct Context*); extern __code rotateLeft_stub(struct Context*); extern __code rotateRight_stub(struct Context*); extern __code colorFlip_stub(struct Context*); @@ -25,7 +23,6 @@ __code initLLRBContext(struct Context* context) { context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; - context->next = malloc(sizeof(enum Code)*ALLOCATE_SIZE); context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE); context->heapStart = malloc(context->heapLimit); @@ -36,11 +33,9 @@ context->code[Code3] = code3_stub; context->code[Code4] = code4; context->code[Code5] = code5; - context->code[Allocator] = allocate; context->code[Put] = put_stub; context->code[Replace] = replaceNode_stub; context->code[Insert] = insertNode_stub; - context->code[Compare] = compare_stub; context->code[RotateL] = rotateLeft_stub; context->code[RotateR] = rotateRight_stub; context->code[ColorFlip] = colorFlip_stub;