annotate src/parallel_execution/RedBlackTree.cbc @ 445:f02bd096af64

fix RedBlackTree.cbc Insertion
author ryokka
date Tue, 28 Nov 2017 22:15:23 +0900
parents 02313bbfe900
children 41a6f8482374
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
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
5 // extern enum Relational compare(struct Node* node1, struct Node* node2);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
6
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
7
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
8 Tree* createRedBlackTree(struct Context* context) {
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
9 struct Tree* tree = new Tree();
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
10 struct RedBlackTree* redBlackTree = new RedBlackTree();
418
a74bec89c198 generate main
mir3636
parents: 415
diff changeset
11 tree->tree = (union Data*)redBlackTree;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
12 redBlackTree->root = NULL;
415
eec6553a2aa6 fix redblacktree
mir3636
parents: 338
diff changeset
13 redBlackTree->nodeStack = (union Data*)createSingleLinkedStack(context);
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
14
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
15 // tree->put = C_putRedBlackTree;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
16 // tree->get = C_getRedBlackTree;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
17 // tree->remove = C_removeRedBlackTree;
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
18 // tree->clear = C_clearRedBlackTree;
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
19 return tree;
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
20 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
21
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
22 // void printTree(union Data* data) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
23 // printTree1(data);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
24 // printf("\n");
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
25 // }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
26 //
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
27 // void printTree1(union Data* data) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
28 // struct Node* node = &data->Node;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
29 // if (node == NULL) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
30 // printf("NULL");
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
31 // } else {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
32 // printf("key = %d (", node->key);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
33 // printTree1((union Data*)(node->right));
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
34 // printf("), (");
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
35 // printTree1((union Data*)(node->left));
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
36 // printf(")");
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
37 // }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
38 // }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
39 //
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
40 // __code putRedBlackTree(struct RedBlackTree* tree, struct Node* node) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
41 // struct Node* newNode = &ALLOCATE(context, Node)->Node;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
42 // struct Node* root = tree->root;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
43 // printTree(tree->root);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
44 // tree->newNode = newNode;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
45 // tree->root = newNode; // this should done at stackClear
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
46 // tree->parent = NULL;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
47 // if (root) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
48 // tree->current = root;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
49 // tree->result = compare(tree->current, node);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
50 // goto insertRBTree(tree);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
51 // }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
52 // goto insertRBTree(tree, node);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
53 // }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
54
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
55 __code stackClear(struct RedBlackTree* tree, struct Stack* nodeStack, __code next(...)) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
56 tree->current = 0;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
57 nodeStack->stack = (union Data*)tree->nodeStack;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
58 nodeStack->next = next;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
59 goto meta(context, tree->nodeStack->clear);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
60 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
61
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
62 // __code getRedBlackTree(struct RedBlackTree* tree, __code next(...)) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
63 // if (tree->root) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
64 // tree->current = tree->root;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
65 // goto insertRBTree();
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
66 // // goto deleteRBTree();
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
67 // }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
68 //
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
69 // goto next(...);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
70 // }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
71
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
72 __code insertRBTree(struct Node* newNode,struct Stack* nodeStack, struct RedBlackTree* rbtree) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
73 rbtree->current = rbtree->root;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
74 goto insertLocate(newNode, nodeStack, rbtree);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
75 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
76
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
77 __code insertLocate(struct Node* node, struct Stack* nodeStack, struct RedBlackTree* rbtree) {
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
78
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
79 struct Stack* nodeStack = tree->nodeStack;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
80 struct Node* trace = rbtree->current;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
81
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
82 // i think faster "compare rbtree->current, node" than "switch case EQ, LT, RT"
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
83 if (rbtree->current > node) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
84 goto nodestack->push(nodeStack,trace,insertLocate);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
85 } else if (rbtree->current < node) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
86 goto nodestack->push(nodeStack, trace, insertLocate);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
87 } else if (rbtree->current == node) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
88 printf("alady member this node(insertLocate)");
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
89 goto next(...);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
90 } else if (rbtree->current == null){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
91 rbtree->current = node;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
92 goto nodeStack->pop(nodeStack,insertBalance);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
93 }else{
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
94 rbtree->root = node;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
95 goto next(...);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
96 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
97 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
98
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
99 __code insertBalance(struct RedBlackTree* rbtree, struct Node* nodeStack, struct Node* node){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
100 rbtree->current = nodeStack->data;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
101 // insert case
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
102 if (current->left->left || current->left->right){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
103 goto insertBalanceLeft(rbtree,nodeStack);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
104 }else if (current->right->left || current->right->right){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
105 goto insertBalanceRight(rbtree,nodeStack);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
106 }else{
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
107 goto nodeStack->pop(nodeStack,insertBalance);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
108 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
109 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
110
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
111 __code insesrtBalanceLeft(struct RedBlackTree* rbtree, struct Node* nodeStack, struct Node* node){
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
112
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
113 if (current->color == Black && current->left->color == Red && current->left->left->color == Red){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
114 struct Node* tmp0 = rbtree->current;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
115 struct Node* tmp1 = rbtree->current->left;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
116 struct Node* tmp2 = rbtree->current->left->left;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
117
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
118 rbtree->current = tmp1;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
119 rbtree->current->right = tmp0;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
120 rbtree->current->left = tmp2;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
121 rbtree->current->right->right = tmp0->right;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
122 rbtree->current->right->left = tmp1->right;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
123 rbtree->current->color = Black;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
124 rbtree->current->left->color = Red;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
125 rbtree->current->right->color = Red;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
126 goto nodeStack->pop(nodeStack,insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
127
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
128 } else if(current->color == Black && current->left->color == Red && current->left->right->color == Red){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
129 struct Node* tmp0 = rbtree->current;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
130 struct Node* tmp1 = rbtree->current->left;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
131 struct Node* tmp2 = rbtree->current->left->right;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
132
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
133 rbtree->current = tmp1;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
134 rbtree->current->right = tmp0;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
135 rbtree->current->left = tmp2;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
136 rbtree->current->right->right = tmp0->right;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
137 rbtree->current->right->left = tmp1->right;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
138 rbtree->current->color = Black;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
139 rbtree->current->left->color = Red;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
140 rbtree->current->right->color = Red;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
141 goto nodeStack->pop(nodeStack,insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
142
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
143 }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
144 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
145
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
146 __code insertBalanceRight(struct RedBlackTree* rbtree, struct Node* nodeStack, struct Node* node){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
147 if (current->color == Black && current->right->color == Red && current->right->right->color == Red){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
148 struct Node* tmp0 = rbtree->current;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
149 struct Node* tmp1 = rbtree->current->left;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
150 struct Node* tmp2 = rbtree->current->left->right;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
151
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
152 rbtree->current = tmp1;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
153 rbtree->current->right = tmp0;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
154 rbtree->current->left = tmp2;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
155 rbtree->current->right->right = tmp0->right;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
156 rbtree->current->right->left = tmp1->right;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
157 rbtree->current->color = Black;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
158 rbtree->current->left->color = Red;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
159 rbtree->current->right->color = Red;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
160 goto nodeStack->pop(nodeStack,insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
161
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
162 } else if (current->color == Black && current->right->color == Red && current->right->left->color == Red){
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
163
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
164 struct Node* tmp0 = rbtree->current;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
165 struct Node* tmp1 = rbtree->current->right;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
166 struct Node* tmp2 = rbtree->current->right->left;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
167
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
168 rbtree->current = tmp1;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
169 rbtree->current->right = tmp0;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
170 rbtree->current->left = tmp2;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
171 rbtree->current->right->right = tmp0->right;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
172 rbtree->current->right->left = tmp1->right;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
173 rbtree->current->color = Black;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
174 rbtree->current->left->color = Red;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
175 rbtree->current->right->color = Red;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
176 goto nodeStack->pop(nodeStack,insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
177
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
178 } else {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
179 printf("error insertBalanceRight");
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
180 goto next(...);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
181 }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
182 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
183
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
184 // insertion code end
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
185
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
186
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
187
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
188
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
189 // __code deleteRBTree(struct RedBlackTree newNode, struct RedBlackTree* rbtree) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
190 // rbtree->current = rbtree->root;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
191 // goto deleteLocate;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
192 // }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
193
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
194 // __code deleteLocate(struct Node* node, struct Stack* nodeStack, struct RedBlackTree* rbtree) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
195 // /\* check delete node locate and push route node *\/
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
196 // struct Stack* nodeStack = tree->nodeStack;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
197 // struct Node* trace = rbtree->current;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
198
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
199 // if (rbtree->current > node) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
200 // goto nodeStack->push(nodeStack,trace,deleteLocate);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
201 // } else if (rbtree->current < node) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
202 // goto nodeStack->push(trace,deleteLocate);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
203 // } else if (rbtree->current == node) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
204 // // trace = rbtree->current;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
205 // goto deleteNode(struct Stack* nodeStack, struct RedBlackTree* rbtree,struct Node* trace);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
206 // // goto nodeStack->push(trace,deleteNode);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
207 // } else if (rbtree->current == null){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
208 // printf("No member Delete node (__code deleteLocate)");
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
209 // goto next(...);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
210 // } else {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
211 // printf("Error,__code deleteLocate");
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
212 // goto next(...);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
213 // }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
214 // }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
215
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
216 // __code deleteNode(struct Node* node, struct Stack* nodeStack, struct RedBlackTree* rbtree) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
217 // struct Stack* nodeStack = tree->nodeStack;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
218 // struct Node* replaceNode = nodeStack->data;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
219
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
220 // if(replaceNode->right == null){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
221 // rbtree->current = replaceNode;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
222 // rbtree->current = rbtree->current->left;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
223 // goto deleteUnbalance(nodeStack,replaceNode);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
224 // }else if(replaceNode->left == null){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
225 // rbtree->current = replaceNode;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
226 // rbtree->current = rbtree->current->right;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
227 // goto deleteUnbalance(nodeStack,replaceNode);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
228 // //goto deleteNodeReplaceNull();
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
229 // }else{
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
230 // // goto nodeStack->push(nodeStack,replaceNode,deleteNodeReplace);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
231 // goto deleteNodeReplace(nodeStack,replaceNode);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
232 // }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
233 // }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
234
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
235
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
236 // __code deleteNodeReplace(){
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
237
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
238 // if (replaceNode->left != null){
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
239 // replaceNode = replaceNode->left;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
240 // goto deleteNodeReplace();
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
241 // }else if(){
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
242
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
243
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
244 // }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
245
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
246 // }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
247
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
248
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
249 // __code deleteUnbalance() {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
250 // if () {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
251 // }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
252
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
253 // }