-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraft.cpp
More file actions
206 lines (167 loc) · 8.51 KB
/
Copy pathdraft.cpp
File metadata and controls
206 lines (167 loc) · 8.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// //Redistribute Left
// void RedistributeLeft(shared_ptr& curr){
// // if it friend is threenode (A B): only refactoring the small part
// // if leaf
// if(Ifleaf(curr)){
// //if the midleft is threenode
// if(IfThreeNode(curr->getParent()->getMiddleLeft())){
// curr->setSmallKey(curr->getParent()->getSmallKey());
// curr->getParent()->setSmallKey(curr->getParent()->getMiddleLeft()->getSmallKey());
// curr->getParent()->getMiddleLeft()->setSmallKey(curr->getParent()->getMiddleLeft()->getMiddleKey());
// curr->getParent()->getMiddleLeft()->setMiddleKey(nullptr);
// }
// // if not: look for parent parent help
// // join the bottom node with parent node
// // then delete parent node for internal node
// else{
// //join the left node
// Merge(curr);
// }
// }
// //not leaf but internal node
// //not matter parent is two or threenode, just redistribute the small key
// else if(curr->getSmallKey() == nullptr && curr->getLeft() != nullptr){
// //if right is threenode
// // and if parent is twonode only
// if(IfTwoNode(curr->getParent())){
// if(IfThreeNode(curr->getParent()->getMiddleLeft())){
// curr->setSmallKey(curr->getParent()->getSmallKey());
// curr->getParent()->setSmallKey(curr->getParent()->getMiddleLeft()->getSmallKey());
// curr->getParent()->getMiddleLeft()->setSmallKey(curr->getParent()->getMiddleLeft()->getMiddleKey());
// curr->getParent()->getMiddleLeft()->setMiddleKey(nullptr);
// //curr->setLeft(curr->getLeft());
// curr->setMiddleLeft(curr->getParent()->getMiddleLeft()->getLeft());
// curr->getParent()->getMiddleLeft()->setLeft(curr->getParent()->getMiddleLeft()->getMiddleLeft());
// curr->getParent()->getMiddleLeft()->setMiddleLeft(curr->getParent()->getMiddleLeft()->getRight());
// curr->getParent()->getMiddleLeft()->setRight(nullptr);
// }
// else{
// Merge(curr);
// }
// }
// }
// }
// //Redistribute Right
// void RedistributeRight(shared_ptr<Node>& curr){
// // if it friend is threenode (A B): only refactoring the small part
// // if leaf
// if(Ifleaf(curr)){
// //if left is threenode
// if(IfThreeNode(curr->getParent()->getLeft())){
// curr->setSmallKey(curr->getParent()->getSmallKey());
// curr->getParent()->setSmallKey(curr->getParent()->getLeft()->getMiddleKey());
// curr->getParent()->getLeft()->setMiddleKey(nullptr);
// }
// // if not: look for parent parent help
// // join the bottom node with parent node
// // then delete parent node for internal node
// else{
// //join the left node
// Merge(curr);
// }
// }
// //not leaf but internal node
// //not matter parent is two or threenode, just redistribute the small key
// else if(curr->getSmallKey() == nullptr && curr->getLeft() != nullptr){
// //parent is two node only
// //if left is threenode
// if(IfThreeNode(curr->getParent()->getLeft()) && IfTwoNode(curr->getParent())){
// curr->setSmallKey(curr->getParent()->getSmallKey());
// curr->getParent()->setSmallKey(curr->getParent()->getLeft()->getMiddleKey());
// curr->getParent()->getLeft()->setMiddleKey(nullptr);
// curr->setMiddleLeft(curr->getLeft());
// curr->setLeft(curr->getParent()->getLeft()->getRight());
// }
// else{
// Merge(curr);
// }
// }
// }
// // Merge to Left node
// void Merge(shared_ptr<Node>& curr){
// if(curr->getParent()->getMiddleLeft() == curr){
// curr->getParent()->getLeft()->setMiddleKey(curr->getParent()->getSmallKey());
// curr->getParent()->setSmallKey(nullptr);
// }
// else if(curr->getParent()->getLeft() == curr){
// curr->setSmallKey(curr->getParent()->getSmallKey());
// curr->setMiddleKey(curr->getParent()->getMiddleLeft()->getSmallKey());
// }
// curr = curr->getParent();
// curr->setMiddleLeft(nullptr);
// //time to separate the direction:
// //if parent is two node
// if(IfTwoNode(curr->getParent())){
// //if curr is stored on right
// if(curr->getParent()->getMiddleLeft() == curr){
// RedistributeRight(curr);
// }
// //if curr is stored on left
// else if(curr->getParent()->getLeft() == curr){
// RedistributeLeft(curr);
// }
// }
// //if parent is three node
// else if(IfThreeNode(curr->getParent())){
// //go ahead and use Restructure
// Restructure(curr);
// //done
// }
// //If parent is nullptr, which means reaching the root aleady
// //Base case
// else if(curr->getParent() == nullptr && curr->getSmallKey() == nullptr && curr->getLeft() != nullptr){
// curr = curr->getLeft();
// curr->setParent(nullptr);
// root = curr;
// }
// // else if(curr->getLeft() != nullptr){
// // //two situation:
// // //parent twonode
// // if(IfTwoNode(curr->getParent())){
// // curr->getParent()->getLeft()->setMiddleKey(curr->getParent()->getSmallKey());
// // curr->getParent()->getLeft()->setRight(curr->getLeft());
// // curr = curr->getParent();
// // curr->setMiddleLeft(nullptr);
// // curr->setSmallKey(nullptr);
// // RedistributeRight(curr);
// // }
// // //parent threenode
// // else if(IfThreeNode(curr->getParent())){
// // //two situation:
// // //node is middle left
// // if(curr->getParent()->getMiddleLeft() == curr){
// // curr->getParent()->getLeft()->setMiddleKey(curr->getParent()->getSmallKey());
// // curr->getParent()->getLeft()->setRight(curr->getLeft());
// // curr = curr->getParent();
// // curr->setSmallKey(curr->getMiddleKey());
// // curr->setMiddleKey(nullptr);
// // }
// // //node is right
// // else if(curr->getParent()->getRight() == curr){
// // }
// // }
// // }
// }
// //Merge to Right node
// // void MergetoRight(shared_ptr<Node>& curr){
// // if(curr->getMiddleLeft() == nullptr){
// // curr->getParent()->getMiddleLeft()->setMiddleKey(curr->getParent()->getMiddleLeft()->getSmallKey());
// // curr->getParent()->getMiddleLeft()->setSmallKey(curr->getParent()->getSmallKey());
// // curr->getParent()->setSmallKey(nullptr);
// // curr = curr->getParent();
// // curr->setLeft(nullptr);
// // RedistributeLeft(curr);
// // }
// // else if(curr->getMiddleLeft() != nullptr){
// // curr->getParent()->getMiddleLeft()->setMiddleKey(curr->getParent()->getMiddleLeft()->getSmallKey());
// // curr->getParent()->getMiddleLeft()->setSmallKey(curr->getParent()->getSmallKey());
// // curr->getParent()->getMiddleLeft()->setRight(curr->getParent()->getMiddleLeft()->getMiddleLeft());
// // curr->getParent()->getMiddleLeft()->setMiddleLeft(curr->getParent()->getMiddleLeft()->getLeft());
// // curr->getParent()->getMiddleLeft()->setLeft(curr->getMiddleLeft());
// // curr = curr->getParent();
// // curr->setLeft(nullptr);
// // curr->setSmallKey(nullptr);
// // RedistributeLeft(curr);
// // //curr->getParent()->setMiddleLeft(nullptr);
// // }
// // }