annotate src/parallel_execution/RedBlackTree.cbc @ 338:0d720487291f

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