comparison src/llrb/llrb.c @ 19:9302b1a48008

add llrb
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Tue, 21 Apr 2015 22:36:23 +0900
parents
children 324c44f2076f
comparison
equal deleted inserted replaced
18:ec4e7a81bddf 19:9302b1a48008
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "llrbContext.h"
5
6 #include "allocate.h"
7 #include "origin_cs.h"
8
9 #ifdef CLANG
10 #define _CbC_retrun __return
11 #define _CbC_environment __environment
12 #endif
13
14 #define NUM 100
15 #define ALLOCATE_SIZE 1024
16
17 extern __code initLLRBContext(struct Context* context);
18 /*
19 __code code1(Allocate allocate) {
20 allocate.size = sizeof(long);
21 allocate.next = Code2;
22 goto Allocate(allocate);
23 }
24 */
25
26 __code code1(struct Context* context) {
27 context->data[0]->allocate.size = sizeof(struct Node);
28 context->data[0]->allocate.next = Put;
29 context->data[0]->allocate.after_put = Code2;
30 goto meta(context, Allocate);
31 }
32
33 __code meta(struct Context* context, enum Code next) {
34 goto (context->code[next])(context);
35 }
36
37 __code put(struct Context* context) {
38 context->data[context->dataSize]->node.key = context->data[0]->allocate.key;
39 context->data[context->dataSize]->node.value = context->data[0]->allocate.value;
40 if (context->root == 0) {
41 context->root = context->data[context->dataSize];
42 context->root->node.color = Red;
43 goto meta(context, context->data[0]->allocate.after_put);
44 }
45 goto meta(context, Insert);
46 }
47
48 __code insert(struct Context* context) {
49 goto meta(context, context->data[0]->allocate.after_put);
50 }
51
52 /*
53 __code code2(Allocate allocate, Count count) {
54 count.count = 0;
55 goto code3(count);
56 }
57 */
58
59 __code code2(struct Context* context) {
60 goto meta(context, Exit);
61 }
62
63 int main() {
64 struct Context* context = (struct Context*)malloc(sizeof(struct Context));
65 context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE);
66 context->data = malloc(sizeof(union Data**)*ALLOCATE_SIZE);
67 context->heap = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
68 initLLRBContext(context);
69 goto start_code(context, Code1);
70 }