35 #ifndef OMEGA_H_RB_TREE_HPP
36 #define OMEGA_H_RB_TREE_HPP
68 void swap(T& a, T& b) {
75 typedef bool Rb_tree_Color_type;
76 static constexpr Rb_tree_Color_type S_rb_tree_red =
false;
77 static constexpr Rb_tree_Color_type S_rb_tree_black =
true;
80 typedef Rb_tree_Color_type Color_type;
89 while (x->M_left !=
nullptr) x = x->M_left;
94 while (x->M_right !=
nullptr) x = x->M_right;
99 template <
class Value>
107 typedef std::ptrdiff_t difference_type;
108 using iterator_category = std::bidirectional_iterator_tag;
112 if (M_node->M_right !=
nullptr) {
113 M_node = M_node->M_right;
114 while (M_node->M_left !=
nullptr) M_node = M_node->M_left;
117 while (M_node == y->M_right) {
121 if (M_node->M_right != y) M_node = y;
126 if (M_node->M_color == S_rb_tree_red &&
127 M_node->M_parent->M_parent == M_node)
128 M_node = M_node->M_right;
129 else if (M_node->M_left !=
nullptr) {
131 while (y->M_right !=
nullptr) y = y->M_right;
135 while (M_node == y->M_left) {
144 template <
class Value,
class Ref,
class Ptr>
146 typedef Value value_type;
147 typedef Ref reference;
159 reference operator*()
const {
return Link_type(M_node)->M_value_field; }
160 pointer operator->()
const {
return &(operator*()); }
166 Self operator++(
int) {
176 Self operator--(
int) {
183 inline bool operator==(
185 return x.M_node == y.M_node;
188 inline bool operator!=(
189 const Rb_tree_base_iterator& x,
const Rb_tree_base_iterator& y) {
190 return x.M_node != y.M_node;
193 inline void Rb_tree_rotate_left(
194 Rb_tree_node_base* x, Rb_tree_node_base*& root) {
195 Rb_tree_node_base* y = x->M_right;
196 x->M_right = y->M_left;
197 if (y->M_left !=
nullptr) y->M_left->M_parent = x;
198 y->M_parent = x->M_parent;
202 else if (x == x->M_parent->M_left)
203 x->M_parent->M_left = y;
205 x->M_parent->M_right = y;
210 inline void Rb_tree_rotate_right(
211 Rb_tree_node_base* x, Rb_tree_node_base*& root) {
212 Rb_tree_node_base* y = x->M_left;
213 x->M_left = y->M_right;
214 if (y->M_right !=
nullptr) y->M_right->M_parent = x;
215 y->M_parent = x->M_parent;
219 else if (x == x->M_parent->M_right)
220 x->M_parent->M_right = y;
222 x->M_parent->M_left = y;
227 inline void Rb_tree_rebalance(Rb_tree_node_base* x, Rb_tree_node_base*& root) {
228 x->M_color = S_rb_tree_red;
229 while (x != root && x->M_parent->M_color == S_rb_tree_red) {
230 if (x->M_parent == x->M_parent->M_parent->M_left) {
231 Rb_tree_node_base* y = x->M_parent->M_parent->M_right;
232 if (y && y->M_color == S_rb_tree_red) {
233 x->M_parent->M_color = S_rb_tree_black;
234 y->M_color = S_rb_tree_black;
235 x->M_parent->M_parent->M_color = S_rb_tree_red;
236 x = x->M_parent->M_parent;
238 if (x == x->M_parent->M_right) {
240 Rb_tree_rotate_left(x, root);
242 x->M_parent->M_color = S_rb_tree_black;
243 x->M_parent->M_parent->M_color = S_rb_tree_red;
244 Rb_tree_rotate_right(x->M_parent->M_parent, root);
247 Rb_tree_node_base* y = x->M_parent->M_parent->M_left;
248 if (y && y->M_color == S_rb_tree_red) {
249 x->M_parent->M_color = S_rb_tree_black;
250 y->M_color = S_rb_tree_black;
251 x->M_parent->M_parent->M_color = S_rb_tree_red;
252 x = x->M_parent->M_parent;
254 if (x == x->M_parent->M_left) {
256 Rb_tree_rotate_right(x, root);
258 x->M_parent->M_color = S_rb_tree_black;
259 x->M_parent->M_parent->M_color = S_rb_tree_red;
260 Rb_tree_rotate_left(x->M_parent->M_parent, root);
264 root->M_color = S_rb_tree_black;
267 inline Rb_tree_node_base* Rb_tree_rebalance_for_erase(Rb_tree_node_base* z,
268 Rb_tree_node_base*& root, Rb_tree_node_base*& leftmost,
269 Rb_tree_node_base*& rightmost) {
270 Rb_tree_node_base* y = z;
271 Rb_tree_node_base* x =
nullptr;
272 Rb_tree_node_base* x_parent =
nullptr;
273 if (y->M_left ==
nullptr)
275 else if (y->M_right ==
nullptr)
279 while (y->M_left !=
nullptr) y = y->M_left;
283 z->M_left->M_parent = y;
284 y->M_left = z->M_left;
285 if (y != z->M_right) {
286 x_parent = y->M_parent;
287 if (x) x->M_parent = y->M_parent;
288 y->M_parent->M_left = x;
289 y->M_right = z->M_right;
290 z->M_right->M_parent = y;
295 else if (z->M_parent->M_left == z)
296 z->M_parent->M_left = y;
298 z->M_parent->M_right = y;
299 y->M_parent = z->M_parent;
300 nonstd::swap(y->M_color, z->M_color);
304 x_parent = y->M_parent;
305 if (x) x->M_parent = y->M_parent;
308 else if (z->M_parent->M_left == z)
309 z->M_parent->M_left = x;
311 z->M_parent->M_right = x;
313 if (z->M_right ==
nullptr) {
314 leftmost = z->M_parent;
317 leftmost = Rb_tree_node_base::S_minimum(x);
320 if (rightmost == z) {
321 if (z->M_left ==
nullptr) {
322 rightmost = z->M_parent;
325 rightmost = Rb_tree_node_base::S_maximum(x);
329 if (y->M_color != S_rb_tree_red) {
330 while (x != root && (x ==
nullptr || x->M_color == S_rb_tree_black))
331 if (x == x_parent->M_left) {
332 Rb_tree_node_base* w = x_parent->M_right;
333 if (w->M_color == S_rb_tree_red) {
334 w->M_color = S_rb_tree_black;
335 x_parent->M_color = S_rb_tree_red;
336 Rb_tree_rotate_left(x_parent, root);
337 w = x_parent->M_right;
339 if ((w->M_left ==
nullptr || w->M_left->M_color == S_rb_tree_black) &&
340 (w->M_right ==
nullptr || w->M_right->M_color == S_rb_tree_black)) {
341 w->M_color = S_rb_tree_red;
343 x_parent = x_parent->M_parent;
345 if (w->M_right ==
nullptr || w->M_right->M_color == S_rb_tree_black) {
346 if (w->M_left) w->M_left->M_color = S_rb_tree_black;
347 w->M_color = S_rb_tree_red;
348 Rb_tree_rotate_right(w, root);
349 w = x_parent->M_right;
351 w->M_color = x_parent->M_color;
352 x_parent->M_color = S_rb_tree_black;
353 if (w->M_right) w->M_right->M_color = S_rb_tree_black;
354 Rb_tree_rotate_left(x_parent, root);
358 Rb_tree_node_base* w = x_parent->M_left;
359 if (w->M_color == S_rb_tree_red) {
360 w->M_color = S_rb_tree_black;
361 x_parent->M_color = S_rb_tree_red;
362 Rb_tree_rotate_right(x_parent, root);
363 w = x_parent->M_left;
365 if ((w->M_right ==
nullptr || w->M_right->M_color == S_rb_tree_black) &&
366 (w->M_left ==
nullptr || w->M_left->M_color == S_rb_tree_black)) {
367 w->M_color = S_rb_tree_red;
369 x_parent = x_parent->M_parent;
371 if (w->M_left ==
nullptr || w->M_left->M_color == S_rb_tree_black) {
372 if (w->M_right) w->M_right->M_color = S_rb_tree_black;
373 w->M_color = S_rb_tree_red;
374 Rb_tree_rotate_left(w, root);
375 w = x_parent->M_left;
377 w->M_color = x_parent->M_color;
378 x_parent->M_color = S_rb_tree_black;
379 if (w->M_left) w->M_left->M_color = S_rb_tree_black;
380 Rb_tree_rotate_right(x_parent, root);
384 if (x) x->M_color = S_rb_tree_black;
396 Rb_tree_base() : M_header(
nullptr) { M_header = M_get_node(); }
409 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
416 typedef Rb_tree_Color_type Color_type;
419 typedef Key key_type;
420 typedef Value value_type;
421 typedef value_type* pointer;
422 typedef const value_type* const_pointer;
423 typedef value_type& reference;
424 typedef const value_type& const_reference;
426 typedef std::size_t size_type;
427 typedef std::ptrdiff_t difference_type;
430 using Base::M_get_node;
431 using Base::M_header;
432 using Base::M_put_node;
435 Link_type M_create_node(
const value_type& x) {
438 new (&tmp->M_value_field) Value(x);
446 Link_type M_create_node(value_type&& x) {
449 new (&tmp->M_value_field) Value(x);
458 Link_type tmp = M_create_node(x->M_value_field);
459 tmp->M_color = x->M_color;
460 tmp->M_left =
nullptr;
461 tmp->M_right =
nullptr;
466 p->M_value_field.~Value();
471 size_type M_node_count;
472 Compare M_key_compare;
478 #pragma clang diagnostic push
479 #pragma clang diagnostic ignored "-Wold-style-cast"
488 static reference S_value(
Link_type x) {
return x->M_value_field; }
489 static const Key& S_key(
Link_type x) {
return KeyOfValue()(S_value(x)); }
490 static Color_type& S_color(
Link_type x) {
return (x->M_color); }
496 static const Key& S_key(
Base_ptr x) {
497 return KeyOfValue()(S_value(
Link_type(x)));
501 #pragma clang diagnostic pop
505 return static_cast<Link_type>(Rb_tree_node_base::S_minimum(x));
509 return static_cast<Link_type>(Rb_tree_node_base::S_maximum(x));
525 Rb_tree() :
Base(), M_node_count(0), M_key_compare() { M_empty_initialize(); }
527 Rb_tree(
const Compare& comp) :
Base(), M_node_count(0), M_key_compare(comp) {
528 M_empty_initialize();
532 :
Base(), M_node_count(0), M_key_compare(x.M_key_compare) {
533 if (x.M_root() ==
nullptr)
534 M_empty_initialize();
536 S_color(M_header) = S_rb_tree_red;
537 M_root() = M_copy(x.M_root(), M_header);
538 M_leftmost() = S_minimum(M_root());
539 M_rightmost() = S_maximum(M_root());
541 M_node_count = x.M_node_count;
548 void M_empty_initialize() {
549 S_color(M_header) = S_rb_tree_red;
552 M_leftmost() = M_header;
553 M_rightmost() = M_header;
558 Compare key_comp()
const {
return M_key_compare; }
559 iterator begin() {
return M_leftmost(); }
563 bool empty()
const {
return M_node_count == 0; }
564 size_type size()
const {
return M_node_count; }
565 size_type max_size()
const {
return size_type(-1); }
568 nonstd::swap(M_header, t.M_header);
569 nonstd::swap(M_node_count, t.M_node_count);
570 nonstd::swap(M_key_compare, t.M_key_compare);
575 std::pair<iterator, bool> insert(
const value_type& x);
576 std::pair<iterator, bool> insert(value_type&& x);
581 template <
class InputIterator>
582 void insert(InputIterator first, InputIterator last);
585 size_type erase(
const key_type& x);
587 void erase(
const key_type* first,
const key_type* last);
589 if (M_node_count != 0) {
591 M_leftmost() = M_header;
593 M_rightmost() = M_header;
602 size_type count(
const key_type& x)
const;
603 iterator lower_bound(
const key_type& x);
605 iterator upper_bound(
const key_type& x);
607 std::pair<iterator, iterator> equal_range(
const key_type& x);
608 std::pair<const_iterator, const_iterator> equal_range(
609 const key_type& x)
const;
612 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
615 return x.size() == y.size() && equal(x.begin(), x.end(), y.begin());
618 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
619 inline bool operator<(
const Rb_tree<Key, Value, KeyOfValue, Compare>& x,
620 const Rb_tree<Key, Value, KeyOfValue, Compare>& y) {
621 return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
624 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
625 Rb_tree<Key, Value, KeyOfValue, Compare>&
626 Rb_tree<Key, Value, KeyOfValue, Compare>::operator=(
627 const Rb_tree<Key, Value, KeyOfValue, Compare>& x) {
631 M_key_compare = x.M_key_compare;
632 if (x.M_root() ==
nullptr) {
634 M_leftmost() = M_header;
635 M_rightmost() = M_header;
637 M_root() = M_copy(x.M_root(), M_header);
638 M_leftmost() = S_minimum(M_root());
639 M_rightmost() = S_maximum(M_root());
640 M_node_count = x.M_node_count;
646 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
647 typename Rb_tree<Key, Value, KeyOfValue, Compare>::iterator
648 Rb_tree<Key, Value, KeyOfValue, Compare>::M_insert(
649 Base_ptr x_, Base_ptr y_,
const Value& v) {
650 Link_type x = Link_type(x_);
651 Link_type y = Link_type(y_);
654 if (y == M_header || x !=
nullptr ||
655 M_key_compare(KeyOfValue()(v), S_key(y))) {
656 z = M_create_node(v);
662 }
else if (y == M_leftmost())
665 z = M_create_node(v);
667 if (y == M_rightmost())
672 S_right(z) =
nullptr;
673 Rb_tree_rebalance(z, M_header->M_parent);
678 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
679 typename Rb_tree<Key, Value, KeyOfValue, Compare>::iterator
680 Rb_tree<Key, Value, KeyOfValue, Compare>::M_insert(
681 Base_ptr x_, Base_ptr y_, Value&& v) {
682 Link_type x = Link_type(x_);
683 Link_type y = Link_type(y_);
686 if (y == M_header || x !=
nullptr ||
687 M_key_compare(KeyOfValue()(v), S_key(y))) {
688 z = M_create_node(std::move(v));
694 }
else if (y == M_leftmost())
697 z = M_create_node(std::move(v));
699 if (y == M_rightmost())
704 S_right(z) =
nullptr;
705 Rb_tree_rebalance(z, M_header->M_parent);
710 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
711 std::pair<typename Rb_tree<Key, Value, KeyOfValue, Compare>::iterator,
bool>
712 Rb_tree<Key, Value, KeyOfValue, Compare>::insert(
const Value& v) {
713 Link_type y = M_header;
714 Link_type x = M_root();
716 while (x !=
nullptr) {
718 comp = M_key_compare(KeyOfValue()(v), S_key(x));
719 x = comp ? S_left(x) : S_right(x);
721 iterator j = iterator(y);
724 return std::pair<iterator, bool>(M_insert(x, y, v),
true);
729 if (M_key_compare(S_key(j.M_node), KeyOfValue()(v))) {
730 return std::pair<iterator, bool>(M_insert(x, y, v),
true);
732 return std::pair<iterator, bool>(j,
false);
735 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
736 std::pair<typename Rb_tree<Key, Value, KeyOfValue, Compare>::iterator,
bool>
737 Rb_tree<Key, Value, KeyOfValue, Compare>::insert(Value&& v) {
738 Link_type y = M_header;
739 Link_type x = M_root();
741 while (x !=
nullptr) {
743 comp = M_key_compare(KeyOfValue()(v), S_key(x));
744 x = comp ? S_left(x) : S_right(x);
746 iterator j = iterator(y);
749 return std::pair<iterator, bool>(M_insert(x, y, std::move(v)),
true);
754 if (M_key_compare(S_key(j.M_node), KeyOfValue()(v))) {
755 return std::pair<iterator, bool>(M_insert(x, y, std::move(v)),
true);
757 return std::pair<iterator, bool>(j,
false);
760 template <
class Key,
class Val,
class KeyOfValue,
class Compare>
761 typename Rb_tree<Key, Val, KeyOfValue, Compare>::iterator
762 Rb_tree<Key, Val, KeyOfValue, Compare>::insert(
763 iterator position,
const Val& v) {
764 if (position.M_node == M_header->M_left) {
765 if (size() > 0 && M_key_compare(KeyOfValue()(v), S_key(position.M_node)))
766 return M_insert(position.M_node, position.M_node, v);
769 return insert(v).first;
770 }
else if (position.M_node == M_header) {
771 if (M_key_compare(S_key(M_rightmost()), KeyOfValue()(v)))
772 return M_insert(
nullptr, M_rightmost(), v);
774 return insert(v).first;
776 iterator before = position;
778 if (M_key_compare(S_key(before.M_node), KeyOfValue()(v)) &&
779 M_key_compare(KeyOfValue()(v), S_key(position.M_node))) {
780 if (S_right(before.M_node) ==
nullptr)
781 return M_insert(
nullptr, before.M_node, v);
783 return M_insert(position.M_node, position.M_node, v);
786 return insert(v).first;
790 template <
class Key,
class Val,
class KeyOfValue,
class Compare>
791 typename Rb_tree<Key, Val, KeyOfValue, Compare>::iterator
792 Rb_tree<Key, Val, KeyOfValue, Compare>::insert(iterator position, Val&& v) {
793 if (position.M_node == M_header->M_left) {
794 if (size() > 0 && M_key_compare(KeyOfValue()(v), S_key(position.M_node)))
795 return M_insert(position.M_node, position.M_node, std::move(v));
798 return insert(std::move(v)).first;
799 }
else if (position.M_node == M_header) {
800 if (M_key_compare(S_key(M_rightmost()), KeyOfValue()(v)))
801 return M_insert(
nullptr, M_rightmost(), std::move(v));
803 return insert(std::move(v)).first;
805 iterator before = position;
807 if (M_key_compare(S_key(before.M_node), KeyOfValue()(v)) &&
808 M_key_compare(KeyOfValue()(v), S_key(position.M_node))) {
809 if (S_right(before.M_node) ==
nullptr)
810 return M_insert(
nullptr, before.M_node, std::move(v));
812 return M_insert(position.M_node, position.M_node, std::move(v));
815 return insert(std::move(v)).first;
819 template <
class Key,
class Val,
class KeyOfValue,
class Cmp>
821 void Rb_tree<Key, Val, KeyOfValue, Cmp>::insert(II first, II last) {
822 for (; first != last; ++first) insert(*first);
825 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
826 inline void Rb_tree<Key, Value, KeyOfValue, Compare>::erase(iterator position) {
827 Link_type y = Rb_tree_rebalance_for_erase(
828 position.M_node, M_header->M_parent, M_header->M_left, M_header->M_right);
833 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
834 typename Rb_tree<Key, Value, KeyOfValue, Compare>::size_type
835 Rb_tree<Key, Value, KeyOfValue, Compare>::erase(
const Key& x) {
836 std::pair<iterator, iterator> p = equal_range(x);
837 size_type n = size_type(std::distance(p.first, p.second));
838 erase(p.first, p.second);
842 template <
class Key,
class Val,
class KeyOfValue,
class Compare>
843 typename Rb_tree<Key, Val, KeyOfValue, Compare>::Link_type
844 Rb_tree<Key, Val, KeyOfValue, Compare>::M_copy(Link_type x, Link_type p) {
846 Link_type top = M_clone_node(x);
850 if (x->M_right) top->M_right = M_copy(S_right(x), top);
854 while (x !=
nullptr) {
855 Link_type y = M_clone_node(x);
858 if (x->M_right) y->M_right = M_copy(S_right(x), y);
870 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
871 void Rb_tree<Key, Value, KeyOfValue, Compare>::M_erase(
873 while (x !=
nullptr) {
875 Link_type y = S_left(x);
881 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
882 void Rb_tree<Key, Value, KeyOfValue, Compare>::erase(
883 iterator first, iterator last) {
884 if (first == begin() && last == end())
887 while (first != last) erase(first++);
890 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
891 void Rb_tree<Key, Value, KeyOfValue, Compare>::erase(
892 const Key* first,
const Key* last) {
893 while (first != last) erase(*first++);
896 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
897 typename Rb_tree<Key, Value, KeyOfValue, Compare>::iterator
898 Rb_tree<Key, Value, KeyOfValue, Compare>::find(
const Key& k) {
899 Link_type y = M_header;
900 Link_type x = M_root();
903 if (!M_key_compare(S_key(x), k))
904 y = x, x = S_left(x);
908 iterator j = iterator(y);
909 return (j == end() || M_key_compare(k, S_key(j.M_node))) ? end() : j;
912 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
913 typename Rb_tree<Key, Value, KeyOfValue, Compare>::const_iterator
914 Rb_tree<Key, Value, KeyOfValue, Compare>::find(
const Key& k)
const {
915 Link_type y = M_header;
916 Link_type x = M_root();
918 while (x !=
nullptr) {
919 if (!M_key_compare(S_key(x), k))
920 y = x, x = S_left(x);
924 const_iterator j = const_iterator(y);
925 return (j == end() || M_key_compare(k, S_key(j.M_node))) ? end() : j;
928 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
929 typename Rb_tree<Key, Value, KeyOfValue, Compare>::size_type
930 Rb_tree<Key, Value, KeyOfValue, Compare>::count(
const Key& k)
const {
931 std::pair<const_iterator, const_iterator> p = equal_range(k);
932 return size_type(std::distance(p.first, p.second));
935 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
936 typename Rb_tree<Key, Value, KeyOfValue, Compare>::iterator
937 Rb_tree<Key, Value, KeyOfValue, Compare>::lower_bound(
const Key& k) {
938 Link_type y = M_header;
939 Link_type x = M_root();
942 if (!M_key_compare(S_key(x), k))
943 y = x, x = S_left(x);
950 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
951 typename Rb_tree<Key, Value, KeyOfValue, Compare>::const_iterator
952 Rb_tree<Key, Value, KeyOfValue, Compare>::lower_bound(
const Key& k)
const {
953 Link_type y = M_header;
954 Link_type x = M_root();
957 if (!M_key_compare(S_key(x), k))
958 y = x, x = S_left(x);
962 return const_iterator(y);
965 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
966 typename Rb_tree<Key, Value, KeyOfValue, Compare>::iterator
967 Rb_tree<Key, Value, KeyOfValue, Compare>::upper_bound(
const Key& k) {
968 Link_type y = M_header;
969 Link_type x = M_root();
972 if (M_key_compare(k, S_key(x)))
973 y = x, x = S_left(x);
980 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
981 typename Rb_tree<Key, Value, KeyOfValue, Compare>::const_iterator
982 Rb_tree<Key, Value, KeyOfValue, Compare>::upper_bound(
const Key& k)
const {
983 Link_type y = M_header;
984 Link_type x = M_root();
987 if (M_key_compare(k, S_key(x)))
988 y = x, x = S_left(x);
992 return const_iterator(y);
995 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
996 inline std::pair<typename Rb_tree<Key, Value, KeyOfValue, Compare>::iterator,
997 typename Rb_tree<Key, Value, KeyOfValue, Compare>::iterator>
998 Rb_tree<Key, Value, KeyOfValue, Compare>::equal_range(
const Key& k) {
999 return std::pair<iterator, iterator>(lower_bound(k), upper_bound(k));
1002 template <
class Key,
class Value,
class KeyOfValue,
class Compare>
1004 typename Rb_tree<Key, Value, KeyOfValue, Compare>::const_iterator,
1005 typename Rb_tree<Key, Value, KeyOfValue, Compare>::const_iterator>
1006 Rb_tree<Key, Value, KeyOfValue, Compare>::equal_range(
const Key& k)
const {
1007 return std::pair<const_iterator, const_iterator>(
1008 lower_bound(k), upper_bound(k));
1011 template <
class Key,
class Value,
class KeyOfValue,
1012 class Compare = std::less<Key>>
1016 rb_tree(
const Compare& comp = Compare()) :
Base(comp) {}
1024 T
const& operator()(T
const& value)
const {
return value; }
1027 template <
class Key>
1030 template <
class T1,
class T2>
1032 T1
const& operator()(std::pair<T1, T2>
const& value)
const {
1037 template <
class Key,
class Value>
1039 :
public rb_tree<Key, std::pair<Key, Value>, Rb_first_as_key<Key, Value>> {
1040 Value& operator[](
const Key& key) {
1041 auto it = this->upper_bound(key);
1042 if (it == this->end() || (!(it->first == key))) {
1043 it = this->insert(it, std::make_pair(key, Value()));
Definition: Omega_h_rbtree.hpp:410
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_rbtree.hpp:1031
Definition: Omega_h_rbtree.hpp:105
Definition: Omega_h_rbtree.hpp:395
Definition: Omega_h_rbtree.hpp:145
Definition: Omega_h_rbtree.hpp:79
Definition: Omega_h_rbtree.hpp:100
Definition: Omega_h_rbtree.hpp:1023
Definition: Omega_h_rbtree.hpp:1039
Definition: Omega_h_rbtree.hpp:1013