annotate src/parallel_execution/RedBlackTree.cbc @ 280:2c2e4e597eb0

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