Mercurial > hg > CbC > old > akasha
changeset 11:b13d2c8d4b47
Fix iterator
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 16 Mar 2016 17:19:50 +0900 |
parents | 48bcaf3f90ef |
children | 78dce131e9d6 |
files | src/insert_verification/akashaLLRBContext.c src/insert_verification/include/akashaLLRBContext.h src/insert_verification/main.c |
diffstat | 3 files changed, 30 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/insert_verification/akashaLLRBContext.c Tue Mar 15 16:59:59 2016 +0900 +++ b/src/insert_verification/akashaLLRBContext.c Wed Mar 16 17:19:50 2016 +0900 @@ -4,6 +4,7 @@ extern __code insertOnce_stub(struct Context*); extern __code showTree_stub(struct Context*); +extern __code iterateInsertion_stub(struct Context*); /* definitions from llrb */ extern __code meta(struct Context*, enum Code next); @@ -52,8 +53,9 @@ context->codeNum = Exit; - context->code[InsertOnce] = insertOnce_stub; - context->code[ShowTree] = showTree_stub; + context->code[InsertOnce] = insertOnce_stub; + context->code[ShowTree] = showTree_stub; + context->code[IterateInsertion] = iterateInsertion_stub; /* definitions from llrb */ context->code[Put] = put_stub; @@ -85,7 +87,7 @@ context->data[Iter] = context->heap; context->heap += sizeof(struct Iterator); - context->dataNum = Node; + context->dataNum = Iter; struct Tree* tree = &context->data[Tree]->tree; tree->root = 0; @@ -101,10 +103,11 @@ __code initIterator(struct Context* context) { struct IterElem* ie = (struct IterElem*)malloc(sizeof(struct IterElem)); - struct Iterator* iter = &context->data[Iter]; + struct Iterator* iter = &context->data[Iter]->iterator; ie->val = 0; ie->next = NULL; + iter->tree = NULL; iter->head = ie; goto initIteratorElem(context, ie); @@ -120,7 +123,7 @@ } __code initFinishIterator(struct Context* context, struct IterElem* elem) { - struct Iterator* iter = &context->data[Iter]; + struct Iterator* iter = &context->data[Iter]->iterator; elem->next = iter->head; iter->last = iter->head; goto meta(context, context->next);
--- a/src/insert_verification/include/akashaLLRBContext.h Tue Mar 15 16:59:59 2016 +0900 +++ b/src/insert_verification/include/akashaLLRBContext.h Wed Mar 16 17:19:50 2016 +0900 @@ -2,11 +2,12 @@ #include "stack.h" #define ALLOCATE_SIZE 1000 -#define LIMIT_OF_VERIFICATION_SIZE 4 +#define LIMIT_OF_VERIFICATION_SIZE 16 enum Code { InsertOnce, ShowTree, + IterateInsertion, /* definitions from llrb */ Allocator,
--- a/src/insert_verification/main.c Tue Mar 15 16:59:59 2016 +0900 +++ b/src/insert_verification/main.c Wed Mar 16 17:19:50 2016 +0900 @@ -36,6 +36,25 @@ goto meta(context, Exit); } +__code verifySpecification(struct Context* context) { +} + +__code iterateInsertion_stub(struct Context* context) { + goto iterateInsertion(context, &context->data[Iter]->iterator, &context->data[Node]->node); +} + +__code iterateInsertion(struct Context* context, struct Iterator* iter, struct Node* node) { + node->key = iter->head->val; + node->value = iter->head->val; + iter->head = iter->head->next; + if (iter->head == iter->last) { goto meta(context, ShowTree); } + + //printf("Trying insertion %d", node->key); + + context->next = IterateInsertion; + goto meta(context, Put); +} + int main(int argc, char const* argv[]) { - goto startCode(InsertOnce); + goto startCode(IterateInsertion); }