comparison src/llrb/llrb.c @ 27:44879c87c2dc

modify
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Fri, 01 May 2015 18:18:36 +0900
parents 06fcbe45e85c
children dbbafae822f8
comparison
equal deleted inserted replaced
26:06fcbe45e85c 27:44879c87c2dc
150 goto meta(context, Allocator); 150 goto meta(context, Allocator);
151 } 151 }
152 152
153 __code rotateLeft(struct Context* context) { 153 __code rotateLeft(struct Context* context) {
154 struct Node* node = &context->data[Tree]->tree.current->node; 154 struct Node* node = &context->data[Tree]->tree.current->node;
155 struct Allocate* allocate = &context->data[Allocate]->allocate;
156
157 allocate->next = ChangeRef;
158 allocate->node.key = node->key;
159 allocate->node.key = node->key;
160 155
161 if (node->right != 0) { 156 if (node->right != 0) {
162 if (node->right->node.color == Red) { 157 if (node->right->node.color == Red) {
163 union Data* tmp = context->data[Tree]->tree.current->node.right; 158 union Data* tmp = context->data[Tree]->tree.current->node.right;
164 context->data[Tree]->tree.current->node.right = tmp->node.left; 159 context->data[Tree]->tree.current->node.right = tmp->node.left;
188 } 183 }
189 } 184 }
190 185
191 goto meta(context, ColorFlip); 186 goto meta(context, ColorFlip);
192 } 187 }
188
193 __code colorFlip(struct Context* context) { 189 __code colorFlip(struct Context* context) {
194 struct Node* node = &context->data[Tree]->tree.current->node; 190 struct Node* node = &context->data[Tree]->tree.current->node;
195 191
196 if (node->right != 0 && node->left != 0) { 192 if (node->right != 0 && node->left != 0) {
197 if (node->right->node.color == Red && node->left->node.color == Red) { 193 if (node->right->node.color == Red && node->left->node.color == Red) {
198 node->color ^= 1; 194 node->color ^= 1;
199 node->left->node.color ^= 1; 195 node->left->node.color ^= 1;
200 node->right->node.color ^= 1; 196 node->right->node.color ^= 1;
201 } 197 }
202 } 198 }
203 199
204 goto meta(context, Compare); 200 goto meta(context, FixUp);
205 } 201 }
202
203 __code fixUp(struct Context* context) {
204 struct Allocate* allocate = &context->data[Allocate]->allocate;
205 struct Node* node = &context->data[Tree]->tree.current->node;
206
207 allocate->next = ChangeRef;
208 allocate->node.key = node->key;
209 allocate->node.key = node->key;
210 context->data[Tree]->tree.prev = context->data[Tree]->tree.current;
211
212 if (stack_pop(pstack, &context->data[Tree]->tree.current) == 0) {
213 goto meta(context, Compare);
214 }
215
216 context->data[Tree]->tree.root = context->data[Tree]->tree.current;
217
218 goto meta(context, context->data[Allocate]->allocate.after_put);
219 }
206 220
207 __code changeReference(struct Context* context) { 221 __code changeReference(struct Context* context) {
208 union Data* data = context->data[Tree]->tree.current; 222 struct Node* node = &context->data[Tree]->tree.current->node;
209 223
210 if (stack_pop(pstack, &context->data[Tree]->tree.current) == 0) { 224 switch (context->data[Tree]->tree.result) {
211 struct Node* node = &context->data[Tree]->tree.current->node; 225 case 1:
212 226 node->left = context->data[Tree]->tree.prev;
213 switch (context->data[Tree]->tree.result) { 227 break;
214 case 1: 228 default:
215 node->left = data; 229 node->right = context->data[Tree]->tree.prev;
216 break; 230 break;
217 default: 231 }
218 node->right = data; 232
219 break; 233 goto meta(context, RotateL);
220 } 234 }
221
222 goto meta(context, RotateL);
223 }
224
225 context->data[Tree]->tree.root = context->data[Tree]->tree.current;
226
227 goto meta(context, context->data[Allocate]->allocate.after_put);
228 }
229
230 235
231 /* 236 /*
232 __code code2(Allocate allocate, Count count) { 237 __code code2(Allocate allocate, Count count) {
233 count.count = 0; 238 count.count = 0;
234 goto code3(count); 239 goto code3(count);
235 } 240 }
236 */ 241 */
237 242
238 __code code2(struct Context* context) { 243 __code code2(struct Context* context) {
239 context->data[2]->count = 0; 244 context->data[2]->count = 1;
240 goto meta(context, Code3); 245 goto meta(context, Code3);
241 } 246 }
242 247
243 __code code3(struct Context* context) { 248 __code code3(struct Context* context) {
244 struct Allocate* allocate = &context->data[Allocate]->allocate; 249 struct Allocate* allocate = &context->data[Allocate]->allocate;
257 262
258 __code code4(struct Context* context) { 263 __code code4(struct Context* context) {
259 pre = context->data[Tree]->tree.root; 264 pre = context->data[Tree]->tree.root;
260 context->data[Allocate]->allocate.size = sizeof(struct Node); 265 context->data[Allocate]->allocate.size = sizeof(struct Node);
261 context->data[Allocate]->allocate.after_put = Code5; 266 context->data[Allocate]->allocate.after_put = Code5;
262 context->data[Allocate]->allocate.node.key = num; 267 context->data[Allocate]->allocate.node.key = 0;
263 context->data[Allocate]->allocate.node.value = num; 268 context->data[Allocate]->allocate.node.value = 0;
264 269
265 goto meta(context, Put); 270 goto meta(context, Put);
266 } 271 }
267 272
268 __code code5(struct Context* context) { 273 __code code5(struct Context* context) {