changeset 14:1bbaafdafa47

Enumerates all paths
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Sun, 20 Mar 2016 19:05:43 +0900
parents f0a1f02e8493
children d6d6e075b498
files src/insert_verification/akashaLLRBContext.c src/insert_verification/include/akashaLLRBContext.h src/insert_verification/main.c
diffstat 3 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/insert_verification/akashaLLRBContext.c	Sun Mar 20 18:23:58 2016 +0900
+++ b/src/insert_verification/akashaLLRBContext.c	Sun Mar 20 19:05:43 2016 +0900
@@ -6,6 +6,7 @@
 extern __code iterateInsertion_stub(struct Context*);
 extern __code putAndGoToNextDepth_stub (struct Context*);
 extern __code duplicateIterator_stub(struct Context*);
+extern __code goToPreviousDepth(struct Context*);
 
 /* definitions from llrb */
 extern __code meta(struct Context*, enum Code next);
@@ -63,6 +64,7 @@
     context->code[IterateInsertion]    = iterateInsertion_stub;
     context->code[PutAndGoToNextDepth] = putAndGoToNextDepth_stub;
     context->code[DuplicateIterator]   = duplicateIterator_stub;
+    context->code[GoToPreviousDepth]   = goToPreviousDepth;
 
     /* definitions from llrb */
     context->code[Put]           = put_stub;
--- a/src/insert_verification/include/akashaLLRBContext.h	Sun Mar 20 18:23:58 2016 +0900
+++ b/src/insert_verification/include/akashaLLRBContext.h	Sun Mar 20 19:05:43 2016 +0900
@@ -2,13 +2,14 @@
 #include "stack.h"
 
 #define ALLOCATE_SIZE 1000
-#define LIMIT_OF_VERIFICATION_SIZE 2
+#define LIMIT_OF_VERIFICATION_SIZE 4
 
 enum Code {
     ShowTree,
     IterateInsertion,
     PutAndGoToNextDepth,
     DuplicateIterator,
+    GoToPreviousDepth,
 
     /* definitions from llrb */
     Allocator,
--- a/src/insert_verification/main.c	Sun Mar 20 18:23:58 2016 +0900
+++ b/src/insert_verification/main.c	Sun Mar 20 19:05:43 2016 +0900
@@ -56,8 +56,10 @@
     node->value = iter->head->val;
     iter->head  = iter->head->next;
 
+    printf("%d\n", node->value);
+
     if (iter->head == iter->last) {
-        context->next = ShowTree; // TODO: add restore and  back trace
+        context->next = GoToPreviousDepth;
     } else {
         context->next = DuplicateIterator;
     }
@@ -131,7 +133,21 @@
 __code duplicateTree(struct Context* context, struct Tree* tree, struct Iterator* iter) {
     // Tree must be non destructive.
     // If you use destructive tree, you must copy tree.
-    iter->tree = tree;
+    iter->previousDepth->tree = tree;
+    goto meta(context, PutAndGoToNextDepth);
+}
+
+__code goToPreviousDepth(struct Context* context) {
+    struct Iterator* finishedIter = &context->data[Iter]->iterator;
+
+    if (finishedIter->previousDepth == NULL) {
+        goto meta(context, ShowTree); // all enumerations finished.
+    }
+
+    context->data[Iter] = (union Data*)finishedIter->previousDepth;
+    context->data[Tree] = (union Data*)finishedIter->previousDepth->tree;
+    // TODO: cleanup memory
+
     goto meta(context, PutAndGoToNextDepth);
 }