comparison src/parallel_execution/RedBlackTree.cbc @ 426:02313bbfe900

fix RedBlackTree.cbc
author mir3636
date Fri, 06 Oct 2017 19:48:42 +0900
parents 3c6af75b13d4
children f02bd096af64
comparison
equal deleted inserted replaced
425:ea6353b6c4ef 426:02313bbfe900
43 tree->root = newNode; // this should done at stackClear 43 tree->root = newNode; // this should done at stackClear
44 tree->parent = NULL; 44 tree->parent = NULL;
45 if (root) { 45 if (root) {
46 tree->current = root; 46 tree->current = root;
47 tree->result = compare(tree->current, node); 47 tree->result = compare(tree->current, node);
48 goto replaceNode(); 48 goto findNode(tree);
49 } 49 }
50 goto insertNode(); 50 goto insertNode(tree, node);
51 } 51 }
52 52
53 __code replaceNode(struct RedBlackTree* tree) { 53 __code findNode(struct RedBlackTree* tree) {
54 struct Stack* nodeStack = tree->nodeStack; 54 struct Stack* nodeStack = tree->nodeStack;
55 struct Node* oldNode = tree->current; 55 struct Node* oldNode = tree->current;
56 struct Node* newNode = tree->newNode; 56 struct Node* newNode = tree->newNode;
57 tree->previous = newNode; 57 tree->previous = newNode;
58 *newNode = *oldNode; 58 *newNode = *oldNode;
59 goto nodeStack->push(newNode, replaceNode1); 59 goto nodeStack->push(newNode, replaceNode1);
60 } 60 }
61 61
62 __code replaceNode1(struct RedBlackTree* tree, struct Node* node, __code next(...)) { 62 __code findNode1(struct RedBlackTree* tree, struct Node* node, __code next(...)) {
63 struct Node* oldNode = tree->current; 63 struct Node* oldNode = tree->current;
64 struct Node* newNode = tree->previous; 64 struct Node* newNode = tree->previous;
65 struct Node* newnewNode = &ALLOCATE(context, Node)->Node; 65 struct Node* newnewNode = &ALLOCATE(context, Node)->Node;
66 int result = tree->result; 66 int result = tree->result;
67 if (result == EQ) { 67 if (result == EQ) {
76 newNode->left = newnewNode; 76 newNode->left = newnewNode;
77 } 77 }
78 tree->newNode = newnewNode; 78 tree->newNode = newnewNode;
79 if (tree->current) { 79 if (tree->current) {
80 tree->result = compare(tree->current, node); 80 tree->result = compare(tree->current, node);
81 goto replaceNode(); 81 goto findNode(tree);
82 } 82 }
83 goto insertNode(); 83 goto insertNode(tree, node);
84 84
85 } 85 }
86 86
87 __code insertNode(struct RedBlackTree* tree, struct Node* node) { 87 __code insertNode(struct RedBlackTree* tree, struct Node* node) {
88 struct Stack* nodeStack = tree->nodeStack; 88 struct Stack* nodeStack = tree->nodeStack;
95 95
96 __code insertCase1(struct RedBlackTree* tree, struct Node *parent, struct Node *grandparent) { 96 __code insertCase1(struct RedBlackTree* tree, struct Node *parent, struct Node *grandparent) {
97 if (parent != NULL) { 97 if (parent != NULL) {
98 tree->parent = parent; 98 tree->parent = parent;
99 tree->grandparent = grandparent; 99 tree->grandparent = grandparent;
100 goto insertCase2(); 100 goto insertCase2(tree);
101 } 101 }
102 tree->root->color = Black; 102 tree->root->color = Black;
103 goto stackClear(); 103 goto stackClear();
104 } 104 }
105 105
112 112
113 __code insertCase2(struct RedBlackTree* tree) { 113 __code insertCase2(struct RedBlackTree* tree) {
114 if (tree->parent->color == Black) { 114 if (tree->parent->color == Black) {
115 goto stackClear(); 115 goto stackClear();
116 } 116 }
117 goto insertCase3(); 117 goto insertCase3(tree);
118 } 118 }
119 119
120 __code insertCase3(struct RedBlackTree* tree, struct Stack* nodeStack) { 120 __code insertCase3(struct RedBlackTree* tree) {
121 struct Stack* nodeStack = tree->nodeStack; 121 struct Stack* nodeStack = tree->nodeStack;
122 struct Node* uncle; 122 struct Node* uncle;
123 123
124 if (tree->grandparent->left == tree->parent) 124 if (tree->grandparent->left == tree->parent)
125 uncle = tree->grandparent->right; 125 uncle = tree->grandparent->right;
193 Gearef(context, RotateTree), 193 Gearef(context, RotateTree),
194 parent, 194 parent,
195 grandparent); 195 grandparent);
196 } 196 }
197 197
198 __code rotateLeft(struct RedBlackTree* tree, struct Stack* nodeStack) { 198 __code rotateLeft(struct RedBlackTree* tree) {
199 nodeStack->stack = (union Data*)tree->nodeStack; 199 struct Stack* nodeStack = tree->nodeStack;
200 nodeStack->next = C_rotateLeft1; 200 goto nodeStack->get(rotateLeft1);
201 goto meta(context, tree->nodeStack->get);
202 } 201 }
203 202
204 __code rotateLeft_stub(struct Context* context) { 203 __code rotateLeft_stub(struct Context* context) {
205 struct RedBlackTree* traverse = context->data[D_RotateTree]->RotateTree.traverse; 204 struct RedBlackTree* traverse = context->data[D_RotateTree]->RotateTree.traverse;
206 goto rotateLeft(context, traverse, Gearef(context, Stack)); 205 goto rotateLeft(context, traverse);
207 } 206 }
208 207
209 __code rotateLeft1(struct Node* node, struct RedBlackTree* tree, struct Node* parent, struct RotateTree* rotateTree) { 208 __code rotateLeft1(struct Node* node, struct RedBlackTree* tree, struct Node* parent, struct RotateTree* rotateTree) {
210 struct Node* tmp = node->right; 209 struct Node* tmp = node->right;
211 210
233 traverse, 232 traverse,
234 parent, 233 parent,
235 Gearef(context, RotateTree)); 234 Gearef(context, RotateTree));
236 } 235 }
237 236
238 __code rotateRight(struct RedBlackTree* tree, struct Stack* nodeStack) { 237 __code rotateRight(struct RedBlackTree* tree) {
239 nodeStack->stack = (union Data*)tree->nodeStack; 238 struct Stack* nodeStack = tree->nodeStack;
240 nodeStack->next = C_rotateRight1; 239 goto nodeStack->get(rotateRight1);
241 goto meta(context, tree->nodeStack->get);
242 } 240 }
243 241
244 __code rotateRight_stub(struct Context* context) { 242 __code rotateRight_stub(struct Context* context) {
245 struct RedBlackTree* traverse = context->data[D_RotateTree]->RotateTree.traverse; 243 struct RedBlackTree* traverse = context->data[D_RotateTree]->RotateTree.traverse;
246 goto rotateLeft(context, traverse, Gearef(context, Stack)); 244 goto rotateLeft(context, traverse);
247 } 245 }
248 246
249 __code rotateRight1(struct Node* node, struct RedBlackTree* traverse,struct Node *parent,struct RotateTree *rotateTree) { 247 __code rotateRight1(struct Node* node, struct RedBlackTree* traverse,struct Node *parent,struct RotateTree *rotateTree) {
250 struct Node* tmp = node->left; 248 struct Node* tmp = node->left;
251 249