41#ifdef PB_DS_CLASS_C_DEC
46join(PB_DS_CLASS_C_DEC& other)
48 PB_DS_ASSERT_VALID((*
this))
49 PB_DS_ASSERT_VALID(other)
50 if (base_type::join_prep(other) == false)
52 PB_DS_ASSERT_VALID((*
this))
53 PB_DS_ASSERT_VALID(other)
57 const node_pointer p_x = other.split_min();
58 join_imp(p_x, other.m_p_head->m_p_parent);
59 base_type::join_finish(other);
60 PB_DS_ASSERT_VALID((*this))
61 PB_DS_ASSERT_VALID(other)
67join_imp(node_pointer p_x, node_pointer p_r)
69 _GLIBCXX_DEBUG_ASSERT(p_x != 0);
73 const size_type h = black_height(base_type::m_p_head->m_p_parent);
74 const size_type other_h = black_height(p_r);
78 const bool right_join = h >= other_h;
81 join_pos = find_join_pos_right(base_type::m_p_head->m_p_parent,
83 p_x_l = join_pos.
first;
88 p_x_l = base_type::m_p_head->m_p_parent;
89 base_type::m_p_head->m_p_parent = p_r;
91 p_r->m_p_parent = base_type::m_p_head;
93 join_pos = find_join_pos_left(base_type::m_p_head->m_p_parent,
95 p_x_r = join_pos.
first;
98 node_pointer p_parent = join_pos.
second;
99 if (p_parent == base_type::m_p_head)
101 base_type::m_p_head->m_p_parent = p_x;
102 p_x->m_p_parent = base_type::m_p_head;
106 p_x->m_p_parent = p_parent;
108 p_x->m_p_parent->m_p_right = p_x;
110 p_x->m_p_parent->m_p_left = p_x;
113 p_x->m_p_left = p_x_l;
115 p_x_l->m_p_parent = p_x;
117 p_x->m_p_right = p_x_r;
119 p_x_r->m_p_parent = p_x;
123 base_type::initialize_min_max();
124 PB_DS_STRUCT_ONLY_ASSERT_VALID((*
this))
125 base_type::update_to_top(p_x, (node_update* )this);
127 PB_DS_STRUCT_ONLY_ASSERT_VALID((*this))
131inline typename PB_DS_CLASS_C_DEC::node_pointer
135 node_pointer p_min = base_type::m_p_head->m_p_left;
138 const node_pointer p_head = base_type::m_p_head;
139 _GLIBCXX_DEBUG_ASSERT(p_min != p_head);
148 typename PB_DS_CLASS_C_DEC::node_pointer,
149 typename PB_DS_CLASS_C_DEC::node_pointer>
151find_join_pos_right(node_pointer p_l, size_type h_l, size_type h_r)
153 _GLIBCXX_DEBUG_ASSERT(h_l >= h_r);
155 if (base_type::m_p_head->m_p_parent == 0)
156 return (std::make_pair((node_pointer)0, base_type::m_p_head));
158 node_pointer p_l_parent = base_type::m_p_head;
161 if (p_l->m_red ==
false)
163 _GLIBCXX_DEBUG_ASSERT(h_l > 0);
168 p_l = p_l->m_p_right;
171 if (!is_effectively_black(p_l))
174 p_l = p_l->m_p_right;
177 _GLIBCXX_DEBUG_ASSERT(is_effectively_black(p_l));
178 _GLIBCXX_DEBUG_ASSERT(black_height(p_l) == h_r);
179 _GLIBCXX_DEBUG_ASSERT(p_l == 0 || p_l->m_p_parent == p_l_parent);
180 return std::make_pair(p_l, p_l_parent);
185 typename PB_DS_CLASS_C_DEC::node_pointer,
186 typename PB_DS_CLASS_C_DEC::node_pointer>
188find_join_pos_left(node_pointer p_r, size_type h_l, size_type h_r)
190 _GLIBCXX_DEBUG_ASSERT(h_r > h_l);
191 if (base_type::m_p_head->m_p_parent == 0)
192 return (std::make_pair((node_pointer)0,
193 base_type::m_p_head));
194 node_pointer p_r_parent = base_type::m_p_head;
197 if (p_r->m_red ==
false)
199 _GLIBCXX_DEBUG_ASSERT(h_r > 0);
207 if (!is_effectively_black(p_r))
213 _GLIBCXX_DEBUG_ASSERT(is_effectively_black(p_r));
214 _GLIBCXX_DEBUG_ASSERT(black_height(p_r) == h_l);
215 _GLIBCXX_DEBUG_ASSERT(p_r == 0 || p_r->m_p_parent == p_r_parent);
216 return std::make_pair(p_r, p_r_parent);
220inline typename PB_DS_CLASS_C_DEC::size_type
222black_height(node_pointer p_nd)
227 if (p_nd->m_red ==
false)
229 p_nd = p_nd->m_p_left;
237split(key_const_reference r_key, PB_DS_CLASS_C_DEC& other)
239 PB_DS_ASSERT_VALID((*
this))
240 PB_DS_ASSERT_VALID(other)
242 if (base_type::split_prep(r_key, other) == false)
244 PB_DS_ASSERT_VALID((*
this))
245 PB_DS_ASSERT_VALID(other)
249 PB_DS_STRUCT_ONLY_ASSERT_VALID((*this))
250 PB_DS_STRUCT_ONLY_ASSERT_VALID(other)
251 node_pointer p_nd = this->upper_bound(r_key).m_p_nd;
254 node_pointer p_next_nd = p_nd->m_p_parent;
255 if (Cmp_Fn::operator()(r_key, PB_DS_V2F(p_nd->m_value)))
256 split_at_node(p_nd, other);
258 PB_DS_STRUCT_ONLY_ASSERT_VALID((*
this))
259 PB_DS_STRUCT_ONLY_ASSERT_VALID(other)
262 while (p_nd != base_type::m_p_head);
264 base_type::split_finish(other);
265 PB_DS_ASSERT_VALID((*this))
271split_at_node(node_pointer p_nd, PB_DS_CLASS_C_DEC& other)
273 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
275 node_pointer p_l = p_nd->m_p_left;
276 node_pointer p_r = p_nd->m_p_right;
277 node_pointer p_parent = p_nd->m_p_parent;
278 if (p_parent == base_type::m_p_head)
280 base_type::m_p_head->m_p_parent = p_l;
283 p_l->m_p_parent = base_type::m_p_head;
289 if (p_parent->m_p_left == p_nd)
290 p_parent->m_p_left = p_l;
292 p_parent->m_p_right = p_l;
295 p_l->m_p_parent = p_parent;
297 this->update_to_top(p_parent, (node_update* )
this);
300 remove_fixup(p_l, p_parent);
303 base_type::initialize_min_max();
304 other.join_imp(p_nd, p_r);
305 PB_DS_STRUCT_ONLY_ASSERT_VALID((*
this))
306 PB_DS_STRUCT_ONLY_ASSERT_VALID(other)
Struct holding two objects of arbitrary type.
_T1 first
The first member.
_T2 second
The second member.