# HG changeset patch # User Yasutaka Higa # Date 1458481673 -32400 # Node ID d6d6e075b49802c4af3d519d4ec797c88aa0ff22 # Parent 1bbaafdafa477eeca17216a23f86fdd32abce4fa Show traces in all paths diff -r 1bbaafdafa47 -r d6d6e075b498 src/insert_verification/akashaLLRBContext.c --- a/src/insert_verification/akashaLLRBContext.c Sun Mar 20 19:05:43 2016 +0900 +++ b/src/insert_verification/akashaLLRBContext.c Sun Mar 20 22:47:53 2016 +0900 @@ -119,7 +119,7 @@ allocate->size = sizeof(struct IterElem); allocator(context); - ie->val = 0; + ie->val = 1; ie->next = NULL; iter->tree = NULL; iter->head = ie; @@ -131,7 +131,7 @@ } __code initIteratorElem(struct Context* context, struct Allocate* allocate, struct IterElem* prev) { - if (prev->val+1 == LIMIT_OF_VERIFICATION_SIZE) { goto initFinishIterator(context, prev); } + if (prev->val == LIMIT_OF_VERIFICATION_SIZE) { goto initFinishIterator(context, prev); } struct IterElem* ie = context->heap; allocate->size = sizeof(struct IterElem); diff -r 1bbaafdafa47 -r d6d6e075b498 src/insert_verification/include/akashaLLRBContext.h --- a/src/insert_verification/include/akashaLLRBContext.h Sun Mar 20 19:05:43 2016 +0900 +++ b/src/insert_verification/include/akashaLLRBContext.h Sun Mar 20 22:47:53 2016 +0900 @@ -2,7 +2,7 @@ #include "stack.h" #define ALLOCATE_SIZE 1000 -#define LIMIT_OF_VERIFICATION_SIZE 4 +#define LIMIT_OF_VERIFICATION_SIZE 2 enum Code { ShowTree, @@ -117,5 +117,6 @@ struct Iterator* previousDepth; struct IterElem* head; struct IterElem* last; + unsigned int iteratedValue; } iterator; }; diff -r 1bbaafdafa47 -r d6d6e075b498 src/insert_verification/main.c --- a/src/insert_verification/main.c Sun Mar 20 19:05:43 2016 +0900 +++ b/src/insert_verification/main.c Sun Mar 20 22:47:53 2016 +0900 @@ -4,6 +4,7 @@ #include "akashaCS.h" extern void allocator(struct Context* context); +void showTrace(struct Iterator* iter); //FIXME void printTree(struct Node* node, int n) { if (node != 0) { @@ -52,13 +53,12 @@ } __code putAndGoToNextDepth(struct Context* context, struct Iterator* iter, struct Tree* tree, struct Node* node) { - node->key = iter->head->val; - node->value = iter->head->val; - iter->head = iter->head->next; + node->key = iter->head->val; + node->value = iter->head->val; + iter->head = iter->head->next; + iter->iteratedValue = node->value; - printf("%d\n", node->value); - - if (iter->head == iter->last) { + if (iter->head == iter->head->next) { context->next = GoToPreviousDepth; } else { context->next = DuplicateIterator; @@ -96,34 +96,29 @@ __code duplicateIteratorElem(struct Context* context, struct Allocate* allocate, struct Iterator* iter) { // All elements in iterator must be unique. - - if ((iter->last != NULL) && (iter->last == iter->previousDepth->last)) { - goto meta(context, ShowTree); /* copy tree */ - } - struct IterElem* dup = context->heap; - allocate->size = sizeof(struct IterElem); - allocator(context); - struct IterElem *oldElem = iter->previousDepth->head; struct IterElem *newElem = iter->head; - while ((newElem->next != NULL) && (oldElem->val == newElem->val)) { + while (newElem->next != NULL) { // FIXME: simple implementation O(n^2) oldElem = oldElem->next; newElem = newElem->next; } - dup->val = oldElem->next->val; - newElem->next = dup; + if (oldElem == iter->previousDepth->head) { + newElem->next = iter->head; + iter->last = newElem; + goto duplicateTree_stub(context); // meta + } else { + struct IterElem* dup = context->heap; + allocate->size = sizeof(struct IterElem); + allocator(context); - if (oldElem->next == iter->previousDepth->last) { - dup->next = iter->head; - iter->last = dup; - goto duplicateTree_stub(context); // meta + dup->val = oldElem->next->val; + newElem->next = dup; + goto duplicateIteratorElem_stub(context); // meta } - - goto duplicateIteratorElem_stub(context); // meta } __code duplicateTree_stub(struct Context* context) { @@ -140,17 +135,31 @@ __code goToPreviousDepth(struct Context* context) { struct Iterator* finishedIter = &context->data[Iter]->iterator; - if (finishedIter->previousDepth == NULL) { - goto meta(context, ShowTree); // all enumerations finished. - } + showTrace(finishedIter); // FIXME: show trace - context->data[Iter] = (union Data*)finishedIter->previousDepth; - context->data[Tree] = (union Data*)finishedIter->previousDepth->tree; - // TODO: cleanup memory + while (finishedIter->head == finishedIter->last) { + if (finishedIter->previousDepth == NULL) { + goto meta(context, ShowTree); // all enumerations finished. + } + + finishedIter = finishedIter->previousDepth; + // TODO: cleanup memory + } + context->data[Iter] = (union Data*)finishedIter; + context->data[Tree] = (union Data*)finishedIter->tree; goto meta(context, PutAndGoToNextDepth); } +void showTrace(struct Iterator* iter) { + printf("show trace(reversed):"); + + for (; iter != NULL; iter = iter->previousDepth) { + printf("%u ", iter->iteratedValue); + } + printf("\n"); +} + int main(int argc, char const* argv[]) { goto startCode(PutAndGoToNextDepth); }