86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <stdio.h>
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 #include "context.h"
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 #include "origin_cs.h"
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 extern void allocator(struct Context* context);
|
91
|
7 extern void compare(struct Context* context, struct Traverse* traverse, int key1, int key2);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8
|
126
|
9 void printTree1(union Data* data) {
|
|
10 struct Node* node = (struct Node*)data;
|
|
11 if (node == NULL) {
|
|
12 printf("NULL");
|
|
13 } else {
|
|
14 printf("key = %d (", node->key);
|
|
15 printTree1((union Data*)node->right);
|
|
16 printf("), (");
|
|
17 printTree1((union Data*)node->left);
|
|
18 printf(")");
|
|
19 }
|
|
20 }
|
|
21
|
|
22 void printTree(union Data* data) {
|
|
23 printTree1(data);
|
|
24 printf("\n");
|
|
25 }
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26
|
124
|
27 __code put(struct Context* context, struct Tree* tree, struct Node* node, struct Traverse* traverse, struct Node* root, struct Node* newNode) {
|
126
|
28 printTree((union Data*)tree->root);
|
122
|
29 traverse->newNode = newNode;
|
|
30 tree->root = newNode; // this should done at stackClear
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 if (root) {
|
91
|
32 traverse->current = root;
|
117
|
33 // traverse->result=compare(...)
|
121
|
34 compare(context, traverse, traverse->current->key, node->key);
|
|
35 // goto replaceNode(traverse->current, newNode, traverse->result);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 goto meta(context, Replace);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 goto meta(context, Insert);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 __code put_stub(struct Context* context) {
|
121
|
43 struct Allocate* allocate = &context->data[Allocate]->allocate;
|
|
44 allocate->size = sizeof(struct Node);
|
|
45 allocator(context);
|
|
46
|
91
|
47 goto put(context,
|
|
48 &context->data[Tree]->tree,
|
124
|
49 &context->data[Node]->node,
|
91
|
50 &context->data[Traverse]->traverse,
|
|
51 context->data[Tree]->tree.root,
|
124
|
52 &context->data[context->dataNum]->node
|
|
53 );
|
121
|
54 }
|
|
55
|
|
56 __code replaceNode(struct Context* context, struct Traverse* traverse, struct Node* oldNode, struct Node* newNode, struct Element* element) {
|
|
57 *newNode = *oldNode;
|
124
|
58 element->next = traverse->nodeStack;
|
|
59 element->data = (union Data* )newNode;
|
|
60 traverse->nodeStack = element;
|
122
|
61 // goto replaceNode1(struct Traverse* traverse, struct Node* node, struct Node* oldNode, struct Node* newNode, +struct Node* newnewNode, int result)
|
121
|
62 goto meta(context, Replace1);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64
|
121
|
65 __code replaceNode_stub(struct Context* context) {
|
|
66 struct Allocate* allocate = &context->data[Allocate]->allocate;
|
|
67 allocate->size = sizeof(struct Element);
|
|
68 allocator(context);
|
124
|
69 struct Element* element = &context->data[context->dataNum]->element;
|
121
|
70 goto replaceNode(context,
|
|
71 &context->data[Traverse]->traverse,
|
|
72 context->data[Traverse]->traverse.current,
|
122
|
73 context->data[Traverse]->traverse.newNode,
|
121
|
74 element);
|
|
75 }
|
|
76
|
|
77 __code replaceNode1(struct Context* context, struct Traverse* traverse, struct Node* node, struct Node* oldNode, struct Node* newNode, struct Node* newnewNode, int result) {
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 if (result == EQ) {
|
121
|
79 newNode->value = node->value;
|
117
|
80 // go to stack clear
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 goto meta(context, context->next);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 } else if (result == GT) {
|
91
|
83 traverse->current = oldNode->right;
|
121
|
84 newNode->right = newnewNode;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 } else {
|
91
|
86 traverse->current = oldNode->left;
|
121
|
87 newNode->left = newnewNode;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 }
|
122
|
89 traverse->newNode = newnewNode;
|
91
|
90 if (traverse->current) {
|
121
|
91 compare(context, traverse, traverse->current->key, node->key);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 goto meta(context, Replace);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 goto meta(context, Insert);
|
121
|
96
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98
|
121
|
99 __code replaceNode1_stub(struct Context* context) {
|
|
100 struct Allocate* allocate = &context->data[Allocate]->allocate;
|
|
101 allocate->size = sizeof(struct Node);
|
|
102 allocator(context);
|
|
103 struct Node* newnewNode = &context->data[context->dataNum]->node;
|
|
104 goto replaceNode1(context,
|
91
|
105 &context->data[Traverse]->traverse,
|
124
|
106 &context->data[Node]->node,
|
91
|
107 context->data[Traverse]->traverse.current,
|
124
|
108 &context->data[Traverse]->traverse.nodeStack->data->node,
|
|
109 newnewNode,
|
91
|
110 context->data[Traverse]->traverse.result);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112
|
127
|
113 __code insertNode(struct Context* context, struct Traverse* traverse, struct Node* node, struct Node* newNode) {
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 *newNode = *node;
|
122
|
115 newNode->color = Red;
|
91
|
116 traverse->current = newNode;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 goto meta(context, InsertCase1);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120 __code insertNode_stub(struct Context* context) {
|
91
|
121 goto insertNode(context,
|
|
122 &context->data[Traverse]->traverse,
|
|
123 &context->data[Node]->node,
|
124
|
124 context->data[Traverse]->traverse.newNode);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
125 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126
|
127
|
127 __code insertCase1(struct Context* context, struct Tree* tree,struct Element* nodeStack) {
|
125
|
128 if (nodeStack!=NULL) {
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 goto meta(context, InsertCase2);
|
122
|
130 }
|
127
|
131 tree->root->color = Black;
|
119
|
132 goto meta(context, StackClear);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
134
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 __code insert1_stub(struct Context* context) {
|
127
|
136 goto insertCase1(context,
|
|
137 &context->data[Tree]->tree,
|
|
138 context->data[Traverse]->traverse.nodeStack);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140
|
122
|
141 __code insertCase2(struct Context* context, struct Node* parent) {
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 if (parent->color == Black) {
|
119
|
143 goto meta(context, StackClear);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
144 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145 goto meta(context, InsertCase3);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148 __code insert2_stub(struct Context* context) {
|
124
|
149 goto insertCase2(context, (struct Node*)context->data[Traverse]->traverse.nodeStack->data);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151
|
124
|
152 __code insertCase3(struct Context* context, struct Traverse* traverse, struct Node* parent, struct Node* grandparent) {
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
153 struct Node* uncle;
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
154
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155 if (grandparent->left == parent)
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 uncle = grandparent->right;
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
157 else
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
158 uncle = grandparent->left;
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
159
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
160 if (uncle && (uncle->color == Red)) {
|
117
|
161 // do insertcase1 on grandparent, stack must be pop by two
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
162 parent->color = Black;
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
163 uncle->color = Black;
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
164 grandparent->color = Red;
|
91
|
165 traverse->current = grandparent;
|
124
|
166 goto meta(context, InsertCase31);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
168 goto meta(context, InsertCase4);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
169 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171 __code insert3_stub(struct Context* context) {
|
122
|
172 goto insertCase3(context, &context->data[Traverse]->traverse,
|
124
|
173 (struct Node*)context->data[Traverse]->traverse.nodeStack->data,
|
|
174 (struct Node*)context->data[Traverse]->traverse.nodeStack->next->data
|
122
|
175 );
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 }
|
122
|
177 __code insertCase31(struct Context* context, struct Traverse* traverse) {
|
|
178 traverse->nodeStack = traverse->nodeStack->next->next;
|
120
|
179 goto meta(context, InsertCase1);
|
|
180 }
|
122
|
181 __code insert31_stub(struct Context* context) {
|
|
182 goto insertCase31(context, &context->data[Traverse]->traverse);
|
120
|
183 }
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184
|
122
|
185 __code insertCase4(struct Context* context, struct Traverse* traverse, struct Node* current,struct Node* parent, struct Node* grandparent) {
|
91
|
186 traverse->current = parent;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
187
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
188 if ((current == parent->right) && (parent == grandparent->left)) {
|
119
|
189 traverse->rotateNext = InsertCase4_1;
|
122
|
190 goto meta(context, InsertCase4_01);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191 } else if ((current == parent->left) && (parent == grandparent->right)) {
|
119
|
192 traverse->rotateNext = InsertCase4_2;
|
122
|
193 goto meta(context, InsertCase4_02);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
195
|
91
|
196 traverse->current = current;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197 goto meta(context, InsertCase5);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
198 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
199
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
200 __code insert4_stub(struct Context* context) {
|
124
|
201 goto insertCase4(context, &context->data[Traverse]->traverse, context->data[Traverse]->traverse.current,
|
|
202 &context->data[Traverse]->traverse.nodeStack->data->node,
|
|
203 &context->data[Traverse]->traverse.nodeStack->next->data->node);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
204 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
205
|
122
|
206 __code insertCase4_01(struct Context* context, struct Traverse* traverse) {
|
126
|
207 traverse->nodeStack = traverse->nodeStack -> next;
|
|
208 traverse->rotateNext = InsertCase5;
|
122
|
209 goto meta(context, RotateL);
|
|
210 }
|
|
211
|
|
212 __code insert4_01_stub(struct Context* context) {
|
|
213 goto insertCase4_01(context, &context->data[Traverse]->traverse);
|
|
214 }
|
91
|
215 __code insertCase4_1(struct Context* context, struct Traverse* traverse) {
|
|
216 traverse->current = traverse->current->left;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
217 goto meta(context, InsertCase5);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
218 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
220 __code insert4_1_stub(struct Context* context) {
|
122
|
221 struct Allocate* allocate = &context->data[Allocate]->allocate;
|
|
222 allocate->size = sizeof(struct Element);
|
|
223 allocator(context);
|
124
|
224 struct Element* element = &context->data[context->dataNum]->element;
|
|
225 struct Traverse* traverse = &context->data[Traverse]->traverse;
|
|
226 element->data = (union Data*)traverse->current;
|
91
|
227 goto insertCase4_1(context, &context->data[Traverse]->traverse);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
228 }
|
122
|
229 __code insertCase4_02(struct Context* context, struct Traverse* traverse) {
|
126
|
230 traverse->nodeStack = traverse->nodeStack -> next;
|
|
231 traverse->rotateNext = InsertCase5;
|
122
|
232 goto meta(context, RotateR);
|
|
233 }
|
|
234
|
|
235 __code insert4_02_stub(struct Context* context) {
|
|
236 goto insertCase4_02(context, &context->data[Traverse]->traverse);
|
|
237 }
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
238
|
91
|
239 __code insertCase4_2(struct Context* context, struct Traverse* traverse) {
|
|
240 traverse->current = traverse->current->right;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
241 goto meta(context, InsertCase5);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
242 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
243
|
123
|
244 __code insert4_2_stub(struct Context* context) {
|
122
|
245 struct Allocate* allocate = &context->data[Allocate]->allocate;
|
|
246 allocate->size = sizeof(struct Element);
|
|
247 allocator(context);
|
124
|
248 struct Element* element = &context->data[context->dataNum]->element;
|
|
249 struct Traverse* traverse = &context->data[Traverse]->traverse;
|
|
250 element->data = (union Data*)traverse->current;
|
91
|
251 goto insertCase4_2(context, &context->data[Traverse]->traverse);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
252 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
253
|
124
|
254 __code insertCase5(struct Context* context, struct Traverse* traverse, struct Node* current, struct Node* parent, struct Node* grandparent) {
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
255 parent->color = Black;
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
256 grandparent->color = Red;
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
257
|
91
|
258 traverse->current = grandparent;
|
119
|
259 traverse->rotateNext = StackClear;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
260 if ((current == parent->left) && (parent == grandparent->left))
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
261 goto meta(context, RotateR);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
262 else
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
263 goto meta(context, RotateL);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
264 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
265
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
266 __code insert5_stub(struct Context* context) {
|
124
|
267 struct Traverse* traverse = &context->data[Traverse]->traverse;
|
122
|
268 struct Node* parent = (struct Node*)traverse->nodeStack->data;
|
|
269 struct Node* grandparent = (struct Node*)traverse->nodeStack->next->data;
|
|
270 traverse->nodeStack = traverse->nodeStack->next->next;
|
124
|
271 goto insertCase5(context, &context->data[Traverse]->traverse, context->data[Traverse]->traverse.current, parent, grandparent);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
272 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
273
|
117
|
274 // put rotateLeft's continuation as argument
|
126
|
275 __code rotateLeft(struct Context* context, struct Node* node, struct Tree* tree, struct Traverse* traverse, struct Node* parent) {
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
276 struct Node* tmp = node->right;
|
123
|
277
|
|
278 if (parent) {
|
|
279 if (node == parent->left)
|
|
280 parent->left = tmp;
|
|
281 else
|
|
282 parent->right = tmp;
|
|
283 } else {
|
|
284 tree->root = tmp;
|
|
285 }
|
117
|
286
|
123
|
287 node->right = tmp->left;
|
|
288 tmp->left = node;
|
|
289 traverse->current = tmp;
|
|
290
|
|
291 goto meta(context, traverse->rotateNext);
|
|
292 }
|
|
293
|
|
294 __code rotateLeft_stub(struct Context* context) {
|
124
|
295 struct Traverse* traverse = &context->data[Traverse]->traverse;
|
123
|
296 struct Node* parent = (traverse->nodeStack)?(struct Node*)traverse->nodeStack->data:NULL;
|
|
297 goto rotateLeft(context,
|
125
|
298 context->data[Traverse]->traverse.current,
|
123
|
299 &context->data[Tree]->tree,
|
124
|
300 &context->data[Traverse]->traverse,
|
126
|
301 parent);
|
123
|
302 }
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
303
|
126
|
304 __code rotateRight(struct Context* context, struct Node* node, struct Tree* tree, struct Traverse* traverse, struct Node* parent) {
|
123
|
305 struct Node* tmp = node->left;
|
|
306
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
307 if (parent) {
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
308 if (node == parent->left)
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
309 parent->left = tmp;
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
310 else
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
311 parent->right = tmp;
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
312 } else {
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
313 tree->root = tmp;
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
314 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
315
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
316 node->left = tmp->right;
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
317 tmp->right = node;
|
91
|
318 traverse->current = tmp;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
319
|
119
|
320 goto meta(context, traverse->rotateNext);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
321 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
322
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
323 __code rotateRight_stub(struct Context* context) {
|
125
|
324 struct Traverse* traverse = &context->data[Traverse]->traverse;
|
|
325 struct Node* parent = (traverse->nodeStack)?(struct Node*)traverse->nodeStack->data:NULL;
|
91
|
326 goto rotateRight(context,
|
125
|
327 context->data[Traverse]->traverse.current,
|
124
|
328 &context->data[Tree]->tree,
|
|
329 &context->data[Traverse]->traverse,
|
126
|
330 parent);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
331 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
332
|
91
|
333 __code stackClear(struct Context* context, stack_ptr node_stack, struct Traverse* traverse) {
|
|
334 traverse->current = 0;
|
127
|
335 traverse->nodeStack = NULL;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
336
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
337 goto meta(context, context->next);
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
338 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
339
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
340 __code stackClear_stub(struct Context* context) {
|
91
|
341 goto stackClear(context, context->node_stack, &context->data[Traverse]->traverse);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
342 }
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
343
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
344
|
92
|
345 __code get(struct Context* context, struct Tree* tree, struct Traverse* traverse) {
|
|
346 if (tree->root) {
|
|
347 traverse->current = tree->root;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
348
|
92
|
349 goto meta(context, Search);
|
|
350 }
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
351
|
119
|
352 goto meta(context, context->next);
|
92
|
353 }
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
354
|
92
|
355 __code get_stub(struct Context* context) {
|
|
356 goto get(context, &context->data[Tree]->tree, &context->data[Traverse]->traverse);
|
|
357 }
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
358
|
91
|
359 __code search(struct Context* context, struct Traverse* traverse, struct Node* node) {
|
|
360 compare(context, traverse, traverse->current->key, node->key);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
361
|
91
|
362 if (traverse->result == EQ) {
|
|
363 *node = *traverse->current;
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
364
|
91
|
365 goto meta(context, context->next);
|
|
366 } else if (traverse->result == GT) {
|
|
367 traverse->current = traverse->current->right;
|
|
368 } else {
|
|
369 traverse->current = traverse->current->left;
|
|
370 }
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
371
|
91
|
372 if (traverse->current)
|
|
373 goto meta(context, Search);
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
374
|
91
|
375 goto meta(context, context->next);
|
|
376 }
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
377
|
91
|
378 __code search_stub(struct Context* context) {
|
|
379 goto search(context, &context->data[Traverse]->traverse, &context->data[Node]->node);
|
|
380 }
|
86
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
381
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
382 /* /\* __code delete(struct Context* context, struct Tree* tree) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
383 /* /\* if (tree->root) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
384 /* /\* stack_push(context->code_stack, &context->next); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
385 /* /\* context->next = Delete1; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
386 /* /\* goto meta(context, Get); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
387 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
388
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
389 /* /\* goto meta(context, context->next); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
390 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
391
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
392 /* /\* __code delete_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
393 /* /\* goto delete(context, &context->data[Tree]->tree); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
394 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
395
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
396 /* /\* __code delete1(struct Context* context, struct Tree* tree, struct Allocate* allocate) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
397 /* /\* allocate->size = sizeof(struct Node); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
398 /* /\* allocator(context); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
399
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
400 /* /\* struct Node* root = tree->root; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
401
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
402 /* /\* tree->root = &context->data[context->dataNum]->node; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
403 /* /\* tree->current = root; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
404
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
405 /* /\* compare(context, tree, tree->current->key, context->data[Node]->node.key); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
406
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
407 /* /\* goto meta(context, Replace_d1); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
408 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
409
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
410 /* /\* __code delete1_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
411 /* /\* goto delete1(context, &context->data[Tree]->tree, &context->data[Allocate]->allocate); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
412 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
413
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
414 /* /\* __code delete2(struct Context* context, struct Node* current) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
415 /* /\* if (current->color == Black) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
416 /* /\* struct Node* child = current->right == NULL ? current->left : current->right; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
417 /* /\* current->color = child == NULL ? Black : child->color; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
418
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
419 /* /\* goto meta(context, DeleteCase1); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
420 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
421
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
422 /* /\* goto meta(context, Delete3); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
423 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
424
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
425 /* /\* __code delete2_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
426 /* /\* goto delete2(context, context->data[Tree]->tree.current); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
427 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
428
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
429 /* /\* __code delete3(struct Context* context, struct Tree* tree, struct Node* current) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
430 /* /\* struct Node* tmp = current->right == NULL ? current->left : current->right; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
431
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
432 /* /\* if (current->parent) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
433 /* /\* if (current == current->parent->left) *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
434 /* /\* current->parent->left = tmp; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
435 /* /\* else *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
436 /* /\* current->parent->right = tmp; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
437 /* /\* } else { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
438 /* /\* tree->root = tmp; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
439 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
440
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
441 /* /\* if (tmp) *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
442 /* /\* tmp->parent = current->parent; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
443
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
444 /* /\* if (current->parent == NULL && tmp) *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
445 /* /\* tmp->color = Black; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
446
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
447 /* /\* current == current->parent->left ? (current->parent->left = NULL) : (current->parent->right = NULL); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
448
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
449 /* /\* stack_pop(context->code_stack, &context->next); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
450 /* /\* goto meta(context, context->next); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
451 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
452
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
453 /* /\* __code delete3_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
454 /* /\* goto delete3(context, &context->data[Tree]->tree, context->data[Tree]->tree.current); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
455 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
456
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
457 /* /\* __code replaceNodeForDelete1(struct Context* context, struct Tree* tree, struct Node* oldNode, struct Node* newNode, int result) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
458 /* /\* *newNode = *oldNode; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
459
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
460 /* /\* if (result == EQ) *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
461 /* /\* goto meta(context, Replace_d2); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
462 /* /\* else if (result == GT) *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
463 /* /\* tree->current = newNode->right; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
464 /* /\* else *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
465 /* /\* tree->current = newNode->left; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
466
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
467 /* /\* tree->current->parent = newNode; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
468
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
469 /* /\* if (tree->current->left == NULL && tree->current->right == NULL) *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
470 /* /\* goto meta(context, Delete2); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
471
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
472 /* /\* if (result == GT) *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
473 /* /\* newNode->right = context->heap; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
474 /* /\* else if (result == LT) *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
475 /* /\* newNode->left = context->heap; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
476
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
477 /* /\* allocator(context); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
478
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
479 /* /\* compare(context, tree, tree->current->key, context->data[Node]->node.key); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
480
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
481 /* /\* goto meta(context, Replace_d1); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
482 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
483
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
484 /* /\* __code replaceNodeForDelete1_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
485 /* /\* goto replaceNodeForDelete1(context, &context->data[Tree]->tree, context->data[Tree]->tree.current, &context->data[context->dataNum]->node, context->data[Tree]->tree.result); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
486 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
487
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
488 /* /\* __code replaceNodeForDelete2(struct Context* context, struct Tree* tree, struct Node* newNode) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
489 /* /\* if (tree->current->left && tree->current->right) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
490 /* /\* newNode->left->parent = newNode; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
491 /* /\* tree->current = newNode->left; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
492 /* /\* newNode->left = context->heap; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
493 /* /\* tree->deleted = newNode; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
494
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
495 /* /\* allocator(context); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
496 /* /\* tree->current->parent = newNode; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
497
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
498 /* /\* goto meta(context, FindMax1); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
499 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
500
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
501 /* /\* goto meta(context, Delete2); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
502 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
503
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
504 /* /\* __code replaceNodeForDelete2_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
505 /* /\* goto replaceNodeForDelete2(context, &context->data[Tree]->tree, &context->data[context->dataNum]->node); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
506 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
507
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
508 /* /\* __code findMax1(struct Context* context, struct Tree* tree, struct Node* oldNode, struct Node* newNode) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
509 /* /\* *newNode = *oldNode; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
510
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
511 /* /\* if (newNode->right) *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
512 /* /\* goto meta(context, FindMax2); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
513
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
514 /* /\* tree->deleted->key = newNode->key; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
515 /* /\* tree->deleted->value = newNode->value; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
516
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
517 /* /\* tree->current = newNode; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
518
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
519 /* /\* goto meta(context, Delete2); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
520 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
521
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
522 /* /\* __code findMax1_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
523 /* /\* goto findMax1(context, &context->data[Tree]->tree, context->data[Tree]->tree.current, &context->data[context->dataNum]->node); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
524 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
525
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
526
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
527 /* /\* __code findMax2(struct Context* context, struct Tree* tree, struct Node* oldNode, struct Node* newNode) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
528 /* /\* *newNode = *oldNode; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
529
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
530 /* /\* if (newNode->right->right) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
531 /* /\* tree->current = newNode->right; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
532 /* /\* newNode->right = context->heap; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
533
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
534 /* /\* allocator(context); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
535 /* /\* tree->current->parent = newNode; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
536
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
537 /* /\* goto meta(context, FindMax2); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
538 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
539
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
540 /* /\* tree->deleted->key = newNode->right->key; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
541 /* /\* tree->deleted->value = newNode->right->value; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
542
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
543 /* /\* tree->current = newNode; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
544
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
545 /* /\* goto meta(context, Delete2); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
546 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
547
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
548 /* /\* __code findMax2_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
549 /* /\* goto findMax2(context, &context->data[Tree]->tree, context->data[Tree]->tree.current, &context->data[context->dataNum]->node); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
550 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
551
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
552 /* /\* __code deleteCase1(struct Context* context, struct Node* current) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
553 /* /\* if (current->parent) *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
554 /* /\* goto meta(context, DeleteCase2); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
555
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
556 /* /\* goto meta(context, Delete3); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
557 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
558
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
559 /* /\* __code deleteCase1_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
560 /* /\* goto deleteCase1(context, context->data[Tree]->tree.current); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
561 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
562
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
563 /* /\* __code deleteCase2(struct Context* context, struct Tree* tree, struct Node* current) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
564 /* /\* struct Node* sibling = current == current->parent->left ? current->parent->right : current->parent->left; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
565
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
566 /* /\* if ((sibling == NULL ? Black : sibling->color) == Red) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
567 /* /\* current->parent->color = Red; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
568 /* /\* sibling->color = Black; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
569
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
570 /* /\* current == current->parent->left ? (current->parent->left = context->heap) : (current->parent->right = context->heap); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
571 /* /\* allocator(context); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
572 /* /\* context->data[context->dataNum]->node = *sibling; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
573
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
574 /* /\* tree->current = current->parent; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
575
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
576 /* /\* context->next = DeleteCase3; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
577 /* /\* stack_push(context->code_stack, &context->next); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
578
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
579 /* /\* if (current == current->parent->left) *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
580 /* /\* goto meta(context, RotateL); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
581 /* /\* else *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
582 /* /\* goto meta(context, RotateR); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
583 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
584
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
585 /* /\* goto meta(context, DeleteCase3); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
586 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
587
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
588 /* /\* __code deleteCase2_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
589 /* /\* goto deleteCase2(context, &context->data[Tree]->tree, context->data[Tree]->tree.current); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
590 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
591
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
592 /* /\* __code deleteCase3(struct Context* context, struct Tree* tree, struct Node* current) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
593 /* /\* struct Node* sibling = current == current->parent->left ? current->parent->right : current->parent->left; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
594
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
595 /* /\* if (current->parent->color == Black && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
596 /* /\* (sibling == NULL ? Black : sibling->color) == Black && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
597 /* /\* (sibling->left == NULL ? Black : sibling->left->color) == Black && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
598 /* /\* (sibling->right == NULL ? Black : sibling->right->color) == Black) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
599 /* /\* sibling->color = Red; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
600
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
601 /* /\* tree->current = current->parent; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
602 /* /\* goto meta(context, DeleteCase1); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
603 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
604
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
605 /* /\* goto meta(context, DeleteCase4); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
606 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
607
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
608 /* /\* __code deleteCase3_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
609 /* /\* goto deleteCase3(context, &context->data[Tree]->tree, context->data[Tree]->tree.current); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
610 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
611
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
612 /* /\* __code deleteCase4(struct Context* context, struct Node* current) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
613 /* /\* struct Node* sibling = current == current->parent->left ? current->parent->right : current->parent->left; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
614
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
615 /* /\* if (current->parent->color == Red && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
616 /* /\* (sibling == NULL ? Black : sibling->color) == Black && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
617 /* /\* (sibling->left == NULL ? Black : sibling->left->color) == Black && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
618 /* /\* (sibling->right == NULL ? Black : sibling->right->color) == Black) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
619 /* /\* sibling->color = Red; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
620 /* /\* current->parent->color = Black; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
621
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
622 /* /\* goto meta(context, Delete3); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
623 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
624
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
625 /* /\* goto meta(context, DeleteCase5); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
626 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
627
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
628 /* /\* __code deleteCase4_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
629 /* /\* goto deleteCase4(context, context->data[Tree]->tree.current); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
630 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
631
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
632 /* /\* __code deleteCase5(struct Context* context, struct Tree* tree, struct Node* current) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
633 /* /\* struct Node* sibling = current == current->parent->left ? current->parent->right : current->parent->left; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
634 /* /\* sibling->parent = current->parent; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
635
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
636 /* /\* if (current == current->parent->left && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
637 /* /\* (sibling == NULL ? Black : sibling->color) == Black && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
638 /* /\* (sibling->left == NULL ? Black : sibling->left->color) == Red && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
639 /* /\* (sibling->right == NULL ? Black : sibling->right->color) == Black) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
640 /* /\* sibling->color = Red; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
641 /* /\* sibling->left->color = Black; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
642
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
643 /* /\* sibling == sibling->parent->left ? (sibling->parent->left = context->heap) : (sibling->parent->right = context->heap); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
644 /* /\* allocator(context); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
645 /* /\* struct Node* tmp = &context->data[context->dataNum]->node; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
646 /* /\* *tmp = *sibling; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
647 /* /\* tmp->parent = current; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
648
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
649 /* /\* tmp->left = context->heap; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
650 /* /\* allocator(context); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
651 /* /\* context->data[context->dataNum]->node = *sibling->left; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
652 /* /\* context->data[context->dataNum]->node.parent = tmp; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
653
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
654 /* /\* tree->current = tmp; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
655
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
656 /* /\* context->next = DeleteCase6; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
657 /* /\* stack_push(context->code_stack, &context->next); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
658
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
659 /* /\* goto meta(context, RotateR); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
660 /* /\* } else if (current == current->parent->right && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
661 /* /\* (sibling == NULL ? Black : sibling->color) == Black && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
662 /* /\* (sibling->left == NULL ? Black : sibling->left->color) == Black && *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
663 /* /\* (sibling->right == NULL ? Black : sibling->right->color) == Red) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
664 /* /\* sibling->color = Red; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
665 /* /\* sibling->right->color = Black; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
666
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
667 /* /\* sibling == sibling->parent->left ? (sibling->parent->left = context->heap) : (sibling->parent->right = context->heap); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
668 /* /\* allocator(context); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
669 /* /\* struct Node* tmp = &context->data[context->dataNum]->node; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
670 /* /\* *tmp = *sibling; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
671 /* /\* tmp->parent = current; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
672
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
673 /* /\* tmp->right = context->heap; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
674 /* /\* allocator(context); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
675 /* /\* context->data[context->dataNum]->node = *sibling->right; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
676 /* /\* context->data[context->dataNum]->node.parent = tmp; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
677
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
678 /* /\* tree->current = tmp; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
679
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
680 /* /\* context->next = DeleteCase6; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
681 /* /\* stack_push(context->code_stack, &context->next); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
682 /* /\* goto meta(context, RotateL); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
683 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
684
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
685 /* /\* goto meta(context, DeleteCase6); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
686 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
687
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
688 /* /\* __code deleteCase5_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
689 /* /\* goto deleteCase5(context, &context->data[Tree]->tree, context->data[Tree]->tree.current); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
690 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
691
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
692 /* /\* __code deleteCase6(struct Context* context, struct Tree* tree, struct Node* current) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
693 /* /\* struct Node* sibling = current == current->parent->left ? current->parent->right : current->parent->left; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
694
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
695 /* /\* sibling == sibling->parent->left ? (sibling->parent->left = context->heap) : (sibling->parent->right = context->heap); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
696 /* /\* allocator(context); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
697 /* /\* struct Node* tmp = &context->data[context->dataNum]->node; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
698 /* /\* *tmp = *sibling; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
699 /* /\* tmp->parent = current; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
700
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
701 /* /\* tmp->color = current->parent->color; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
702 /* /\* current->parent->color = Black; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
703
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
704 /* /\* context->next = Delete3; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
705 /* /\* stack_push(context->code_stack, &context->next); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
706
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
707 /* /\* if (current == current->parent->left) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
708 /* /\* tmp->right->color = Black; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
709 /* /\* tree->current = current->parent; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
710
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
711 /* /\* goto meta(context, RotateL); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
712 /* /\* } else { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
713 /* /\* tmp->left->color = Black; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
714 /* /\* tree->current = current->parent; *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
715
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
716 /* /\* goto meta(context, RotateR); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
717 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
718 /* /\* } *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
719
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
720 /* /\* __code deleteCase6_stub(struct Context* context) { *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
721 /* /\* goto deleteCase6(context, &context->data[Tree]->tree, context->data[Tree]->tree.current); *\/ */
|
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
722 /* /\* } *\/ */
|