annotate src/parallel_execution/RedBlackTree.cbc @ 458:3025d00eb87d

Merge
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Thu, 14 Dec 2017 07:44:58 +0900
parents a44dbeb08895
children 5fd0502a6c35 8d7e5d48cad3
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"
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
4 #include "../compare.c"
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
5
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
6 extern enum Relational compare(struct Node* node1, struct Node* node2);
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
7
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
8
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
9 Tree* createRedBlackTree(struct Context* context) {
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
10 struct Tree* tree = new Tree();
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
11 struct RedBlackTree* rbtree = new RedBlackTree();
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
12
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
13 tree->tree = (union Data*)rbtree;
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
14 rbtree->root = NULL;
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
15 rbtree->nodeStack = (union Data*)createSingleLinkedStack(context);
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
16 tree->put = C_putRedBlackTree;
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
17 // tree->get = C_getRedBlackTree;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
18 // tree->remove = C_removeRedBlackTree;
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
19 // tree->clear = C_clearRedBlackTree;
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
20 return tree;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
21 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
22
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
23 void printNode(struct Node* node) {
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
24 if (node == NULL) {
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
25 printf("leaf");
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
26 } else {
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
27 printf("((%d,%d (",node->color, node->key);
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
28 printNode(node->right);
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
29 printf(") (");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
30 printNode(node->left);
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
31 printf(")");
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
32 }
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
33 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
34
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
35 void printTree(struct RedBlackTree* tree) {
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
36 printf("\n");
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
37 tree->current = tree->root;
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
38 printNode(tree->current);
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
39 printf(")\n");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
40 }
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
41
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
42 __code putRedBlackTree(struct RedBlackTree* tree, struct Node* node, __code next(...)) {
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
43 printf("C_putRedBlackTree\n");
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
44 //struct Node* newNode = &ALLOCATE(context, Node)->Node;
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
45 printf("value->%d,key->%d \n",node->value,node->key);
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
46 tree->previous = tree->newNode;
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
47 tree->newNode = node;
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
48 tree->newNode->color = Red;
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
49 // tree->root = newNode; // this should done at stackClear
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
50 // tree->parent = NULL;
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
51 // if (root) {
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
52 tree->current = tree->root;
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
53 // tree->result = compare(tree->current, node);
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
54 goto insertRBTree(node, tree);
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
55 // }
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
56 // printf("error : __code putRedBlackTree \n");
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
57 // goto meta(context, C_exit_code);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
58 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
59
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
60 //__code stackClear(struct RedBlackTree* tree, struct Stack* nodeStack, __code next(...)) {
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
61 // tree->current = 0;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
62 // nodeStack->stack = tree->nodeStack;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
63 // nodeStack->next = next;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
64 // goto meta(context, tree->nodeStack->clear);
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
65 //}
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
66
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
67 // __code getRedBlackTree(struct RedBlackTree* tree, __code next(...)) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
68 // if (tree->root) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
69 // tree->current = tree->root;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
70 // goto insertRBTree();
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
71 // // goto deleteRBTree();
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
72 // }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
73 //
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
74 // goto next(...);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
75 // }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
76
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
77 __code insertRBTree(struct Node* node, struct RedBlackTree* tree, struct Stack* stack, __code next(...)) {
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
78 // first case tree->current = root;
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
79 printf("C_insertRBTree\n");
455
a44dbeb08895 Fix nodeStack
innparusu
parents: 454
diff changeset
80 //stack = tree->nodeStack;
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
81 printf("value->%d,key->%d\n",node->value,node->key);
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
82 printf("newNode value->%d,newNode key->%d\n",tree->newNode->value,tree->newNode->key);
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
83
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
84 if (tree->root == NULL) {
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
85 printf("insertRBTree_root eq NULL\n");
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
86 tree->root = tree->newNode;
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
87 tree->root->color = Black;
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
88 printf("tree->root->key = %d, tree->root->color = %d \n",tree->root->key,tree->root->color);
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
89 printTree(tree);
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
90 goto next(tree,...);
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
91 } else {
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
92 goto searchInsertLocation(node, tree, stack);
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
93 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
94 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
95
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
96
455
a44dbeb08895 Fix nodeStack
innparusu
parents: 454
diff changeset
97 __code searchInsertLocation(struct Node* node, struct RedBlackTree* tree) {
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
98 // first case tree->current = root; PreCase remove root=NULL case.don't exist firstCase tree->current=NULL
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
99 printf("C_searchInsertLocation\n");
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
100 printf("nownode->key %d , previous->key %d \n",tree->newNode->key,tree->previous->key);
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
101
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
102 tree->result = compare(tree->current, node);
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
103 printf("tree->current->key = %d, node->key %d\n",tree->current->key,node->key);
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
104 printf("compare (%d,%d)\n",tree->current,node);
455
a44dbeb08895 Fix nodeStack
innparusu
parents: 454
diff changeset
105 struct Stack* stack = tree->nodeStack;
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
106 if (tree->current == NULL) {
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
107 printf("goto insertLocationBackInsert stack->pop");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
108 goto stack->pop(insertLocationBackInsert);
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
109 }
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
110 if (tree->result == GT) {
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
111 printf("GT searchInsertLocation");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
112 tree->current = tree->current->right;
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
113 goto stack->push(tree->newNode,insertLocationBackInsert);
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
114 } else if (tree->result == LT) {
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
115 printf("LT searchInsertLocation");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
116 tree->current = tree->current->left;
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
117 goto stack->push(tree->newNode, searchInsertLocation);
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
118 } else if (tree->result == EQ) {
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
119 printf("already member this node : __code searchInsertLocation()\n");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
120 goto meta(context, C_exit_code);
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
121 } else {
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
122 printf("$insert value tree : __code searchInsertLocation() \n");
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
123 goto meta(context, C_exit_code);
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
124 }
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
125 }
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
126
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
127 __code insertLocationBackInsert(struct RedBlackTree* tree, struct Node* node, struct Stack* stack) {
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
128 printf("C_insertLocationBackInsert\n");
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
129 struct Node* hoge = stack->data;
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
130 printf("stackpopdata%d\n",stack->data);
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
131 tree->current = tree->previous;
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
132 // tree->current = nodeStack->data;
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
133 // this CS is ones only backTrace, and insert node
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
134 tree->result = compare(tree->previous,tree->newNode);
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
135 printf("back,compare\n");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
136 if (tree->result == GT) {
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
137 printf("ok\n");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
138 tree->current->right = tree->newNode;
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
139 printTree(tree);
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
140 goto insertBalance();
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
141 } else if (tree->result == LT) {
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
142 printf("LT\n");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
143 tree->current->left = tree->newNode;
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
144 goto insertBalance();
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
145 } else {
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
146 printf("error : __code insertLocationBackTrace() \n");
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
147 goto meta(context, C_exit_code);
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
148 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
149 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
150
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
151 __code insertBalance(struct RedBlackTree* tree, struct Node* nodeStack, struct Node* node, __code next(...)) {
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
152 printf("C_insertBalance\n");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
153 struct Node* traceNode = tree->nodeStack->data;
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
154 tree->current = traceNode;
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
155 struct Stack* stack = tree->nodeStack;
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
156
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
157 // exit insertion code
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
158 if (tree->current == tree->root) {
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
159 tree->current->color = Black;
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
160 printTree(tree);
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
161 //printTree
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
162 goto next(tree,...);
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
163 }
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
164
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
165
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
166 //current color eq Red
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
167 if (tree->current->color == Red)
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
168 goto stack->pop(insertBalance);
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
169
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
170 // current color eq Black
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
171 if (tree->current->left->left || tree->current->left->right) {
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
172 goto insertBalanceLeft(tree,nodeStack);
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
173 } else if (tree->current->right->left || tree->current->right->right) {
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
174 goto insertBalanceRight(tree,nodeStack);
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
175 } else {
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
176 goto stack->pop(insertBalance);
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
177 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
178 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
179
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
180 __code insertBalanceLeft(struct RedBlackTree* tree, struct Node* nodeStack, struct Node* node) {
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
181 printf("C_insertBalanceLeft\n");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
182 struct Stack* stack = tree->nodeStack;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
183
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
184 if (tree->current->color == Black && tree->current->left->color == Red && tree->current->left->left->color == Red) {
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
185 struct Node* tmpCurrent = tree->current;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
186 struct Node* tmpLeft = tree->current->left;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
187 struct Node* tmpLeftLeft = tree->current->left->left;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
188
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
189 tree->current = tmpLeft;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
190 tree->current->right = tmpCurrent;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
191 tree->current->left = tmpLeftLeft;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
192 tree->current->right->left = tmpLeft->right;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
193 tree->current->color = Red;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
194 tree->current->left->color = Black;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
195 tree->current->right->color = Black;
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
196 goto stack->pop(insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
197
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
198 } else if(tree->current->color == Black && tree->current->left->color == Red && tree->current->left->right->color == Red) {
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
199 struct Node* tmpCurrent = tree->current;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
200 struct Node* tmpLeft = tree->current->left;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
201 struct Node* tmpLeftRight = tree->current->left->right;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
202
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
203 tree->current = tmpLeft;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
204 tree->current->right = tmpCurrent;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
205 tree->current->left = tmpLeftRight;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
206 tree->current->right->left = tmpLeft->left;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
207 tree->current->color = Red;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
208 tree->current->left->color = Black;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
209 tree->current->right->color = Black;
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
210 goto stack->pop(insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
211
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
212 }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
213 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
214
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
215 __code insertBalanceRight(struct RedBlackTree* tree, struct Node* nodeStack, struct Node* node) {
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
216 printf("C_insertBalanceLeft\n");
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
217 struct Stack* stack = tree->nodeStack;
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
218
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
219 if (tree->current->color == Black && tree->current->right->color == Red && tree->current->right->right->color == Red) {
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
220 struct Node* tmpCurrent = tree->current;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
221 struct Node* tmpRight = tree->current->right;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
222 struct Node* tmpRightRight = tree->current->right->right;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
223
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
224 tree->current = tmpRight;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
225 tree->current->left = tmpCurrent;
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
226 tree->current->right = tmpRightRight;
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
227 tree->current->left->right = tmpRight->left;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
228 tree->current->color = Red;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
229 tree->current->left->color = Black;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
230 tree->current->right->color = Black;
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
231 goto stack->pop(insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
232
454
77de0283ac92 Debug RedBlackTree.cbc.
ryokka
parents: 452
diff changeset
233 } else if (tree->current->color == Black && tree->current->right->color == Red && tree->current->right->left->color == Red) {
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
234
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
235 struct Node* tmpCurrent = tree->current;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
236 struct Node* tmpRight = tree->current->right;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
237 struct Node* tmpRightLeft = tree->current->right->left;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
238
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
239 tree->current = tmpRight;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
240 tree->current->right = tmpCurrent;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
241 tree->current->left = tmpRightLeft;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
242 tree->current->left->right = tmpRight->right;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
243 tree->current->color = Red;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
244 tree->current->left->color = Black;
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
245 tree->current->right->color = Black;
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
246 goto stack->pop(insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
247
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
248 } else {
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
249 printf("unkwon error : __code insertBalanceRight() \n");
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
250 goto meta(context, C_exit_code);
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
251 }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
252 }
452
1432d924c472 fix RedBlackTree.cbc Insert, debug now
ryokka
parents: 446
diff changeset
253 // insertCode end