annotate src/parallel_execution/rb_tree.c @ 144:d529c024e5a5

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