44 join(PB_DS_CLASS_C_DEC& other)
46 PB_DS_ASSERT_VALID((*
this))
47 PB_DS_ASSERT_VALID(other)
49 if (!join_prep(other, bag))
51 PB_DS_ASSERT_VALID((*
this))
52 PB_DS_ASSERT_VALID(other)
56 m_p_head->m_p_parent = rec_join(m_p_head->m_p_parent,
57 other.m_p_head->m_p_parent, 0, bag);
59 m_p_head->m_p_parent->m_p_parent = m_p_head;
60 m_size += other.m_size;
62 PB_DS_ASSERT_VALID(other)
63 m_p_head->m_p_min = leftmost_descendant(m_p_head->m_p_parent);
64 m_p_head->m_p_max = rightmost_descendant(m_p_head->m_p_parent);
65 PB_DS_ASSERT_VALID((*this))
71 join_prep(PB_DS_CLASS_C_DEC& other, branch_bag& r_bag)
73 PB_DS_ASSERT_VALID((*
this))
74 PB_DS_ASSERT_VALID(other)
75 if (other.m_size == 0)
85 synth_access_traits::cmp_keys(PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_max)->value()),
86 PB_DS_V2F(static_cast<leaf_const_pointer>(other.m_p_head->m_p_min)->value()));
89 synth_access_traits::cmp_keys(PB_DS_V2F(static_cast<leaf_const_pointer>(other.m_p_head->m_p_max)->value()),
90 PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_min)->value()));
92 if (!greater && !lesser)
95 rec_join_prep(m_p_head->m_p_parent, other.m_p_head->m_p_parent, r_bag);
96 _GLIBCXX_DEBUG_ONLY(debug_base::join(other,
false);)
103 rec_join_prep(node_const_pointer p_l, node_const_pointer p_r,
106 if (p_l->m_type == leaf_node)
108 if (p_r->m_type == leaf_node)
110 rec_join_prep(static_cast<leaf_const_pointer>(p_l),
111 static_cast<leaf_const_pointer>(p_r), r_bag);
115 _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node);
116 rec_join_prep(static_cast<leaf_const_pointer>(p_l),
117 static_cast<inode_const_pointer>(p_r), r_bag);
121 _GLIBCXX_DEBUG_ASSERT(p_l->m_type == i_node);
122 if (p_r->m_type == leaf_node)
124 rec_join_prep(static_cast<inode_const_pointer>(p_l),
125 static_cast<leaf_const_pointer>(p_r), r_bag);
129 _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node);
131 rec_join_prep(static_cast<inode_const_pointer>(p_l),
132 static_cast<inode_const_pointer>(p_r), r_bag);
138 rec_join_prep(leaf_const_pointer , leaf_const_pointer ,
140 { r_bag.add_branch(); }
145 rec_join_prep(leaf_const_pointer , inode_const_pointer ,
147 { r_bag.add_branch(); }
152 rec_join_prep(inode_const_pointer , leaf_const_pointer ,
154 { r_bag.add_branch(); }
159 rec_join_prep(inode_const_pointer p_l, inode_const_pointer p_r,
162 if (p_l->get_e_ind() == p_r->get_e_ind() &&
163 synth_access_traits::equal_prefixes(p_l->pref_b_it(), p_l->pref_e_it(),
164 p_r->pref_b_it(), p_r->pref_e_it()))
166 for (
typename inode::const_iterator it = p_r->begin();
167 it != p_r->end(); ++ it)
169 node_const_pointer p_l_join_child = p_l->get_join_child(*it,
this);
170 if (p_l_join_child != 0)
171 rec_join_prep(p_l_join_child, * it, r_bag);
176 if (p_r->get_e_ind() < p_l->get_e_ind() &&
177 p_r->should_be_mine(p_l->pref_b_it(), p_l->pref_e_it(), 0,
this))
179 node_const_pointer p_r_join_child = p_r->get_join_child(p_l,
this);
180 if (p_r_join_child != 0)
181 rec_join_prep(p_r_join_child, p_l, r_bag);
185 if (p_r->get_e_ind() < p_l->get_e_ind() &&
186 p_r->should_be_mine(p_l->pref_b_it(), p_l->pref_e_it(), 0,
this))
188 node_const_pointer p_r_join_child = p_r->get_join_child(p_l,
this);
189 if (p_r_join_child != 0)
190 rec_join_prep(p_r_join_child, p_l, r_bag);
197 typename PB_DS_CLASS_C_DEC::node_pointer
199 rec_join(node_pointer p_l, node_pointer p_r, size_type checked_ind,
202 _GLIBCXX_DEBUG_ASSERT(p_r != 0);
205 apply_update(p_r, (node_update*)
this);
209 if (p_l->m_type == leaf_node)
211 if (p_r->m_type == leaf_node)
213 node_pointer p_ret = rec_join(static_cast<leaf_pointer>(p_l),
214 static_cast<leaf_pointer>(p_r), r_bag);
215 apply_update(p_ret, (node_update*)
this);
219 _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node);
220 node_pointer p_ret = rec_join(static_cast<leaf_pointer>(p_l),
221 static_cast<inode_pointer>(p_r),
223 apply_update(p_ret, (node_update*)
this);
227 _GLIBCXX_DEBUG_ASSERT(p_l->m_type == i_node);
228 if (p_r->m_type == leaf_node)
230 node_pointer p_ret = rec_join(static_cast<inode_pointer>(p_l),
231 static_cast<leaf_pointer>(p_r),
233 apply_update(p_ret, (node_update*)
this);
237 _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node);
238 node_pointer p_ret = rec_join(static_cast<inode_pointer>(p_l),
239 static_cast<inode_pointer>(p_r),
242 apply_update(p_ret, (node_update*)
this);
247 typename PB_DS_CLASS_C_DEC::node_pointer
249 rec_join(leaf_pointer p_l, leaf_pointer p_r, branch_bag& r_bag)
251 _GLIBCXX_DEBUG_ASSERT(p_r != 0);
254 node_pointer p_ret = insert_branch(p_l, p_r, r_bag);
255 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) == 2);
260 typename PB_DS_CLASS_C_DEC::node_pointer
262 rec_join(leaf_pointer p_l, inode_pointer p_r, size_type checked_ind,
265 #ifdef _GLIBCXX_DEBUG 266 const size_type lhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_l);
267 const size_type rhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_r);
270 _GLIBCXX_DEBUG_ASSERT(p_r != 0);
271 node_pointer p_ret = rec_join(p_r, p_l, checked_ind, r_bag);
272 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) == lhs_leafs + rhs_leafs);
277 typename PB_DS_CLASS_C_DEC::node_pointer
279 rec_join(inode_pointer p_l, leaf_pointer p_r, size_type checked_ind, branch_bag& r_bag)
281 _GLIBCXX_DEBUG_ASSERT(p_l != 0);
282 _GLIBCXX_DEBUG_ASSERT(p_r != 0);
284 #ifdef _GLIBCXX_DEBUG 285 const size_type lhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_l);
286 const size_type rhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_r);
289 if (!p_l->should_be_mine(pref_begin(p_r), pref_end(p_r), checked_ind,
this))
291 node_pointer p_ret = insert_branch(p_l, p_r, r_bag);
292 PB_DS_ASSERT_NODE_VALID(p_ret)
293 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) ==
294 lhs_leafs + rhs_leafs);
298 node_pointer p_pot_child = p_l->add_child(p_r, pref_begin(p_r),
299 pref_end(p_r),
this);
300 if (p_pot_child != p_r)
302 node_pointer p_new_child = rec_join(p_pot_child, p_r, p_l->get_e_ind(),
305 p_l->replace_child(p_new_child, pref_begin(p_new_child),
306 pref_end(p_new_child),
this);
309 PB_DS_ASSERT_NODE_VALID(p_l)
310 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_l) == lhs_leafs + rhs_leafs);
315 typename PB_DS_CLASS_C_DEC::node_pointer
317 rec_join(inode_pointer p_l, inode_pointer p_r,
320 _GLIBCXX_DEBUG_ASSERT(p_l != 0);
321 _GLIBCXX_DEBUG_ASSERT(p_r != 0);
323 #ifdef _GLIBCXX_DEBUG 324 const size_type lhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_l);
325 const size_type rhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_r);
328 if (p_l->get_e_ind() == p_r->get_e_ind() &&
329 synth_access_traits::equal_prefixes(p_l->pref_b_it(), p_l->pref_e_it(),
330 p_r->pref_b_it(), p_r->pref_e_it()))
332 for (
typename inode::iterator it = p_r->begin();
333 it != p_r->end(); ++ it)
335 node_pointer p_new_child = rec_join(p_l->get_join_child(*it,
this),
337 p_l->replace_child(p_new_child, pref_begin(p_new_child),
338 pref_end(p_new_child),
this);
342 s_inode_allocator.deallocate(p_r, 1);
343 PB_DS_ASSERT_NODE_VALID(p_l)
344 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_l) == lhs_leafs + rhs_leafs);
348 if (p_l->get_e_ind() < p_r->get_e_ind() &&
349 p_l->should_be_mine(p_r->pref_b_it(), p_r->pref_e_it(), 0,
this))
351 node_pointer p_new_child = rec_join(p_l->get_join_child(p_r,
this),
353 p_l->replace_child(p_new_child, pref_begin(p_new_child),
354 pref_end(p_new_child),
this);
355 PB_DS_ASSERT_NODE_VALID(p_l)
359 if (p_r->get_e_ind() < p_l->get_e_ind() &&
360 p_r->should_be_mine(p_l->pref_b_it(), p_l->pref_e_it(), 0,
this))
362 node_pointer p_new_child = rec_join(p_r->get_join_child(p_l,
this), p_l,
365 p_r->replace_child(p_new_child, pref_begin(p_new_child),
366 pref_end(p_new_child),
this);
368 PB_DS_ASSERT_NODE_VALID(p_r)
369 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_r) == lhs_leafs + rhs_leafs);
373 node_pointer p_ret = insert_branch(p_l, p_r, r_bag);
374 PB_DS_ASSERT_NODE_VALID(p_ret)
375 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) == lhs_leafs + rhs_leafs);
382 insert(const_reference r_val)
384 node_pointer p_lf = find_imp(PB_DS_V2F(r_val));
385 if (p_lf != 0 && p_lf->m_type == leaf_node &&
386 synth_access_traits::equal_keys(PB_DS_V2F(static_cast<leaf_pointer>(p_lf)->value()), PB_DS_V2F(r_val)))
388 PB_DS_CHECK_KEY_EXISTS(PB_DS_V2F(r_val))
389 PB_DS_ASSERT_VALID((*
this))
393 PB_DS_CHECK_KEY_DOES_NOT_EXIST(PB_DS_V2F(r_val))
395 leaf_pointer p_new_lf = s_leaf_allocator.allocate(1);
396 cond_dealtor cond(p_new_lf);
398 new (p_new_lf) leaf(r_val);
399 apply_update(p_new_lf, (node_update*)this);
400 cond.set_call_destructor();
403 m_p_head->m_p_parent = rec_join(m_p_head->m_p_parent, p_new_lf, 0, bag);
404 m_p_head->m_p_parent->m_p_parent = m_p_head;
405 cond.set_no_action_dtor();
407 update_min_max_for_inserted_leaf(p_new_lf);
408 _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_val));)
409 PB_DS_ASSERT_VALID((*this))
414 typename PB_DS_CLASS_C_DEC::size_type
416 keys_diff_ind(typename access_traits::const_iterator b_l,
417 typename access_traits::const_iterator e_l,
418 typename access_traits::const_iterator b_r,
419 typename access_traits::const_iterator e_r)
421 size_type diff_pos = 0;
426 if (access_traits::e_pos(*b_l) != access_traits::e_pos(*b_r))
432 _GLIBCXX_DEBUG_ASSERT(b_r != e_r);
437 typename PB_DS_CLASS_C_DEC::inode_pointer
439 insert_branch(node_pointer p_l, node_pointer p_r, branch_bag& r_bag)
441 typename synth_access_traits::const_iterator left_b_it = pref_begin(p_l);
442 typename synth_access_traits::const_iterator left_e_it = pref_end(p_l);
443 typename synth_access_traits::const_iterator right_b_it = pref_begin(p_r);
444 typename synth_access_traits::const_iterator right_e_it = pref_end(p_r);
446 const size_type diff_ind = keys_diff_ind(left_b_it, left_e_it,
447 right_b_it, right_e_it);
449 inode_pointer p_new_nd = r_bag.get_branch();
450 new (p_new_nd) inode(diff_ind, left_b_it);
451 p_new_nd->add_child(p_l, left_b_it, left_e_it,
this);
452 p_new_nd->add_child(p_r, right_b_it, right_e_it,
this);
453 p_l->m_p_parent = p_new_nd;
454 p_r->m_p_parent = p_new_nd;
455 PB_DS_ASSERT_NODE_VALID(p_new_nd)
462 update_min_max_for_inserted_leaf(leaf_pointer p_new_lf)
464 if (m_p_head->m_p_min == m_p_head ||
465 synth_access_traits::cmp_keys(PB_DS_V2F(p_new_lf->value()),
466 PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_min)->value())))
467 m_p_head->m_p_min = p_new_lf;
469 if (m_p_head->m_p_max == m_p_head ||
470 synth_access_traits::cmp_keys(PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_max)->value()), PB_DS_V2F(p_new_lf->value())))
471 m_p_head->m_p_max = p_new_lf;
ISO C++ entities toplevel namespace is std.
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.
Struct holding two objects of arbitrary type.