49 if (!join_prep(other, bag))
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;
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);
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);
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);
116 rec_join_prep(static_cast<leaf_const_pointer>(p_l),
117 static_cast<inode_const_pointer>(p_r), r_bag);
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);
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,
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);
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);
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);
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)
254 node_pointer p_ret = insert_branch(p_l, p_r, r_bag);
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
271 node_pointer p_ret = rec_join(p_r, p_l, checked_ind, r_bag);
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)
284 #ifdef _GLIBCXX_DEBUG
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);
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);
317 rec_join(inode_pointer p_l, inode_pointer p_r,
323 #ifdef _GLIBCXX_DEBUG
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);
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);
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);
373 node_pointer p_ret = insert_branch(p_l, p_r, r_bag);
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)))
390 return std::make_pair(iterator(p_lf),
false);
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);
410 return std::make_pair(point_iterator(p_new_lf),
true);
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))
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;
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;
#define false
Definition: stdbool.h:35
#define _GLIBCXX_DEBUG_ASSERT(_Condition)
Definition: debug.h:61
#define true
Definition: stdbool.h:34
#define _GLIBCXX_DEBUG_ONLY(_Statement)
Definition: debug.h:63
#define PB_DS_CLASS_C_DEC
Definition: bin_search_tree_.hpp:71
#define PB_DS_CLASS_T_DEC
Definition: bin_search_tree_.hpp:67
return(unsigned int) __res
#define PB_DS_ASSERT_NODE_VALID(X)
Definition: pat_trie_.hpp:570
void __throw_join_error()
Definition: exception.hpp:84
#define PB_DS_CHECK_KEY_EXISTS(_Key)
Definition: container_base_dispatch.hpp:55
#define PB_DS_ASSERT_VALID(X)
Definition: binary_heap_.hpp:324
#define PB_DS_V2F(X)
Definition: container_base_dispatch.hpp:80
#define PB_DS_CHECK_KEY_DOES_NOT_EXIST(_Key)
Definition: container_base_dispatch.hpp:58
#define PB_DS_RECURSIVE_COUNT_LEAFS(X)
Definition: pat_trie_.hpp:573