54 struct no_sibling : std::logic_error {
no_sibling() : std::logic_error(
"neolib::red_black_tree::node::no_sibling") {} };
65 iColor{ aColor }, iParent{ aColor !=
NIL ? nullptr : this }, iLeft{ aColor !=
NIL ? nullptr : this }, iRight{ aColor !=
NIL ? nullptr : this }
69 iColor{ aOther.iColor }, iParent{ aOther.iColor !=
NIL ? nullptr : this }, iLeft{ aOther.iColor !=
NIL ? nullptr : this }, iRight{ aOther.iColor !=
NIL ? nullptr : this }
83 return iColor !=
NIL ? iColor :
BLACK;
92 return iParent !=
nullptr && !iParent->
is_nil();
104 return iLeft !=
nullptr && !iLeft->
is_nil();
108 if (iLeft !=
nullptr)
118 return iRight !=
nullptr && !iRight->
is_nil();
122 if (iRight !=
nullptr)
157 if (aNil->
parent() == aGarbage)
159 if (aNil->
left() == aGarbage)
161 if (aNil->
right() == aGarbage)
174 iRoot{ nullptr }, iNil{
node::NIL }
200 template <
typename Predicate>
209 if (aPredicate(z, x))
219 if (aPredicate(z, y))
235 y = tree_successor(z);
258 if (performDeleteFixup)
268 void insert_fixup(node* aNode)
271 while (z->parent()->color() ==
node::RED)
273 if (z->parent() == z->parent()->parent()->left())
275 node* y = z->parent()->parent()->right();
280 z->parent()->parent()->set_color(
node::RED);
281 z = z->parent()->parent();
285 if (z == z->parent()->right())
291 z->parent()->parent()->set_color(
node::RED);
292 right_rotate(z->parent()->parent());
297 node* y = z->parent()->parent()->left();
302 z->parent()->parent()->set_color(
node::RED);
303 z = z->parent()->parent();
307 if (z == z->parent()->left())
313 z->parent()->parent()->set_color(
node::RED);
314 left_rotate(z->parent()->parent());
320 void left_rotate(node* aNode)
323 node* y = x->right();
324 x->set_right(y->left());
326 y->left()->set_parent(x);
327 y->set_parent(x->parent());
332 if (x == x->parent()->left())
333 x->parent()->set_left(y);
335 x->parent()->set_right(y);
340 void right_rotate(node* aNode)
344 y->set_left(x->right());
346 x->right()->set_parent(y);
347 x->set_parent(y->parent());
352 if (y == y->parent()->right())
353 y->parent()->set_right(x);
355 y->parent()->set_left(x);
360 node* tree_minimum(node* aNode)
367 node* tree_successor(node* aNode)
371 return tree_minimum(x->right());
372 node* y = x->parent();
380 void delete_fixup(node* aNode)
385 if (x == x->parent()->left())
387 node* w = x->parent()->right();
392 left_rotate(x->parent());
393 w = x->parent()->right();
407 w = x->parent()->right();
409 w->set_color(x->parent()->color());
412 left_rotate(x->parent());
418 node* w = x->parent()->left();
423 right_rotate(x->parent());
424 w = x->parent()->left();
438 w = x->parent()->left();
440 w->set_color(x->parent()->color());
443 right_rotate(x->parent());
void swap(plf::hive< element_type, allocator_type > &a, plf::hive< element_type, allocator_type > &b) noexcept(std::allocator_traits< allocator_type >::propagate_on_container_swap::value||std::allocator_traits< allocator_type >::is_always_equal::value)