Mercurial > hg > CbC > old > akasha
changeset 3:c80e44ac8f5e
Import origin_cs and llrbContext
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 13 Mar 2016 18:19:40 +0900 |
parents | 9815b09dc853 |
children | d41e349d6e22 |
files | src/insert_verification/CMakeLists.txt src/insert_verification/akasha_cs.c src/insert_verification/akasha_llrb_context.c src/insert_verification/include/akasha_cs.h src/insert_verification/include/akasha_llrb_context.h src/insert_verification/include/llrbContext.h src/insert_verification/include/origin_cs.h src/insert_verification/main.c |
diffstat | 8 files changed, 213 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/insert_verification/CMakeLists.txt Fri Mar 11 19:24:34 2016 +0900 +++ b/src/insert_verification/CMakeLists.txt Sun Mar 13 18:19:40 2016 +0900 @@ -5,14 +5,15 @@ include_directories(include) include_directories($ENV{GEARS_PATH}/src/include) -include_directories(${llrb_path}/include) +include_directories(${llrb_path}) add_executable(insert_verification main.c - ${llrb_path}/llrb.c - ${llrb_path}/llrbContext.c # TODO: create file in akasha + akasha_cs.c + akasha_llrb_context.c ${llrb_path}/allocate.c # TODO: create file in akasha ${llrb_path}/compare.c # TODO: create file in akasha - ${llrb_path}/origin_cs.c # TODO: create file in akasha ${llrb_path}/stack.c # TODO: create file in akasha + + ${llrb_path}/llrb.c )
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/insert_verification/akasha_cs.c Sun Mar 13 18:19:40 2016 +0900 @@ -0,0 +1,17 @@ +#include <stdlib.h> +#include "llrbContext.h" + +__code meta(struct Context* context, enum Code next) { + goto (context->code[next])(context); +} + +__code start_code(struct Context* context, enum Code next) { + goto meta(context, next); +} + +__code exit_code(struct Context* context) { + free(context->code); + free(context->data); + free(context->heapStart); + goto exit(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/insert_verification/akasha_llrb_context.c Sun Mar 13 18:19:40 2016 +0900 @@ -0,0 +1,83 @@ +#include <stdlib.h> + +#include "akasha_llrb_context.h" + +extern __code meta(struct Context*); +extern __code put_stub(struct Context*); +extern __code replaceNode_stub(struct Context*); +extern __code insertNode_stub(struct Context*); +extern __code rotateLeft_stub(struct Context*); +extern __code rotateRight_stub(struct Context*); +extern __code colorFlip_stub(struct Context*); +extern __code fixUp_stub(struct Context*); +extern __code changeReference_stub(struct Context*); +extern __code insert1_stub(struct Context*); +extern __code insert2_stub(struct Context*); +extern __code insert3_stub(struct Context*); +extern __code insert4_stub(struct Context*); +extern __code insert4_1_stub(struct Context*); +extern __code insert4_2_stub(struct Context*); +extern __code insert5_stub(struct Context*); +extern __code stackClear_stub(struct Context*); +extern __code get_stub(struct Context*); +extern __code search_stub(struct Context*); +extern __code delete_stub(struct Context*); +extern __code delete1_stub(struct Context*); +extern __code delete2_stub(struct Context*); +extern __code delete3_stub(struct Context*); +extern __code replaceNodeForDelete1_stub(struct Context*); +extern __code replaceNodeForDelete2_stub(struct Context*); +extern __code findMax1_stub(struct Context*); +extern __code findMax2_stub(struct Context*); +extern __code deleteCase1_stub(struct Context*); +extern __code deleteCase2_stub(struct Context*); +extern __code deleteCase3_stub(struct Context*); +extern __code deleteCase4_stub(struct Context*); +extern __code deleteCase5_stub(struct Context*); +extern __code deleteCase6_stub(struct Context*); +extern __code exit_code(struct Context*); + +__code initLLRBContext(struct Context* context, int num) { + context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; + context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); + context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE); + context->heapStart = malloc(context->heapLimit); + + context->codeNum = Exit; + + context->code[Put] = put_stub; + context->code[Replace] = replaceNode_stub; + context->code[Insert] = insertNode_stub; + context->code[RotateL] = rotateLeft_stub; + context->code[RotateR] = rotateRight_stub; + context->code[InsertCase1] = insert1_stub; + context->code[InsertCase2] = insert2_stub; + context->code[InsertCase3] = insert3_stub; + context->code[InsertCase4] = insert4_stub; + context->code[InsertCase4_1] = insert4_1_stub; + context->code[InsertCase4_2] = insert4_2_stub; + context->code[InsertCase5] = insert5_stub; + context->code[StackClear] = stackClear_stub; + context->code[Exit] = exit_code; + + context->heap = context->heapStart; + + context->data[Allocate] = context->heap; + context->heap += sizeof(struct Allocate); + + context->data[Tree] = context->heap; + context->heap += sizeof(struct Tree); + + context->data[Node] = context->heap; + context->heap += sizeof(struct Node); + + context->dataNum = Node; + + struct Tree* tree = &context->data[Tree]->tree; + tree->root = 0; + tree->current = 0; + tree->deleted = 0; + + context->node_stack = stack_init(sizeof(struct Node*), 100); + context->code_stack = stack_init(sizeof(enum Code), 100); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/insert_verification/include/akasha_cs.h Sun Mar 13 18:19:40 2016 +0900 @@ -0,0 +1,3 @@ +extern __code start_code(struct Context* context, enum Code next); +extern __code exit_code(struct Context* context); +extern __code meta(struct Context* context, enum Code next);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/insert_verification/include/akasha_llrb_context.h Sun Mar 13 18:19:40 2016 +0900 @@ -0,0 +1,100 @@ +/* Context definition for llrb example */ +#include "stack.h" + +#define ALLOCATE_SIZE 1000 + +enum Code { + Allocator, + Put, + Replace, + Insert, + Compare, + RotateL, + RotateR, + SetTree, + InsertCase1, + InsertCase2, + InsertCase3, + InsertCase4, + InsertCase4_1, + InsertCase4_2, + InsertCase5, + StackClear, + Get, + Search, + Delete, + Delete1, + Delete2, + Delete3, + Replace_d1, + Replace_d2, + FindMax1, + FindMax2, + DeleteCase1, + DeleteCase2, + DeleteCase3, + DeleteCase4, + DeleteCase5, + DeleteCase6, + Exit, +}; + +enum Relational { + EQ, + GT, + LT, +}; + +enum UniqueData { + Allocate, + Tree, + Node, +}; + +struct Context { + enum Code next; + int codeNum; + __code (**code) (struct Context*); + void* heapStart; + void* heap; + long heapLimit; + int dataNum; + stack_ptr code_stack; + stack_ptr node_stack; + union Data **data; +}; + +union Data { + struct Comparable { // inteface + enum Code compare; + union Data* data; + } compare; + struct Count { + enum Code next; + long i; + } count; + struct Tree { + enum Code next; + struct Node* root; + struct Node* current; + struct Node* deleted; + int result; + } tree; + struct Node { + // need to tree + enum Code next; + int key; // comparable data segment + int value; + struct Node* left; + struct Node* right; + // need to balancing + enum Color { + Red, + Black, + } color; + } node; + struct Allocate { + enum Code next; + long size; + } allocate; +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/insert_verification/include/llrbContext.h Sun Mar 13 18:19:40 2016 +0900 @@ -0,0 +1,3 @@ +/* Stub for context in original llrb */ + +#include "akasha_llrb_context.h"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/insert_verification/include/origin_cs.h Sun Mar 13 18:19:40 2016 +0900 @@ -0,0 +1,2 @@ +/* Stub for code segment definition in original llrb */ +#include "akasha_cs.h"
--- a/src/insert_verification/main.c Fri Mar 11 19:24:34 2016 +0900 +++ b/src/insert_verification/main.c Sun Mar 13 18:19:40 2016 +0900 @@ -5,22 +5,6 @@ struct Node; struct Allocate; - -/* FIXME: temporal definition for compile */ -__code code1() { } -__code code2() { } -__code code3() { } -__code code4() { } -__code code5() { } -__code code6() { } -__code code1_stub() { } -__code code2_stub() { } -__code code3_stub() { } -__code code4_stub() { } -__code find() { } -__code not_find() { } - - extern __code put(struct Context*, struct Tree*, struct Node*, struct Allocate*); __code hello() { printf("access to llrb library: %p\n", put);