comparison src/llrb/llrb.c @ 54:0299b90256e5

syntax suggest
author kkb
date Thu, 11 Jun 2015 17:23:50 +0900
parents 399ed10d1760
children c469c5ed5b4d
comparison
equal deleted inserted replaced
53:399ed10d1760 54:0299b90256e5
42 printf("key=%d depth=%d\t%p\n", node->key, n, node); 42 printf("key=%d depth=%d\t%p\n", node->key, n, node);
43 print_tree(node->right, n+1); 43 print_tree(node->right, n+1);
44 } 44 }
45 } 45 }
46 46
47 __code meta_code1_before(struct Context* context) {
48 goto code1(context, &context->data[Allocate]->allocate);
49 }
50
47 __code code1(struct Context* context, struct Allocate *allocate) { 51 __code code1(struct Context* context, struct Allocate *allocate) {
48 allocate->size = sizeof(long); 52 allocate->size = sizeof(struct Count);
49 allocate->next = Code2; 53 allocate->next = Code2;
50 goto meta(context, Allocator); 54 goto meta(context, Allocater);
51 } 55 }
52 56
53 /* __code code1(struct Context* context) { */ 57 /* __code code1(struct Context* context) { */
54 /* context->data[Allocate]->allocate.size = sizeof(long); */ 58 /* context->data[Allocate]->allocate.size = sizeof(long); */
55 /* context->data[Allocate]->allocate.next = Code2; */ 59 /* context->data[Allocate]->allocate.next = Code2; */
56 /* goto meta(context, Allocator); */ 60 /* goto meta(context, Allocator); */
57 /* } */ 61 /* } */
58 62
63 /*
64 __code code2(Allocate allocate, Count count) {
65 count.count = 0;
66 goto code3(count);
67 }
68 */
69
70 __code code2_stub(struct Context* context) {
71 goto code2(context, &context->data[context->dataNum]->count);
72 }
73
74 __code code2(struct Context* context, struct Count* count) {
75 count->i = 1;
76 goto meta(context, Code3);
77 }
78
59 __code meta(struct Context* context, enum Code next) { 79 __code meta(struct Context* context, enum Code next) {
60 if (next == Code1)
61 goto code1(context, &context->data[Allocate]->allocate);
62
63 goto (context->code[next])(context); 80 goto (context->code[next])(context);
64 } 81 }
65 82
66 __code put(struct Context* context) { 83 __code put_stub(struct Context* context) {
67 struct Tree* tree = &context->data[Tree]->tree; 84 goto put(context, &context->data[Tree]->tree, &context->data[Allocate]->allocate);
68 context->data[Next]->next = context->data[Allocate]->allocate.next; 85 }
69 86
87 __code put(struct Context* context, struct Tree* tree, struct Allocate* allocate) {
88 allocate->size = sizeof(struct Node);
70 if (tree->root == 0) { 89 if (tree->root == 0) {
71 context->data[Allocate]->allocate.next = Insert; 90 allocate->next = Insert;
72 goto meta(context, Allocator); 91 goto meta(context, Allocator);
73 } 92 }
74 93
75 context->data[Allocate]->allocate.next = Create; 94 allocate->next = Create;
76 tree->current = tree->root; 95 tree->current = tree->root;
77 96
78 goto meta(context, Compare); 97 goto meta(context, Compare);
79 } 98 }
80 99
261 280
262 __code delete(struct Context* context) { 281 __code delete(struct Context* context) {
263 goto meta(context, Get); 282 goto meta(context, Get);
264 } 283 }
265 284
266 /* 285 __code meta_code3_before(struct Context* context) {
267 __code code2(Allocate allocate, Count count) { 286 goto code3(context, &context->data[Node]->node, &context->data[4]->count);
268 count.count = 0; 287 }
269 goto code3(count); 288
270 } 289 __code code3(struct Context* context, struct Node* node, struct Count* count) {
271 */ 290 if (count->i == num) {
272
273 __code code2(struct Context* context) {
274 context->data[4]->count = 1;
275 goto meta(context, Code3);
276 }
277
278 __code code3(struct Context* context) {
279 struct Allocate* allocate = &context->data[Allocate]->allocate;
280 struct Node* node = &context->data[Node]->node;
281 long loop = context->data[4]->count;
282
283 if (loop == num) {
284 goto meta(context, Code4); 291 goto meta(context, Code4);
285 } 292 }
286 293
287 allocate->size = sizeof(struct Node); 294 node->next = Code3;
288 allocate->next = Code3;
289
290 node->key = loop; 295 node->key = loop;
291 node->value = loop; 296 node->value = loop;
292 297
293 context->data[4]->count++; 298 count->i++;
294 goto meta(context, Put); 299 goto meta(context, Put);
295 } 300 }
296
297 __code code4(struct Context* context) { 301 __code code4(struct Context* context) {
298 puts("---before---"); 302 puts("---before---");
299 print_tree(context->data[Tree]->tree.root, 0); 303 print_tree(context->data[Tree]->tree.root, 0);
300 304
301 struct Allocate* allocate = &context->data[Allocate]->allocate; 305 struct Allocate* allocate = &context->data[Allocate]->allocate;