annotate src/insert_verification/main.c @ 46:44cc739b8b56 default tip

Fix assert condition
author atton
date Tue, 21 Jun 2016 07:41:55 +0000
parents 56ea709e7af3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
1 #include <stdbool.h>
1
a13620720e35 Add directory for insert verification
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdio.h>
a13620720e35 Add directory for insert verification
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
7
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
4 #include "akashaLLRBContext.h"
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
5 #include "akashaCS.h"
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
6
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
7 extern void allocator(struct Context* context);
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
8
28
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
9 void* akashaMalloc(struct Context* context, size_t size) {
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
10 context->data[++context->dataNum] = context->heap;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
11 context->heap += size;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
12 return context->data[context->dataNum];
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
13 }
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
14
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
15 struct Node* nodeDeepCopy(struct Context* newContext, struct Node* oldNode) {
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
16 if (oldNode == NULL) return NULL;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
17
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
18 struct Node* newNode = akashaMalloc(newContext, sizeof(struct Node));
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
19 newNode->next = oldNode->next;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
20 newNode->key = oldNode->key;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
21 newNode->value = oldNode->value;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
22 newNode->color = oldNode->color;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
23
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
24 if (oldNode->left != NULL) {
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
25 newNode->left = nodeDeepCopy(newContext, oldNode->left);
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
26 } else {
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
27 newNode->left = NULL;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
28 }
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
29
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
30 if (oldNode->right != NULL) {
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
31 newNode->right = nodeDeepCopy(newContext, oldNode->right);
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
32 } else {
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
33 newNode->right = NULL;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
34 }
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
35
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
36 return newNode;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
37 }
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
38
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
39 void treeDeepCopy(struct Context* newContext, struct Tree* newTree, struct Tree* oldTree) {
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
40 if (oldTree == NULL) return;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
41 newTree->next = oldTree->next;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
42 newTree->result = oldTree->result;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
43 newTree->root = nodeDeepCopy(newContext, oldTree->root);
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
44 newTree->current = nodeDeepCopy(newContext, oldTree->current);
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
45 newTree->deleted = nodeDeepCopy(newContext, oldTree->deleted);
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
46 }
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
47
18
38e8d5a58fe8 Search all paths using iterator for insertion of 7 elements
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
48 /* Code Segments */
38e8d5a58fe8 Search all paths using iterator for insertion of 7 elements
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
49
7
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
50 __code showTree_stub(struct Context* context) {
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
51 goto showTree(context, &context->data[Tree]->tree);
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
52 }
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
53
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
54 __code showTree(struct Context* context, struct Tree* tree) {
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
55 printTree(tree->root, 0);
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
56 puts("");
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
57
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
58 goto meta(context, Exit);
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
59 }
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
60
11
b13d2c8d4b47 Fix iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
61 __code iterateInsertion_stub(struct Context* context) {
b13d2c8d4b47 Fix iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
62 goto iterateInsertion(context, &context->data[Iter]->iterator, &context->data[Node]->node);
b13d2c8d4b47 Fix iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
63 }
b13d2c8d4b47 Fix iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
64
b13d2c8d4b47 Fix iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
65 __code iterateInsertion(struct Context* context, struct Iterator* iter, struct Node* node) {
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
66 // puts all elements in iterator into tree.
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
67 node->key = iter->head->val;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
68 node->value = iter->head->val;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
69 iter->head = iter->head->next;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
70
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
71 if (iter->head == iter->last) {
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
72 context->next = ShowTree;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
73 } else {
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
74 context->next = IterateInsertion;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
75 }
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
76 goto meta(context, Put);
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
77 }
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
78
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
79 __code putAndGoToNextDepth_stub(struct Context* context) {
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
80 goto putAndGoToNextDepth(context, &context->data[Iter]->iterator, &context->data[Tree]->tree, &context->data[Node]->node);
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
81 }
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
82
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
83 __code putAndGoToNextDepth(struct Context* context, struct Iterator* iter, struct Tree* tree, struct Node* node) {
15
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
84 node->key = iter->head->val;
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
85 node->value = iter->head->val;
28
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
86 node->left = NULL;
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
87 node->right = NULL;
15
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
88 iter->head = iter->head->next;
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
89 iter->iteratedValue = node->value;
11
b13d2c8d4b47 Fix iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
90
15
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
91 if (iter->head == iter->head->next) {
14
1bbaafdafa47 Enumerates all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
92 context->next = GoToPreviousDepth;
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
93 } else {
18
38e8d5a58fe8 Search all paths using iterator for insertion of 7 elements
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
94 context->next = VerifySpecification;
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
95 }
11
b13d2c8d4b47 Fix iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
96 goto meta(context, Put);
b13d2c8d4b47 Fix iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
97 }
b13d2c8d4b47 Fix iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
98
32
be67b0312bea Convert "showTrace" function to CodeSegment
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
99 __code showTrace_stub(struct Context* context) {
be67b0312bea Convert "showTrace" function to CodeSegment
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
100 goto showTrace(context, &context->data[Iter]->iterator);
be67b0312bea Convert "showTrace" function to CodeSegment
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
101 }
be67b0312bea Convert "showTrace" function to CodeSegment
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
102
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
103 __code duplicateIterator_stub(struct Context* context) {
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
104 goto duplicateIterator(context, &context->data[Allocate]->allocate, &context->data[Iter]->iterator);
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
105 }
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
106
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
107 __code duplicateIterator(struct Context* context, struct Allocate* allocate, struct Iterator* iter) {
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
108 struct Iterator* newIter = context->heap;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
109 allocate->size = sizeof(struct Iterator);
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
110 allocator(context);
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
111
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
112 struct IterElem* dup = context->heap;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
113 allocate->size = sizeof(struct IterElem);
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
114 allocator(context);
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
115
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
116 dup->val = iter->head->val;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
117 dup->next = NULL;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
118
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
119 newIter->previousDepth = iter;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
120 newIter->head = dup;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
121 newIter->last = NULL;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
122 context->data[Iter] = (union Data*) newIter;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
123
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
124 goto duplicateIteratorElem_stub(context);
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
125 }
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
126
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
127 __code duplicateIteratorElem_stub(struct Context* context) {
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
128 goto duplicateIteratorElem(context, &context->data[Allocate]->allocate, &context->data[Iter]->iterator);
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
129 }
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
130
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
131 __code duplicateIteratorElem(struct Context* context, struct Allocate* allocate, struct Iterator* iter) {
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
132 // All elements in iterator must be unique.
16
3acaadc0a60c Enumerate all insetion patterns
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 15
diff changeset
133 struct IterElem *oldElem = iter->previousDepth->head->next;
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
134 struct IterElem *newElem = iter->head;
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
135
26
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
136 while (oldElem->val != iter->previousDepth->iteratedValue) {
15
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
137 allocate->size = sizeof(struct IterElem);
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
138 allocator(context);
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
139
26
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
140 newElem->next = (struct IterElem*)context->data[context->dataNum];
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
141 newElem->next->val = oldElem->val;
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
142
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
143 newElem = newElem->next;
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
144 oldElem = oldElem->next;
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
145 }
26
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
146 newElem->next = iter->head;
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
147 iter->last = iter->head;
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
148 goto meta(context, DuplicateTree);
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
149 }
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
150
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
151 __code duplicateTree_stub(struct Context* context) {
26
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
152 goto duplicateTree(context, &context->data[Allocate]->allocate, &context->data[Tree]->tree, &context->data[Iter]->iterator);
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
153 }
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
154
26
cf7cbe70404f WIP: Trying implement copying GC...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
155 __code duplicateTree(struct Context* context, struct Allocate* allocate, struct Tree* tree, struct Iterator* iter) {
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
156 // Tree must be non destructive.
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
157 // If you use destructive tree, you must copy tree.
28
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
158 iter->previousDepth->tree = akashaMalloc(context, sizeof(struct Tree));
04283ef8f3ca Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
159 treeDeepCopy(context, iter->previousDepth->tree, tree);
14
1bbaafdafa47 Enumerates all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
160 goto meta(context, PutAndGoToNextDepth);
1bbaafdafa47 Enumerates all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
161 }
1bbaafdafa47 Enumerates all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
162
1bbaafdafa47 Enumerates all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
163 __code goToPreviousDepth(struct Context* context) {
1bbaafdafa47 Enumerates all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
164 struct Iterator* finishedIter = &context->data[Iter]->iterator;
1bbaafdafa47 Enumerates all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
165
16
3acaadc0a60c Enumerate all insetion patterns
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 15
diff changeset
166 while (finishedIter->last == finishedIter->head) {
15
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
167 if (finishedIter->previousDepth == NULL) {
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
168 goto meta(context, ShowTree); // all enumerations finished.
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
169 }
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
170
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
171 finishedIter = finishedIter->previousDepth;
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
172 }
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
173 context->data[Iter] = (union Data*)finishedIter;
d6d6e075b498 Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 14
diff changeset
174 context->data[Tree] = (union Data*)finishedIter->tree;
14
1bbaafdafa47 Enumerates all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
175
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
176 goto meta(context, PutAndGoToNextDepth);
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
177 }
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
178
1
a13620720e35 Add directory for insert verification
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 int main(int argc, char const* argv[]) {
13
f0a1f02e8493 Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
180 goto startCode(PutAndGoToNextDepth);
1
a13620720e35 Add directory for insert verification
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 }