Mercurial > hg > CbC > old > akasha
annotate src/insert_verification/akashaLLRBContext.c @ 32:be67b0312bea
Convert "showTrace" function to CodeSegment
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 07 Jun 2016 15:12:18 +0900 |
parents | 04283ef8f3ca |
children | 593ab851ad76 |
rev | line source |
---|---|
4 | 1 #include <stdlib.h> |
24
8ca38f736745
Fill allocated memory spaces by zero
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
23
diff
changeset
|
2 #include <string.h> |
4 | 3 |
4 #include "akashaLLRBContext.h" | |
5 | |
7 | 6 extern __code showTree_stub(struct Context*); |
11 | 7 extern __code iterateInsertion_stub(struct Context*); |
13
f0a1f02e8493
Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
8 extern __code putAndGoToNextDepth_stub (struct Context*); |
32
be67b0312bea
Convert "showTrace" function to CodeSegment
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
9 extern __code showTrace_stub(struct Context*); |
18
38e8d5a58fe8
Search all paths using iterator for insertion of 7 elements
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
10 extern __code verifySpecification_stub (struct Context*); |
13
f0a1f02e8493
Enumerate single path using iterator
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
12
diff
changeset
|
11 extern __code duplicateIterator_stub(struct Context*); |
16
3acaadc0a60c
Enumerate all insetion patterns
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
15
diff
changeset
|
12 extern __code duplicateIteratorElem_stub(struct Context*); |
17 | 13 extern __code duplicateTree_stub(struct Context*); |
14
1bbaafdafa47
Enumerates all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
14 extern __code goToPreviousDepth(struct Context*); |
6 | 15 |
16 /* definitions from llrb */ | |
9 | 17 extern __code meta(struct Context*, enum Code next); |
4 | 18 extern __code put_stub(struct Context*); |
19 extern __code replaceNode_stub(struct Context*); | |
20 extern __code insertNode_stub(struct Context*); | |
21 extern __code rotateLeft_stub(struct Context*); | |
22 extern __code rotateRight_stub(struct Context*); | |
23 extern __code colorFlip_stub(struct Context*); | |
24 extern __code fixUp_stub(struct Context*); | |
25 extern __code changeReference_stub(struct Context*); | |
26 extern __code insert1_stub(struct Context*); | |
27 extern __code insert2_stub(struct Context*); | |
28 extern __code insert3_stub(struct Context*); | |
29 extern __code insert4_stub(struct Context*); | |
30 extern __code insert4_1_stub(struct Context*); | |
31 extern __code insert4_2_stub(struct Context*); | |
32 extern __code insert5_stub(struct Context*); | |
33 extern __code stackClear_stub(struct Context*); | |
34 extern __code get_stub(struct Context*); | |
35 extern __code search_stub(struct Context*); | |
36 extern __code delete_stub(struct Context*); | |
37 extern __code delete1_stub(struct Context*); | |
38 extern __code delete2_stub(struct Context*); | |
39 extern __code delete3_stub(struct Context*); | |
40 extern __code replaceNodeForDelete1_stub(struct Context*); | |
41 extern __code replaceNodeForDelete2_stub(struct Context*); | |
42 extern __code findMax1_stub(struct Context*); | |
43 extern __code findMax2_stub(struct Context*); | |
44 extern __code deleteCase1_stub(struct Context*); | |
45 extern __code deleteCase2_stub(struct Context*); | |
46 extern __code deleteCase3_stub(struct Context*); | |
47 extern __code deleteCase4_stub(struct Context*); | |
48 extern __code deleteCase5_stub(struct Context*); | |
49 extern __code deleteCase6_stub(struct Context*); | |
6 | 50 extern __code exitCode(struct Context*); |
4 | 51 |
12 | 52 /* for allocator */ |
53 extern void allocator(struct Context* context); | |
54 | |
55 | |
56 __code initIterator(struct Context* context, struct Allocate* allocate, struct Iterator* iter); | |
9 | 57 __code initFinishIterator(struct Context*, struct IterElem*); |
12 | 58 __code initIteratorElem(struct Context* context, struct Allocate* allocate, struct IterElem* prev); |
9 | 59 |
60 __code initLLRBContext(struct Context* context, enum Code next) { | |
23
dcfd4b848886
Support memory refresh
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
61 context->codeNum = Exit; |
dcfd4b848886
Support memory refresh
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
62 |
28
04283ef8f3ca
Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
63 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; |
23
dcfd4b848886
Support memory refresh
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
64 context->code = malloc(sizeof(__code*)*context->codeNum); |
28
04283ef8f3ca
Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
65 context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE); |
4 | 66 context->heapStart = malloc(context->heapLimit); |
28
04283ef8f3ca
Free memory when backed previous depth
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
25
diff
changeset
|
67 memset(context->heapStart, 0, context->heapLimit); |
4 | 68 |
69 | |
16
3acaadc0a60c
Enumerate all insetion patterns
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
15
diff
changeset
|
70 context->code[ShowTree] = showTree_stub; |
3acaadc0a60c
Enumerate all insetion patterns
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
15
diff
changeset
|
71 context->code[IterateInsertion] = iterateInsertion_stub; |
3acaadc0a60c
Enumerate all insetion patterns
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
15
diff
changeset
|
72 context->code[PutAndGoToNextDepth] = putAndGoToNextDepth_stub; |
32
be67b0312bea
Convert "showTrace" function to CodeSegment
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
73 context->code[ShowTrace] = showTrace_stub; |
be67b0312bea
Convert "showTrace" function to CodeSegment
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
74 context->code[VerifySpecification] = verifySpecification_stub; |
16
3acaadc0a60c
Enumerate all insetion patterns
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
15
diff
changeset
|
75 context->code[DuplicateIterator] = duplicateIterator_stub; |
17 | 76 context->code[DuplicateIteratorElem] = duplicateIteratorElem_stub; |
77 context->code[DuplicateTree] = duplicateTree_stub; | |
16
3acaadc0a60c
Enumerate all insetion patterns
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
15
diff
changeset
|
78 context->code[GoToPreviousDepth] = goToPreviousDepth; |
6 | 79 |
80 /* definitions from llrb */ | |
4 | 81 context->code[Put] = put_stub; |
82 context->code[Replace] = replaceNode_stub; | |
83 context->code[Insert] = insertNode_stub; | |
84 context->code[RotateL] = rotateLeft_stub; | |
85 context->code[RotateR] = rotateRight_stub; | |
86 context->code[InsertCase1] = insert1_stub; | |
87 context->code[InsertCase2] = insert2_stub; | |
88 context->code[InsertCase3] = insert3_stub; | |
89 context->code[InsertCase4] = insert4_stub; | |
90 context->code[InsertCase4_1] = insert4_1_stub; | |
91 context->code[InsertCase4_2] = insert4_2_stub; | |
92 context->code[InsertCase5] = insert5_stub; | |
93 context->code[StackClear] = stackClear_stub; | |
6 | 94 context->code[Exit] = exitCode; |
4 | 95 |
96 context->heap = context->heapStart; | |
97 | |
98 context->data[Allocate] = context->heap; | |
99 context->heap += sizeof(struct Allocate); | |
100 | |
101 context->data[Tree] = context->heap; | |
102 context->heap += sizeof(struct Tree); | |
103 | |
104 context->data[Node] = context->heap; | |
105 context->heap += sizeof(struct Node); | |
106 | |
9 | 107 context->data[Iter] = context->heap; |
108 context->heap += sizeof(struct Iterator); | |
109 | |
11 | 110 context->dataNum = Iter; |
4 | 111 |
112 struct Tree* tree = &context->data[Tree]->tree; | |
113 tree->root = 0; | |
114 tree->current = 0; | |
115 tree->deleted = 0; | |
116 | |
21
2112f0024537
Downgrade cmake minimum versions for CentOS7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
117 context->node_stack = stack_init(sizeof(struct Node*), 1000); |
2112f0024537
Downgrade cmake minimum versions for CentOS7
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
118 context->code_stack = stack_init(sizeof(enum Code), 1000); |
9 | 119 |
120 context->next = next; | |
12 | 121 goto initIterator_stub(context); |
4 | 122 } |
9 | 123 |
12 | 124 __code initIterator_stub(struct Context* context) { |
125 goto initIterator(context, &context->data[Allocate]->allocate, &context->data[Iter]->iterator); | |
126 } | |
127 | |
128 __code initIterator(struct Context* context, struct Allocate* allocate, struct Iterator* iter) { | |
129 struct IterElem* ie = context->heap; | |
130 allocate->size = sizeof(struct IterElem); | |
131 allocator(context); | |
9 | 132 |
15
d6d6e075b498
Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
14
diff
changeset
|
133 ie->val = 1; |
9 | 134 ie->next = NULL; |
11 | 135 iter->tree = NULL; |
9 | 136 iter->head = ie; |
137 | |
12 | 138 goto initIteratorElem_stub(context, ie); |
139 } | |
140 __code initIteratorElem_stub(struct Context* context, struct IterElem* prev) { | |
141 goto initIteratorElem(context, &context->data[Allocate]->allocate, prev); | |
9 | 142 } |
143 | |
12 | 144 __code initIteratorElem(struct Context* context, struct Allocate* allocate, struct IterElem* prev) { |
15
d6d6e075b498
Show traces in all paths
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
14
diff
changeset
|
145 if (prev->val == LIMIT_OF_VERIFICATION_SIZE) { goto initFinishIterator(context, prev); } |
9 | 146 |
12 | 147 struct IterElem* ie = context->heap; |
148 allocate->size = sizeof(struct IterElem); | |
149 allocator(context); | |
150 | |
9 | 151 ie->val = prev->val + 1; |
152 prev->next = ie; | |
12 | 153 goto initIteratorElem_stub(context, ie); |
9 | 154 } |
155 | |
156 __code initFinishIterator(struct Context* context, struct IterElem* elem) { | |
11 | 157 struct Iterator* iter = &context->data[Iter]->iterator; |
9 | 158 elem->next = iter->head; |
159 iter->last = iter->head; | |
160 goto meta(context, context->next); | |
161 } |