3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the terms
8 // of the GNU General Public License as published by the Free Software
9 // Foundation; either version 3, or (at your option) any later
12 // This library is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
28 // Permission to use, copy, modify, sell, and distribute this software
29 // is hereby granted without fee, provided that the above copyright
30 // notice appears in all copies, and that both that copyright notice
31 // and this permission notice appear in supporting documentation. None
32 // of the above authors, nor IBM Haifa Research Laboratories, make any
33 // representation about the suitability of this software for any
34 // purpose. It is provided "as is" without express or implied
38 * @file constructors_destructor_fn_imps.hpp
39 * Contains an implementation class for bin_search_tree_.
43 typename PB_DS_CLASS_C_DEC::head_allocator
44 PB_DS_CLASS_C_DEC::s_head_allocator;
47 typename PB_DS_CLASS_C_DEC::internal_node_allocator
48 PB_DS_CLASS_C_DEC::s_internal_node_allocator;
51 typename PB_DS_CLASS_C_DEC::leaf_allocator
52 PB_DS_CLASS_C_DEC::s_leaf_allocator;
57 m_p_head(s_head_allocator.allocate(1)),
61 _GLIBCXX_DEBUG_ONLY(assert_valid();)
66 PB_DS_CLASS_NAME(const e_access_traits& r_e_access_traits) :
67 synth_e_access_traits(r_e_access_traits),
68 m_p_head(s_head_allocator.allocate(1)),
72 _GLIBCXX_DEBUG_ONLY(assert_valid();)
77 PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) :
81 synth_e_access_traits(other),
83 m_p_head(s_head_allocator.allocate(1)),
87 m_size = other.m_size;
88 _GLIBCXX_DEBUG_ONLY(other.assert_valid();)
89 if (other.m_p_head->m_p_parent == 0)
91 _GLIBCXX_DEBUG_ONLY(assert_valid();)
96 m_p_head->m_p_parent = recursive_copy_node(other.m_p_head->m_p_parent);
100 s_head_allocator.deallocate(m_p_head, 1);
101 __throw_exception_again;
104 m_p_head->m_p_min = leftmost_descendant(m_p_head->m_p_parent);
105 m_p_head->m_p_max = rightmost_descendant(m_p_head->m_p_parent);
106 m_p_head->m_p_parent->m_p_parent = m_p_head;
107 _GLIBCXX_DEBUG_ONLY(assert_valid();)
113 swap(PB_DS_CLASS_C_DEC& other)
115 _GLIBCXX_DEBUG_ONLY(assert_valid();)
116 _GLIBCXX_DEBUG_ONLY(other.assert_valid();)
118 std::swap((e_access_traits& )(*this), (e_access_traits& )other);
119 _GLIBCXX_DEBUG_ONLY(assert_valid();)
120 _GLIBCXX_DEBUG_ONLY(other.assert_valid();)
126 value_swap(PB_DS_CLASS_C_DEC& other)
128 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other);)
129 std::swap(m_p_head, other.m_p_head);
130 std::swap(m_size, other.m_size);
138 s_head_allocator.deallocate(m_p_head, 1);
146 new (m_p_head) head();
147 m_p_head->m_p_parent = 0;
148 m_p_head->m_p_min = m_p_head;
149 m_p_head->m_p_max = m_p_head;
154 template<typename It>
157 copy_from_range(It first_it, It last_it)
159 while (first_it != last_it)
160 insert(*(first_it++));
164 typename PB_DS_CLASS_C_DEC::node_pointer
166 recursive_copy_node(const_node_pointer p_other_nd)
168 _GLIBCXX_DEBUG_ASSERT(p_other_nd != 0);
169 if (p_other_nd->m_type == pat_trie_leaf_node_type)
171 const_leaf_pointer p_other_leaf = static_cast<const_leaf_pointer>(p_other_nd);
173 leaf_pointer p_new_lf = s_leaf_allocator.allocate(1);
174 cond_dealtor cond(p_new_lf);
175 new (p_new_lf) leaf(p_other_leaf->value());
176 apply_update(p_new_lf, (node_update* )this);
177 cond.set_no_action_dtor();
181 _GLIBCXX_DEBUG_ASSERT(p_other_nd->m_type == pat_trie_internal_node_type);
182 node_pointer a_p_children[internal_node::arr_size];
183 size_type child_i = 0;
184 const_internal_node_pointer p_other_internal_nd =
185 static_cast<const_internal_node_pointer>(p_other_nd);
187 typename internal_node::const_iterator child_it =
188 p_other_internal_nd->begin();
190 internal_node_pointer p_ret;
193 while (child_it != p_other_internal_nd->end())
194 a_p_children[child_i++] = recursive_copy_node(*(child_it++));
195 p_ret = s_internal_node_allocator.allocate(1);
199 while (child_i-- > 0)
200 clear_imp(a_p_children[child_i]);
201 __throw_exception_again;
204 new (p_ret) internal_node(p_other_internal_nd->get_e_ind(),
205 pref_begin(a_p_children[0]));
208 _GLIBCXX_DEBUG_ASSERT(child_i >= 1);
210 p_ret->add_child(a_p_children[child_i], pref_begin(a_p_children[child_i]),
211 pref_end(a_p_children[child_i]), this);
212 while (child_i-- > 0);
213 apply_update(p_ret, (node_update* )this);