57 struct no_left_node : std::logic_error {
no_left_node() : std::logic_error(
"neolib::index_array_tree::node::no_left_node") {} };
70 iColor{ aColor }, iParent{ aColor !=
NIL ? nullptr : this }, iLeft{ aColor !=
NIL ? nullptr : this }, iRight{ aColor !=
NIL ? nullptr : this }, iPrevious{ nullptr }, iNext{ nullptr }, iSize{ 0 }, iForeignIndex{}
74 iColor{ aOther.iColor }, iParent{ aOther.iColor !=
NIL ? nullptr : this }, iLeft{ aOther.iColor !=
NIL ? nullptr : this }, iRight{ aOther.iColor !=
NIL ? nullptr : this }, iPrevious{ nullptr }, iNext{ nullptr }, iSize{ 0 }, iForeignIndex{}
88 return iColor !=
NIL ? iColor :
BLACK;
105 if (iLeft !=
nullptr)
115 if (iRight !=
nullptr)
129 iPrevious = aPrevoius;
141 return iColor !=
NIL ? iSize : 0;
191 iForeignIndex += difference;
214 if (aNil->
parent() == aGarbage)
216 if (aNil->
left() == aGarbage)
218 if (aNil->
right() == aGarbage)
233 typedef typename std::allocator_traits<allocator_type>:: template rebind_alloc<node> node_allocator_type;
237 iAllocator(aAllocator),
243 iNil = std::allocator_traits<node_allocator_type>::allocate(iAllocator, 1);
246 std::allocator_traits<node_allocator_type>::construct(iAllocator, iNil,
node(
node::NIL));
250 std::allocator_traits<node_allocator_type>::deallocate(iAllocator, iNil, 1);
257 std::allocator_traits<node_allocator_type>::destroy(iAllocator, iNil);
258 std::allocator_traits<node_allocator_type>::deallocate(iAllocator, iNil, 1);
292 return aNode ? aNode->
size() : 0;
300 return aNode && aNode->
left() ? aNode->
left()->
size() : 0;
328 if (aPosition < index)
341 template <
typename Pred = std::less<foreign_index_type>>
349 if (aPred(aForeignIndex, foreignIndex))
363 aNodeForeignIndex = foreignIndex;
375 previousIndex = index;
377 if (aPosition <= index)
393 if (aPosition <= previousIndex)
416 y = tree_successor(z);
458 if (performDeleteFixup)
463 std::swap(iAllocator, aOther.iAllocator);
471 void insert_fixup(node* aNode)
474 while (z->parent()->color() ==
node::RED)
476 if (z->parent() == z->parent()->parent()->left())
478 node* y = z->parent()->parent()->right();
483 z->parent()->parent()->set_color(
node::RED);
484 z = z->parent()->parent();
488 if (z == z->parent()->right())
494 z->parent()->parent()->set_color(
node::RED);
495 right_rotate(z->parent()->parent());
500 node* y = z->parent()->parent()->left();
505 z->parent()->parent()->set_color(
node::RED);
506 z = z->parent()->parent();
510 if (z == z->parent()->left())
516 z->parent()->parent()->set_color(
node::RED);
517 left_rotate(z->parent()->parent());
523 void left_rotate(node* aNode)
526 node* y = x->right();
527 x->set_right(y->left());
529 y->left()->set_parent(x);
530 y->set_parent(x->parent());
535 if (x == x->parent()->left())
536 x->parent()->set_left(y);
538 x->parent()->set_right(y);
544 y->iSize = x->size();
545 x->iSize -= previousSize;
546 x->iSize += x->right()->size();
549 y->iForeignIndex = x->foreign_index();
550 x->iForeignIndex -= previousForeignIndex;
551 x->iForeignIndex += x->right()->foreign_index();
553 void right_rotate(node* aNode)
557 y->set_left(x->right());
559 x->right()->set_parent(y);
560 x->set_parent(y->parent());
565 if (y == y->parent()->right())
566 y->parent()->set_right(x);
568 y->parent()->set_left(x);
574 x->iSize = y->size();
575 y->iSize -= previousSize;
576 y->iSize += y->left()->size();
579 x->iForeignIndex = y->foreign_index();
580 y->iForeignIndex -= previousForeignIndex;
581 y->iForeignIndex += y->left()->foreign_index();
583 node* tree_minimum(node* aNode)
590 node* tree_successor(node* aNode)
594 return tree_minimum(x->right());
595 node* y = x->parent();
603 void delete_fixup(node* aNode)
608 if (x == x->parent()->left())
610 node* w = x->parent()->right();
615 left_rotate(x->parent());
616 w = x->parent()->right();
630 w = x->parent()->right();
632 w->set_color(x->parent()->color());
635 left_rotate(x->parent());
641 node* w = x->parent()->left();
646 right_rotate(x->parent());
647 w = x->parent()->left();
661 w = x->parent()->left();
663 w->set_color(x->parent()->color());
666 right_rotate(x->parent());
675 node_allocator_type iAllocator;
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)