#include <rb_tree.hpp>
template<typename TKey, class TAllocator = std::allocator>
class std::rb_tree< TKey, TAllocator >
◆ allocator_type
◆ key_type
◆ size_type
◆ TravFunc
◆ value_type
◆ color_e
Aufzählungswerte |
---|
red | |
black | |
Definition: rb_tree.hpp:48
Definition: rb_tree.hpp:47
◆ rb_tree()
template<typename TKey , class TAllocator = std::allocator>
554 : internal::rb_tree_base(allocator) {}
◆ alloc_node()
517 node* mem = (node*)m_allocator.allocate(
sizeof(node));
518 return new (mem) node();
◆ clear()
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()
◆ erase() [1/2]
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]
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
void validate() const
Definition: rb_tree.hpp:446
void free_node(node *n, bool recursive)
Definition: rb_tree.hpp:520
◆ find_next_node()
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()
146 while (iter != &ms_sentinel)
148 const key_type& iter_key = iter->value.get_key();
151 else if (key < iter_key)
typename internal::rb_tree_traits< TKey > ::key_type key_type
Definition: rb_tree.hpp:69
◆ free_node()
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()
266 if (m_root != &ms_sentinel)
269 while (iter->left != &ms_sentinel)
◆ insert()
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 * alloc_node()
Definition: rb_tree.hpp:515
◆ num_nodes()
size_type num_nodes(const node *n) const
Definition: rb_tree.hpp:313
◆ rebalance()
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;
372 m_root->color =
black;
Definition: rb_tree.hpp:48
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()
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;
413 node* sibling = iter->parent->left;
414 if (sibling->color ==
red)
416 sibling->color =
black;
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
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
◆ rotate_left()
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)
484 n->parent->left = rightChild;
486 n->parent->right = rightChild;
488 rightChild->left = n;
489 n->parent = rightChild;
◆ rotate_right()
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)
508 n->parent->left = leftChild;
510 n->parent->right = leftChild;
512 leftChild->right = n;
513 n->parent = leftChild;
◆ size()
◆ swap()
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()
void traverse_node(node *n, TravFunc func, int depth)
Definition: rb_tree.hpp:243
◆ traverse_node()
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()
448 assert(m_root->color ==
black);
Definition: rb_tree.hpp:48
void validate_node(node *n) const
Definition: rb_tree.hpp:451
◆ validate_node()
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: