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