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)
51 if (!join_prep(other, bag))
53 PB_DS_ASSERT_VALID((*
this))
54 PB_DS_ASSERT_VALID(other)
58 m_p_head->m_p_parent = rec_join(m_p_head->m_p_parent,
59 other.m_p_head->m_p_parent, 0, bag);
61 m_p_head->m_p_parent->m_p_parent = m_p_head;
62 m_size += other.m_size;
64 PB_DS_ASSERT_VALID(other)
65 m_p_head->m_p_min = leftmost_descendant(m_p_head->m_p_parent);
66 m_p_head->m_p_max = rightmost_descendant(m_p_head->m_p_parent);
67 PB_DS_ASSERT_VALID((*this))
73join_prep(PB_DS_CLASS_C_DEC& other, branch_bag& r_bag)
75 PB_DS_ASSERT_VALID((*
this))
76 PB_DS_ASSERT_VALID(other)
77 if (other.m_size == 0)
87 synth_access_traits::cmp_keys(PB_DS_V2F(
static_cast<leaf_const_pointer
>(m_p_head->m_p_max)->value()),
88 PB_DS_V2F(
static_cast<leaf_const_pointer
>(other.m_p_head->m_p_min)->value()));
91 synth_access_traits::cmp_keys(PB_DS_V2F(
static_cast<leaf_const_pointer
>(other.m_p_head->m_p_max)->value()),
92 PB_DS_V2F(
static_cast<leaf_const_pointer
>(m_p_head->m_p_min)->value()));
94 if (!greater && !lesser)
97 rec_join_prep(m_p_head->m_p_parent, other.m_p_head->m_p_parent, r_bag);
98 _GLIBCXX_DEBUG_ONLY(debug_base::join(other,
false);)
105rec_join_prep(node_const_pointer p_l, node_const_pointer p_r,
108 if (p_l->m_type == leaf_node)
110 if (p_r->m_type == leaf_node)
112 rec_join_prep(
static_cast<leaf_const_pointer
>(p_l),
113 static_cast<leaf_const_pointer
>(p_r), r_bag);
117 _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node);
118 rec_join_prep(
static_cast<leaf_const_pointer
>(p_l),
119 static_cast<inode_const_pointer
>(p_r), r_bag);
123 _GLIBCXX_DEBUG_ASSERT(p_l->m_type == i_node);
124 if (p_r->m_type == leaf_node)
126 rec_join_prep(
static_cast<inode_const_pointer
>(p_l),
127 static_cast<leaf_const_pointer
>(p_r), r_bag);
131 _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node);
133 rec_join_prep(
static_cast<inode_const_pointer
>(p_l),
134 static_cast<inode_const_pointer
>(p_r), r_bag);
140rec_join_prep(leaf_const_pointer , leaf_const_pointer ,
142{ r_bag.add_branch(); }
147rec_join_prep(leaf_const_pointer , inode_const_pointer ,
149{ r_bag.add_branch(); }
154rec_join_prep(inode_const_pointer , leaf_const_pointer ,
156{ r_bag.add_branch(); }
161rec_join_prep(inode_const_pointer p_l, inode_const_pointer p_r,
164 if (p_l->get_e_ind() == p_r->get_e_ind() &&
165 synth_access_traits::equal_prefixes(p_l->pref_b_it(), p_l->pref_e_it(),
166 p_r->pref_b_it(), p_r->pref_e_it()))
168 for (
typename inode::const_iterator it = p_r->begin();
169 it != p_r->end(); ++ it)
171 node_const_pointer p_l_join_child = p_l->get_join_child(*it,
this);
172 if (p_l_join_child != 0)
173 rec_join_prep(p_l_join_child, * it, r_bag);
178 if (p_r->get_e_ind() < p_l->get_e_ind() &&
179 p_r->should_be_mine(p_l->pref_b_it(), p_l->pref_e_it(), 0,
this))
181 node_const_pointer p_r_join_child = p_r->get_join_child(p_l,
this);
182 if (p_r_join_child != 0)
183 rec_join_prep(p_r_join_child, p_l, r_bag);
187 if (p_r->get_e_ind() < p_l->get_e_ind() &&
188 p_r->should_be_mine(p_l->pref_b_it(), p_l->pref_e_it(), 0,
this))
190 node_const_pointer p_r_join_child = p_r->get_join_child(p_l,
this);
191 if (p_r_join_child != 0)
192 rec_join_prep(p_r_join_child, p_l, r_bag);
199typename PB_DS_CLASS_C_DEC::node_pointer
201rec_join(node_pointer p_l, node_pointer p_r, size_type checked_ind,
204 _GLIBCXX_DEBUG_ASSERT(p_r != 0);
207 apply_update(p_r, (node_update*)
this);
211 if (p_l->m_type == leaf_node)
213 if (p_r->m_type == leaf_node)
215 node_pointer p_ret = rec_join(
static_cast<leaf_pointer
>(p_l),
216 static_cast<leaf_pointer
>(p_r), r_bag);
217 apply_update(p_ret, (node_update*)
this);
221 _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node);
222 node_pointer p_ret = rec_join(
static_cast<leaf_pointer
>(p_l),
223 static_cast<inode_pointer
>(p_r),
225 apply_update(p_ret, (node_update*)
this);
229 _GLIBCXX_DEBUG_ASSERT(p_l->m_type == i_node);
230 if (p_r->m_type == leaf_node)
232 node_pointer p_ret = rec_join(
static_cast<inode_pointer
>(p_l),
233 static_cast<leaf_pointer
>(p_r),
235 apply_update(p_ret, (node_update*)
this);
239 _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node);
240 node_pointer p_ret = rec_join(
static_cast<inode_pointer
>(p_l),
241 static_cast<inode_pointer
>(p_r),
244 apply_update(p_ret, (node_update*)
this);
249typename PB_DS_CLASS_C_DEC::node_pointer
251rec_join(leaf_pointer p_l, leaf_pointer p_r, branch_bag& r_bag)
253 _GLIBCXX_DEBUG_ASSERT(p_r != 0);
256 node_pointer p_ret = insert_branch(p_l, p_r, r_bag);
257 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) == 2);
262typename PB_DS_CLASS_C_DEC::node_pointer
264rec_join(leaf_pointer p_l, inode_pointer p_r, size_type checked_ind,
268 const size_type lhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_l);
269 const size_type rhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_r);
272 _GLIBCXX_DEBUG_ASSERT(p_r != 0);
273 node_pointer p_ret = rec_join(p_r, p_l, checked_ind, r_bag);
274 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) == lhs_leafs + rhs_leafs);
279typename PB_DS_CLASS_C_DEC::node_pointer
281rec_join(inode_pointer p_l, leaf_pointer p_r, size_type checked_ind, branch_bag& r_bag)
283 _GLIBCXX_DEBUG_ASSERT(p_l != 0);
284 _GLIBCXX_DEBUG_ASSERT(p_r != 0);
287 const size_type lhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_l);
288 const size_type rhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_r);
291 if (!p_l->should_be_mine(pref_begin(p_r), pref_end(p_r), checked_ind,
this))
293 node_pointer p_ret = insert_branch(p_l, p_r, r_bag);
294 PB_DS_ASSERT_NODE_VALID(p_ret)
295 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) ==
296 lhs_leafs + rhs_leafs);
300 node_pointer p_pot_child = p_l->add_child(p_r, pref_begin(p_r),
301 pref_end(p_r),
this);
302 if (p_pot_child != p_r)
304 node_pointer p_new_child = rec_join(p_pot_child, p_r, p_l->get_e_ind(),
307 p_l->replace_child(p_new_child, pref_begin(p_new_child),
308 pref_end(p_new_child),
this);
311 PB_DS_ASSERT_NODE_VALID(p_l)
312 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_l) == lhs_leafs + rhs_leafs);
317typename PB_DS_CLASS_C_DEC::node_pointer
319rec_join(inode_pointer p_l, inode_pointer p_r,
322 _GLIBCXX_DEBUG_ASSERT(p_l != 0);
323 _GLIBCXX_DEBUG_ASSERT(p_r != 0);
326 const size_type lhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_l);
327 const size_type rhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_r);
330 if (p_l->get_e_ind() == p_r->get_e_ind() &&
331 synth_access_traits::equal_prefixes(p_l->pref_b_it(), p_l->pref_e_it(),
332 p_r->pref_b_it(), p_r->pref_e_it()))
334 for (
typename inode::iterator it = p_r->begin();
335 it != p_r->end(); ++ it)
337 node_pointer p_new_child = rec_join(p_l->get_join_child(*it,
this),
339 p_l->replace_child(p_new_child, pref_begin(p_new_child),
340 pref_end(p_new_child),
this);
344 s_inode_allocator.deallocate(p_r, 1);
345 PB_DS_ASSERT_NODE_VALID(p_l)
346 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_l) == lhs_leafs + rhs_leafs);
350 if (p_l->get_e_ind() < p_r->get_e_ind() &&
351 p_l->should_be_mine(p_r->pref_b_it(), p_r->pref_e_it(), 0,
this))
353 node_pointer p_new_child = rec_join(p_l->get_join_child(p_r,
this),
355 p_l->replace_child(p_new_child, pref_begin(p_new_child),
356 pref_end(p_new_child),
this);
357 PB_DS_ASSERT_NODE_VALID(p_l)
361 if (p_r->get_e_ind() < p_l->get_e_ind() &&
362 p_r->should_be_mine(p_l->pref_b_it(), p_l->pref_e_it(), 0,
this))
364 node_pointer p_new_child = rec_join(p_r->get_join_child(p_l,
this), p_l,
367 p_r->replace_child(p_new_child, pref_begin(p_new_child),
368 pref_end(p_new_child),
this);
370 PB_DS_ASSERT_NODE_VALID(p_r)
371 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_r) == lhs_leafs + rhs_leafs);
375 node_pointer p_ret = insert_branch(p_l, p_r, r_bag);
376 PB_DS_ASSERT_NODE_VALID(p_ret)
377 _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) == lhs_leafs + rhs_leafs);
384insert(const_reference r_val)
386 node_pointer p_lf = find_imp(PB_DS_V2F(r_val));
387 if (p_lf != 0 && p_lf->m_type == leaf_node &&
388 synth_access_traits::equal_keys(PB_DS_V2F(
static_cast<leaf_pointer
>(p_lf)->value()), PB_DS_V2F(r_val)))
390 PB_DS_CHECK_KEY_EXISTS(PB_DS_V2F(r_val))
391 PB_DS_ASSERT_VALID((*
this))
392 return
std::make_pair(iterator(p_lf), false);
395 PB_DS_CHECK_KEY_DOES_NOT_EXIST(PB_DS_V2F(r_val))
397 leaf_pointer p_new_lf = s_leaf_allocator.allocate(1);
398 cond_dealtor cond(p_new_lf);
400 new (p_new_lf) leaf(r_val);
401 apply_update(p_new_lf, (node_update*)this);
402 cond.set_call_destructor();
405 m_p_head->m_p_parent = rec_join(m_p_head->m_p_parent, p_new_lf, 0, bag);
406 m_p_head->m_p_parent->m_p_parent = m_p_head;
407 cond.set_no_action_dtor();
409 update_min_max_for_inserted_leaf(p_new_lf);
410 _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_val));)
411 PB_DS_ASSERT_VALID((*this))
412 return
std::make_pair(point_iterator(p_new_lf), true);
416typename PB_DS_CLASS_C_DEC::size_type
418keys_diff_ind(typename access_traits::const_iterator b_l,
419 typename access_traits::const_iterator e_l,
420 typename access_traits::const_iterator b_r,
421 typename access_traits::const_iterator e_r)
423 size_type diff_pos = 0;
428 if (access_traits::e_pos(*b_l) != access_traits::e_pos(*b_r))
434 _GLIBCXX_DEBUG_ASSERT(b_r != e_r);
439typename PB_DS_CLASS_C_DEC::inode_pointer
441insert_branch(node_pointer p_l, node_pointer p_r, branch_bag& r_bag)
443 typename synth_access_traits::const_iterator left_b_it = pref_begin(p_l);
444 typename synth_access_traits::const_iterator left_e_it = pref_end(p_l);
445 typename synth_access_traits::const_iterator right_b_it = pref_begin(p_r);
446 typename synth_access_traits::const_iterator right_e_it = pref_end(p_r);
448 const size_type diff_ind = keys_diff_ind(left_b_it, left_e_it,
449 right_b_it, right_e_it);
451 inode_pointer p_new_nd = r_bag.get_branch();
452 new (p_new_nd) inode(diff_ind, left_b_it);
453 p_new_nd->add_child(p_l, left_b_it, left_e_it,
this);
454 p_new_nd->add_child(p_r, right_b_it, right_e_it,
this);
455 p_l->m_p_parent = p_new_nd;
456 p_r->m_p_parent = p_new_nd;
457 PB_DS_ASSERT_NODE_VALID(p_new_nd)
464update_min_max_for_inserted_leaf(leaf_pointer p_new_lf)
466 if (m_p_head->m_p_min == m_p_head ||
467 synth_access_traits::cmp_keys(PB_DS_V2F(p_new_lf->value()),
468 PB_DS_V2F(
static_cast<leaf_const_pointer
>(m_p_head->m_p_min)->value())))
469 m_p_head->m_p_min = p_new_lf;
471 if (m_p_head->m_p_max == m_p_head ||
472 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())))
473 m_p_head->m_p_max = p_new_lf;
ISO C++ entities toplevel namespace is std.
Struct holding two objects of arbitrary type.