Mercurial > hg > CbC > old > akasha
changeset 7:24ae2641fec5
Show tree in llrb
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Mar 2016 11:52:37 +0900 |
parents | 3f00d95339a7 |
children | 46bc6ea5fa81 |
files | src/insert_verification/akashaLLRBContext.c src/insert_verification/include/akashaLLRBContext.h src/insert_verification/main.c |
diffstat | 3 files changed, 28 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/insert_verification/akashaLLRBContext.c Tue Mar 15 11:45:17 2016 +0900 +++ b/src/insert_verification/akashaLLRBContext.c Tue Mar 15 11:52:37 2016 +0900 @@ -3,6 +3,7 @@ #include "akashaLLRBContext.h" extern __code insertOnce_stub(struct Context*); +extern __code showTree_stub(struct Context*); /* definitions from llrb */ extern __code meta(struct Context*); @@ -49,6 +50,7 @@ context->codeNum = Exit; context->code[InsertOnce] = insertOnce_stub; + context->code[ShowTree] = showTree_stub; /* definitions from llrb */ context->code[Put] = put_stub;
--- a/src/insert_verification/include/akashaLLRBContext.h Tue Mar 15 11:45:17 2016 +0900 +++ b/src/insert_verification/include/akashaLLRBContext.h Tue Mar 15 11:52:37 2016 +0900 @@ -5,6 +5,7 @@ enum Code { InsertOnce, + ShowTree, /* definitions from llrb */ Allocator,
--- a/src/insert_verification/main.c Tue Mar 15 11:45:17 2016 +0900 +++ b/src/insert_verification/main.c Tue Mar 15 11:52:37 2016 +0900 @@ -1,7 +1,18 @@ #include <stdio.h> -#include "llrbContext.h" -#include "origin_cs.h" +#include "akashaLLRBContext.h" +#include "akashaCS.h" + + +void printTree(struct Node* node, int n) { + if (node != 0) { + printTree(node->left, n+1); + for (int i=0;i<n;i++) + printf(" "); + printf("key=%d value=%d color=%s\t%p\n", node->key, node->value,/* n, */node->color==0? "R":"B", node); + printTree(node->right, n+1); + } +} __code insertOnce_stub(struct Context* context) { goto insertOnce(context, &context->data[Node]->node); @@ -9,15 +20,24 @@ __code insertOnce(struct Context* context, struct Node* node) { - // print_tree(context->data[Tree]->tree.root, 0); - // puts(""); - context->next = Exit; node->key = rand()%100+1; node->value = 100; + context->next = ShowTree; goto meta(context, Put); } +__code showTree_stub(struct Context* context) { + goto showTree(context, &context->data[Tree]->tree); +} + +__code showTree(struct Context* context, struct Tree* tree) { + printTree(tree->root, 0); + puts(""); + + goto meta(context, Exit); +} + int main(int argc, char const* argv[]) { goto startCode(InsertOnce); }