4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <stdlib.h>
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 #include "akashaLLRBContext.h"
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4
|
6
|
5 extern __code insertOnce_stub(struct Context*);
|
7
|
6 extern __code showTree_stub(struct Context*);
|
6
|
7
|
|
8 /* definitions from llrb */
|
4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 extern __code meta(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 extern __code put_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 extern __code replaceNode_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 extern __code insertNode_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 extern __code rotateLeft_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 extern __code rotateRight_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 extern __code colorFlip_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 extern __code fixUp_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 extern __code changeReference_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 extern __code insert1_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 extern __code insert2_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 extern __code insert3_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 extern __code insert4_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 extern __code insert4_1_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 extern __code insert4_2_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 extern __code insert5_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 extern __code stackClear_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 extern __code get_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 extern __code search_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 extern __code delete_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 extern __code delete1_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 extern __code delete2_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 extern __code delete3_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 extern __code replaceNodeForDelete1_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 extern __code replaceNodeForDelete2_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 extern __code findMax1_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 extern __code findMax2_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 extern __code deleteCase1_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 extern __code deleteCase2_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 extern __code deleteCase3_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 extern __code deleteCase4_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 extern __code deleteCase5_stub(struct Context*);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 extern __code deleteCase6_stub(struct Context*);
|
6
|
42 extern __code exitCode(struct Context*);
|
4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43
|
6
|
44 __code initLLRBContext(struct Context* context) {
|
4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
|
6
|
46 context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE);
|
|
47 context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
|
4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 context->heapStart = malloc(context->heapLimit);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 context->codeNum = Exit;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51
|
6
|
52 context->code[InsertOnce] = insertOnce_stub;
|
7
|
53 context->code[ShowTree] = showTree_stub;
|
6
|
54
|
|
55 /* definitions from llrb */
|
4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 context->code[Put] = put_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 context->code[Replace] = replaceNode_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 context->code[Insert] = insertNode_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 context->code[RotateL] = rotateLeft_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 context->code[RotateR] = rotateRight_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 context->code[InsertCase1] = insert1_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 context->code[InsertCase2] = insert2_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 context->code[InsertCase3] = insert3_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 context->code[InsertCase4] = insert4_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 context->code[InsertCase4_1] = insert4_1_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 context->code[InsertCase4_2] = insert4_2_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 context->code[InsertCase5] = insert5_stub;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 context->code[StackClear] = stackClear_stub;
|
6
|
69 context->code[Exit] = exitCode;
|
4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 context->heap = context->heapStart;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 context->data[Allocate] = context->heap;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 context->heap += sizeof(struct Allocate);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 context->data[Tree] = context->heap;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 context->heap += sizeof(struct Tree);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 context->data[Node] = context->heap;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 context->heap += sizeof(struct Node);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 context->dataNum = Node;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 struct Tree* tree = &context->data[Tree]->tree;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 tree->root = 0;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 tree->current = 0;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 tree->deleted = 0;
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 context->node_stack = stack_init(sizeof(struct Node*), 100);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 context->code_stack = stack_init(sizeof(enum Code), 100);
|
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 }
|