FastLED 3.9.15
Loading...
Searching...
No Matches

◆ deleteFixup()

template<typename T, typename Compare = less<T>, typename Allocator = allocator_slab<char>>
void fl::RedBlackTree< T, Compare, Allocator >::deleteFixup ( RBNode * x,
RBNode * xParent )
inlineprivate

Definition at line 170 of file rbtree.h.

170 {
171 while ((x != mRoot) && (x == nullptr || x->color == Color::kBlack)) {
172 if (x == (xParent ? xParent->left : nullptr)) {
173 RBNode* w = xParent ? xParent->right : nullptr;
174 if (w && w->color == Color::kRed) {
175 w->color = Color::kBlack;
176 if (xParent) { xParent->color = Color::kRed; rotateLeft(xParent); }
177 w = xParent ? xParent->right : nullptr;
178 }
179 bool wLeftBlack = (!w || !w->left || w->left->color == Color::kBlack);
180 bool wRightBlack = (!w || !w->right || w->right->color == Color::kBlack);
181 if (wLeftBlack && wRightBlack) {
182 if (w) w->color = Color::kRed;
183 x = xParent;
184 xParent = xParent ? xParent->parent : nullptr;
185 } else {
186 if (!w || (w->right == nullptr || w->right->color == Color::kBlack)) {
187 if (w && w->left) w->left->color = Color::kBlack;
188 if (w) { w->color = Color::kRed; rotateRight(w); }
189 w = xParent ? xParent->right : nullptr;
190 }
191 if (w) w->color = xParent ? xParent->color : Color::kBlack;
192 if (xParent) xParent->color = Color::kBlack;
193 if (w && w->right) w->right->color = Color::kBlack;
195 x = mRoot;
196 }
197 } else {
198 RBNode* w = xParent ? xParent->left : nullptr;
199 if (w && w->color == Color::kRed) {
200 w->color = Color::kBlack;
201 if (xParent) { xParent->color = Color::kRed; rotateRight(xParent); }
202 w = xParent ? xParent->left : nullptr;
203 }
204 bool wRightBlack = (!w || !w->right || w->right->color == Color::kBlack);
205 bool wLeftBlack = (!w || !w->left || w->left->color == Color::kBlack);
206 if (wRightBlack && wLeftBlack) {
207 if (w) w->color = Color::kRed;
208 x = xParent;
209 xParent = xParent ? xParent->parent : nullptr;
210 } else {
211 if (!w || (w->left == nullptr || w->left->color == Color::kBlack)) {
212 if (w && w->right) w->right->color = Color::kBlack;
213 if (w) { w->color = Color::kRed; rotateLeft(w); }
214 w = xParent ? xParent->left : nullptr;
215 }
216 if (w) w->color = xParent ? xParent->color : Color::kBlack;
217 if (xParent) xParent->color = Color::kBlack;
218 if (w && w->left) w->left->color = Color::kBlack;
220 x = mRoot;
221 }
222 }
223 }
224 if (x) x->color = Color::kBlack;
225 }
void rotateRight(RBNode *x)
Definition rbtree.h:85
void rotateLeft(RBNode *x)
Definition rbtree.h:67
RBNode * mRoot
Definition rbtree.h:61

Referenced by fl::RedBlackTree< value_type, PairCompare, Allocator >::erase().

+ Here is the caller graph for this function: