44 split(key_const_reference r_key, PB_DS_CLASS_C_DEC& other)
46 PB_DS_ASSERT_VALID((*
this))
47 PB_DS_ASSERT_VALID(other)
49 leaf_pointer p_split_lf = split_prep(r_key, other, bag);
52 _GLIBCXX_DEBUG_ASSERT(bag.empty());
53 PB_DS_ASSERT_VALID((*
this))
54 PB_DS_ASSERT_VALID(other)
58 _GLIBCXX_DEBUG_ASSERT(!bag.empty());
61 m_p_head->m_p_parent = rec_split(m_p_head->m_p_parent, pref_begin(p_split_lf),
62 pref_end(p_split_lf), other, bag);
64 m_p_head->m_p_parent->m_p_parent = m_p_head;
66 head_pointer __ohead = other.m_p_head;
67 __ohead->m_p_max = m_p_head->m_p_max;
68 m_p_head->m_p_max = rightmost_descendant(m_p_head->m_p_parent);
69 __ohead->m_p_min = other.leftmost_descendant(__ohead->m_p_parent);
72 other.PB_DS_CLASS_C_DEC::
end());
73 m_size -= other.m_size;
74 PB_DS_ASSERT_VALID((*this))
75 PB_DS_ASSERT_VALID(other)
79 typename PB_DS_CLASS_C_DEC::leaf_pointer
81 split_prep(key_const_reference r_key, PB_DS_CLASS_C_DEC& other,
84 _GLIBCXX_DEBUG_ASSERT(r_bag.empty());
88 PB_DS_ASSERT_VALID((*
this))
89 PB_DS_ASSERT_VALID(other)
93 if (synth_access_traits::cmp_keys(r_key,
94 PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_min)->value())))
98 PB_DS_ASSERT_VALID((*
this))
99 PB_DS_ASSERT_VALID(other)
103 if (!synth_access_traits::cmp_keys(r_key,
104 PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_max)->value())))
106 PB_DS_ASSERT_VALID((*
this))
107 PB_DS_ASSERT_VALID(other)
111 iterator it = lower_bound(r_key);
113 if (!synth_access_traits::equal_keys(PB_DS_V2F(*it), r_key))
116 node_pointer p_nd = it.m_p_nd;
117 _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == leaf_node);
118 leaf_pointer p_ret_l = static_cast<leaf_pointer>(p_nd);
119 while (p_nd->m_type != head_node)
122 p_nd = p_nd->m_p_parent;
124 _GLIBCXX_DEBUG_ONLY(debug_base::split(r_key,(synth_access_traits&)(*
this), other);)
130 typename PB_DS_CLASS_C_DEC::node_pointer
132 rec_split(node_pointer p_nd, a_const_iterator b_it, a_const_iterator e_it,
133 PB_DS_CLASS_C_DEC& other, branch_bag& r_bag)
135 if (p_nd->m_type == leaf_node)
137 _GLIBCXX_DEBUG_ASSERT(other.m_p_head->m_p_parent == 0);
141 _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == i_node);
142 inode_pointer p_ind =
static_cast<inode_pointer
>(p_nd);
144 node_pointer pfirst = p_ind->get_child_node(b_it, e_it,
this);
145 node_pointer p_child_ret = rec_split(pfirst, b_it, e_it, other, r_bag);
146 PB_DS_ASSERT_NODE_VALID(p_child_ret)
147 p_ind->replace_child(p_child_ret, b_it, e_it, this);
148 apply_update(p_ind, (node_update*)this);
150 inode_iterator child_it = p_ind->get_child_it(b_it, e_it, this);
151 const size_type lhs_dist =
std::
distance(p_ind->begin(), child_it);
152 const size_type lhs_num_children = lhs_dist + 1;
153 _GLIBCXX_DEBUG_ASSERT(lhs_num_children > 0);
155 const size_type rhs_dist =
std::
distance(p_ind->begin(), p_ind->end());
156 size_type rhs_num_children = rhs_dist - lhs_num_children;
157 if (rhs_num_children == 0)
159 apply_update(p_ind, (node_update*)
this);
163 other.split_insert_branch(p_ind->get_e_ind(), b_it, child_it,
164 rhs_num_children, r_bag);
166 child_it = p_ind->get_child_it(b_it, e_it,
this);
167 while (rhs_num_children != 0)
170 p_ind->remove_child(child_it);
173 apply_update(p_ind, (node_update*)
this);
175 const size_type int_dist =
std::distance(p_ind->begin(), p_ind->end());
176 _GLIBCXX_DEBUG_ASSERT(int_dist >= 1);
179 p_ind->update_prefixes(
this);
180 PB_DS_ASSERT_NODE_VALID(p_ind)
181 apply_update(p_ind, (node_update*)this);
185 node_pointer p_ret = *p_ind->begin();
187 s_inode_allocator.deallocate(p_ind, 1);
188 apply_update(p_ret, (node_update*)this);
195 split_insert_branch(size_type e_ind, a_const_iterator b_it,
196 inode_iterator child_b_it,
197 size_type num_children, branch_bag& r_bag)
199 #ifdef _GLIBCXX_DEBUG
200 if (m_p_head->m_p_parent != 0)
201 PB_DS_ASSERT_NODE_VALID(m_p_head->m_p_parent)
204 const size_type start = m_p_head->m_p_parent == 0 ? 0 : 1;
205 const size_type total_num_children = start + num_children;
206 if (total_num_children == 0)
208 _GLIBCXX_DEBUG_ASSERT(m_p_head->m_p_parent == 0);
212 if (total_num_children == 1)
214 if (m_p_head->m_p_parent != 0)
216 PB_DS_ASSERT_NODE_VALID(m_p_head->m_p_parent)
220 _GLIBCXX_DEBUG_ASSERT(m_p_head->m_p_parent == 0);
222 m_p_head->m_p_parent = *child_b_it;
223 m_p_head->m_p_parent->m_p_parent = m_p_head;
224 apply_update(m_p_head->m_p_parent, (node_update*)this);
225 PB_DS_ASSERT_NODE_VALID(m_p_head->m_p_parent)
229 _GLIBCXX_DEBUG_ASSERT(total_num_children > 1);
230 inode_pointer p_new_root = r_bag.get_branch();
231 new (p_new_root) inode(e_ind, b_it);
232 size_type num_inserted = 0;
233 while (num_inserted++ < num_children)
236 PB_DS_ASSERT_NODE_VALID((*child_b_it))
237 p_new_root->add_child(*child_b_it, pref_begin(*child_b_it),
238 pref_end(*child_b_it), this);
241 if (m_p_head->m_p_parent != 0)
242 p_new_root->add_child(m_p_head->m_p_parent,
243 pref_begin(m_p_head->m_p_parent),
244 pref_end(m_p_head->m_p_parent), this);
246 m_p_head->m_p_parent = p_new_root;
247 p_new_root->m_p_parent = m_p_head;
248 apply_update(m_p_head->m_p_parent, (node_update*)this);
249 PB_DS_ASSERT_NODE_VALID(m_p_head->m_p_parent)
auto end(_Container &__cont) -> decltype(__cont.end())
Return an iterator pointing to one past the last element of the container.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
ISO C++ entities toplevel namespace is std.
auto begin(_Container &__cont) -> decltype(__cont.begin())
Return an iterator pointing to the first element of the container.