44 join(PB_DS_CLASS_C_DEC& other)
46 PB_DS_ASSERT_VALID((*
this))
47 PB_DS_ASSERT_VALID(other)
48 if (base_type::join_prep(other) == false)
50 PB_DS_ASSERT_VALID((*
this))
51 PB_DS_ASSERT_VALID(other)
55 const node_pointer p_x = other.split_min();
56 join_imp(p_x, other.m_p_head->m_p_parent);
57 base_type::join_finish(other);
58 PB_DS_ASSERT_VALID((*this))
59 PB_DS_ASSERT_VALID(other)
65 join_imp(node_pointer p_x, node_pointer p_r)
67 _GLIBCXX_DEBUG_ASSERT(p_x != 0);
71 const size_type h = black_height(base_type::m_p_head->m_p_parent);
72 const size_type other_h = black_height(p_r);
76 const bool right_join = h >= other_h;
79 join_pos = find_join_pos_right(base_type::m_p_head->m_p_parent,
81 p_x_l = join_pos.
first;
86 p_x_l = base_type::m_p_head->m_p_parent;
87 base_type::m_p_head->m_p_parent = p_r;
89 p_r->m_p_parent = base_type::m_p_head;
91 join_pos = find_join_pos_left(base_type::m_p_head->m_p_parent,
93 p_x_r = join_pos.
first;
96 node_pointer p_parent = join_pos.
second;
97 if (p_parent == base_type::m_p_head)
99 base_type::m_p_head->m_p_parent = p_x;
100 p_x->m_p_parent = base_type::m_p_head;
104 p_x->m_p_parent = p_parent;
106 p_x->m_p_parent->m_p_right = p_x;
108 p_x->m_p_parent->m_p_left = p_x;
111 p_x->m_p_left = p_x_l;
113 p_x_l->m_p_parent = p_x;
115 p_x->m_p_right = p_x_r;
117 p_x_r->m_p_parent = p_x;
121 base_type::initialize_min_max();
122 PB_DS_STRUCT_ONLY_ASSERT_VALID((*
this))
123 base_type::update_to_top(p_x, (node_update* )this);
125 PB_DS_STRUCT_ONLY_ASSERT_VALID((*this))
129 inline typename PB_DS_CLASS_C_DEC::node_pointer
133 node_pointer p_min = base_type::m_p_head->m_p_left;
135 #ifdef _GLIBCXX_DEBUG
136 const node_pointer p_head = base_type::m_p_head;
137 _GLIBCXX_DEBUG_ASSERT(p_min != p_head);
146 typename PB_DS_CLASS_C_DEC::node_pointer,
147 typename PB_DS_CLASS_C_DEC::node_pointer>
149 find_join_pos_right(node_pointer p_l, size_type h_l, size_type h_r)
151 _GLIBCXX_DEBUG_ASSERT(h_l >= h_r);
153 if (base_type::m_p_head->m_p_parent == 0)
156 node_pointer p_l_parent = base_type::m_p_head;
159 if (p_l->m_red ==
false)
161 _GLIBCXX_DEBUG_ASSERT(h_l > 0);
166 p_l = p_l->m_p_right;
169 if (!is_effectively_black(p_l))
172 p_l = p_l->m_p_right;
175 _GLIBCXX_DEBUG_ASSERT(is_effectively_black(p_l));
176 _GLIBCXX_DEBUG_ASSERT(black_height(p_l) == h_r);
177 _GLIBCXX_DEBUG_ASSERT(p_l == 0 || p_l->m_p_parent == p_l_parent);
183 typename PB_DS_CLASS_C_DEC::node_pointer,
184 typename PB_DS_CLASS_C_DEC::node_pointer>
186 find_join_pos_left(node_pointer p_r, size_type h_l, size_type h_r)
188 _GLIBCXX_DEBUG_ASSERT(h_r > h_l);
189 if (base_type::m_p_head->m_p_parent == 0)
191 base_type::m_p_head));
192 node_pointer p_r_parent = base_type::m_p_head;
195 if (p_r->m_red ==
false)
197 _GLIBCXX_DEBUG_ASSERT(h_r > 0);
205 if (!is_effectively_black(p_r))
211 _GLIBCXX_DEBUG_ASSERT(is_effectively_black(p_r));
212 _GLIBCXX_DEBUG_ASSERT(black_height(p_r) == h_l);
213 _GLIBCXX_DEBUG_ASSERT(p_r == 0 || p_r->m_p_parent == p_r_parent);
218 inline typename PB_DS_CLASS_C_DEC::size_type
220 black_height(node_pointer p_nd)
225 if (p_nd->m_red ==
false)
227 p_nd = p_nd->m_p_left;
235 split(key_const_reference r_key, PB_DS_CLASS_C_DEC& other)
237 PB_DS_ASSERT_VALID((*
this))
238 PB_DS_ASSERT_VALID(other)
240 if (base_type::split_prep(r_key, other) == false)
242 PB_DS_ASSERT_VALID((*
this))
243 PB_DS_ASSERT_VALID(other)
247 PB_DS_STRUCT_ONLY_ASSERT_VALID((*this))
248 PB_DS_STRUCT_ONLY_ASSERT_VALID(other)
249 node_pointer p_nd = this->upper_bound(r_key).m_p_nd;
252 node_pointer p_next_nd = p_nd->m_p_parent;
253 if (Cmp_Fn::operator()(r_key, PB_DS_V2F(p_nd->m_value)))
254 split_at_node(p_nd, other);
256 PB_DS_STRUCT_ONLY_ASSERT_VALID((*
this))
257 PB_DS_STRUCT_ONLY_ASSERT_VALID(other)
260 while (p_nd != base_type::m_p_head);
262 base_type::split_finish(other);
263 PB_DS_ASSERT_VALID((*this))
269 split_at_node(node_pointer p_nd, PB_DS_CLASS_C_DEC& other)
271 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
273 node_pointer p_l = p_nd->m_p_left;
274 node_pointer p_r = p_nd->m_p_right;
275 node_pointer p_parent = p_nd->m_p_parent;
276 if (p_parent == base_type::m_p_head)
278 base_type::m_p_head->m_p_parent = p_l;
281 p_l->m_p_parent = base_type::m_p_head;
287 if (p_parent->m_p_left == p_nd)
288 p_parent->m_p_left = p_l;
290 p_parent->m_p_right = p_l;
293 p_l->m_p_parent = p_parent;
295 this->update_to_top(p_parent, (node_update* )
this);
298 remove_fixup(p_l, p_parent);
301 base_type::initialize_min_max();
302 other.join_imp(p_nd, p_r);
303 PB_DS_STRUCT_ONLY_ASSERT_VALID((*
this))
304 PB_DS_STRUCT_ONLY_ASSERT_VALID(other)
_T1 first
second_type is the second bound type
_T2 second
first is a copy of the first object
Struct holding two objects of arbitrary type.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.