#include <rb_tree.hpp>
template<class TTreeTraits, class TAllocator = std::allocator>
class std::rb_tree_base< TTreeTraits, TAllocator >
◆ allocator_type
template<class TTreeTraits, class TAllocator = std::allocator>
◆ key_type
template<class TTreeTraits, class TAllocator = std::allocator>
◆ size_type
◆ TravFunc
template<class TTreeTraits, class TAllocator = std::allocator>
◆ value_type
template<class TTreeTraits, class TAllocator = std::allocator>
◆ color_e
Aufzählungswerte |
---|
red | |
black | |
Definition: rb_tree.hpp:48
Definition: rb_tree.hpp:47
◆ rb_tree_base()
template<class TTreeTraits, class TAllocator = std::allocator>
91 : m_size(0), m_allocator(allocator)
94 ms_sentinel.
left = &ms_sentinel;
95 ms_sentinel.
right = &ms_sentinel;
96 ms_sentinel.
parent = &ms_sentinel;
97 m_root = &ms_sentinel;
Definition: rb_tree.hpp:48
color_e color
Definition: rb_tree.hpp:87
node * parent
Definition: rb_tree.hpp:84
node * left
Definition: rb_tree.hpp:83
node * right
Definition: rb_tree.hpp:85
◆ ~rb_tree_base()
template<class TTreeTraits, class TAllocator = std::allocator>
void clear()
Definition: rb_tree.hpp:211
◆ alloc_node()
template<class TTreeTraits, class TAllocator = std::allocator>
517 node* mem = (node*)m_allocator.allocate(
sizeof(node));
518 return new (mem) node();
◆ clear()
template<class TTreeTraits, class TAllocator = std::allocator>
216 m_root = &ms_sentinel;
bool empty() const
Definition: rb_tree.hpp:232
void free_node(node *n, bool recursive)
Definition: rb_tree.hpp:520
◆ empty()
template<class TTreeTraits, class TAllocator = std::allocator>
◆ erase() [1/2]
template<class TTreeTraits, class TAllocator = std::allocator>
int size_type
Definition: rb_tree.hpp:44
size_type erase(const key_type &key)
Definition: rb_tree.hpp:159
node * find_node(const key_type &key)
Definition: rb_tree.hpp:143
◆ erase() [2/2]
template<class TTreeTraits, class TAllocator = std::allocator>
175 if (n->left == &ms_sentinel || n->right == &ms_sentinel)
182 while (toErase->left != &ms_sentinel)
183 toErase = toErase->left;
186 node* eraseChild = (toErase->left != &ms_sentinel ? toErase->
left : toErase->
right);
187 eraseChild->parent = toErase->parent;
188 if (toErase->parent != &ms_sentinel)
190 if (toErase == toErase->parent->left)
191 toErase->parent->left = eraseChild;
193 toErase->parent->right = eraseChild;
200 n->
value = toErase->value;
202 if (toErase->color ==
black)
void rebalance_after_erase(node *n)
Definition: rb_tree.hpp:375
Definition: rb_tree.hpp:48
value_type value
Definition: rb_tree.hpp:86
void validate() const
Definition: rb_tree.hpp:446
void free_node(node *n, bool recursive)
Definition: rb_tree.hpp:520
node * left
Definition: rb_tree.hpp:83
node * right
Definition: rb_tree.hpp:85
◆ find_next_node()
template<class TTreeTraits, class TAllocator = std::allocator>
280 if (n->right != &ms_sentinel)
283 while (next->left != &ms_sentinel)
286 else if (n->parent != &ms_sentinel)
288 if (n == n->parent->left)
293 while (next->parent != &ms_sentinel)
295 if (next == next->parent->right)
◆ find_node()
template<class TTreeTraits, class TAllocator = std::allocator>
146 while (iter != &ms_sentinel)
148 const key_type& iter_key = iter->value.get_key();
151 else if (key < iter_key)
typename TTreeTraits::key_type key_type
Definition: rb_tree.hpp:69
◆ free_node()
template<class TTreeTraits, class TAllocator = std::allocator>
524 if (n->left != &ms_sentinel)
526 if (n->right != &ms_sentinel)
529 if (n != &ms_sentinel)
532 m_allocator.deallocate(n,
sizeof(node));
void free_node(node *n, bool recursive)
Definition: rb_tree.hpp:520
◆ get_begin_node()
template<class TTreeTraits, class TAllocator = std::allocator>
266 if (m_root != &ms_sentinel)
269 while (iter->left != &ms_sentinel)
node * left
Definition: rb_tree.hpp:83
◆ insert()
template<class TTreeTraits, class TAllocator = std::allocator>
107 node* parent(&ms_sentinel);
108 while (iter != &ms_sentinel)
111 if (iter->value.get_key() < v.get_key())
113 else if (v.get_key() < iter->value.get_key())
120 new_node->color =
red;
122 new_node->left = &ms_sentinel;
123 new_node->
right = &ms_sentinel;
124 new_node->
parent = parent;
125 if (parent != &ms_sentinel)
127 if (v.get_key() < parent->value.get_key())
128 parent->
left = new_node;
130 parent->
right = new_node;
Definition: rb_tree.hpp:47
void validate() const
Definition: rb_tree.hpp:446
void rebalance(node *new_node)
Definition: rb_tree.hpp:317
node * parent
Definition: rb_tree.hpp:84
node * alloc_node()
Definition: rb_tree.hpp:515
node * left
Definition: rb_tree.hpp:83
node * right
Definition: rb_tree.hpp:85
◆ num_nodes()
template<class TTreeTraits, class TAllocator = std::allocator>
size_type num_nodes(const node *n) const
Definition: rb_tree.hpp:313
◆ rebalance()
template<class TTreeTraits, class TAllocator = std::allocator>
319 assert(new_node->color ==
red);
320 node* iter(new_node);
321 while (iter->parent->color ==
red)
323 node* grandparent(iter->parent->parent);
324 if (iter->parent == grandparent->left)
326 node* uncle = grandparent->right;
328 if (uncle->color ==
red)
330 iter->parent->color =
black;
331 uncle->color =
black;
332 grandparent->color =
red;
337 if (iter == iter->parent->right)
342 grandparent = iter->parent->parent;
343 iter->parent->color =
black;
344 grandparent->color =
red;
350 node* uncle = grandparent->left;
351 if (uncle->color ==
red)
353 grandparent->color =
red;
354 iter->parent->color =
black;
355 uncle->color =
black;
360 if (iter == iter->parent->left)
365 grandparent = iter->parent->parent;
366 iter->parent->color =
black;
367 grandparent->color =
red;
Definition: rb_tree.hpp:48
color_e color
Definition: rb_tree.hpp:87
void rotate_left(node *n)
Definition: rb_tree.hpp:467
Definition: rb_tree.hpp:47
void rotate_right(node *n)
Definition: rb_tree.hpp:491
◆ rebalance_after_erase()
template<class TTreeTraits, class TAllocator = std::allocator>
378 while (iter != m_root && iter->color ==
black)
380 if (iter == iter->parent->left)
382 node* sibling = iter->parent->right;
383 if (sibling->color ==
red)
385 sibling->color =
black;
386 iter->parent->color =
red;
388 sibling = iter->parent->right;
390 if (sibling->left->color ==
black && sibling->right->color ==
black)
392 sibling->color =
red;
397 if (sibling->right->color ==
black)
399 sibling->left->color =
black;
400 sibling->color =
red;
402 sibling = iter->parent->right;
404 sibling->color = iter->parent->color;
405 iter->parent->color =
black;
406 sibling->right->color =
black;
414 if (sibling->color ==
red)
417 iter->parent->color =
red;
419 sibling = iter->parent->left;
421 if (sibling->left->color ==
black && sibling->right->color ==
black)
423 sibling->color =
red;
428 if (sibling->left->color ==
black)
430 sibling->right->color =
black;
431 sibling->color =
red;
433 sibling = iter->parent->left;
435 sibling->color = iter->parent->color;
436 iter->parent->color =
black;
437 sibling->left->color =
black;
Definition: rb_tree.hpp:48
color_e color
Definition: rb_tree.hpp:87
void rotate_left(node *n)
Definition: rb_tree.hpp:467
Definition: rb_tree.hpp:47
node * parent
Definition: rb_tree.hpp:84
void rotate_right(node *n)
Definition: rb_tree.hpp:491
node * left
Definition: rb_tree.hpp:83
◆ rotate_left()
template<class TTreeTraits, class TAllocator = std::allocator>
470 node* rightChild = n->right;
471 n->right = rightChild->left;
472 if (n->right != &ms_sentinel)
473 n->right->parent = n;
476 rightChild->parent = n->parent;
477 if (n->parent == &ms_sentinel)
483 if (n == n->parent->left)
488 rightChild->
left = n;
node * parent
Definition: rb_tree.hpp:84
node * left
Definition: rb_tree.hpp:83
node * right
Definition: rb_tree.hpp:85
◆ rotate_right()
template<class TTreeTraits, class TAllocator = std::allocator>
493 node* leftChild(n->left);
494 n->left = leftChild->right;
496 if (n->left != &ms_sentinel)
499 leftChild->parent = n->parent;
500 if (n->parent == &ms_sentinel)
507 if (n == n->parent->left)
512 leftChild->
right = n;
node * parent
Definition: rb_tree.hpp:84
node * left
Definition: rb_tree.hpp:83
node * right
Definition: rb_tree.hpp:85
◆ size()
template<class TTreeTraits, class TAllocator = std::allocator>
◆ swap()
template<class TTreeTraits, class TAllocator = std::allocator>
225 assert(m_allocator == other.m_allocator);
void swap(TAssignable &a, TAssignable &b)
Definition: algorithm.hpp:205
void validate() const
Definition: rb_tree.hpp:446
◆ traverse()
template<class TTreeTraits, class TAllocator = std::allocator>
void traverse_node(node *n, TravFunc func, int depth)
Definition: rb_tree.hpp:243
◆ traverse_node()
template<class TTreeTraits, class TAllocator = std::allocator>
246 if (n->parent != &ms_sentinel)
248 left = n->parent->left == n;
250 func(n, left, depth);
251 if (n->left != &ms_sentinel)
253 if (n->right != &ms_sentinel)
void traverse_node(node *n, TravFunc func, int depth)
Definition: rb_tree.hpp:243
◆ validate()
template<class TTreeTraits, class TAllocator = std::allocator>
Definition: rb_tree.hpp:48
color_e color
Definition: rb_tree.hpp:87
void validate_node(node *n) const
Definition: rb_tree.hpp:451
◆ validate_node()
template<class TTreeTraits, class TAllocator = std::allocator>
454 assert(n->parent == &ms_sentinel ||
455 n->parent->left == n || n->parent->right == n);
459 assert(n->left->color ==
black);
460 assert(n->right->color ==
black);
462 if (n->left != &ms_sentinel)
464 if (n->right != &ms_sentinel)
Definition: rb_tree.hpp:48
Definition: rb_tree.hpp:47
void validate_node(node *n) const
Definition: rb_tree.hpp:451
Die Dokumentation für diese Klasse wurde erzeugt aufgrund der Datei: