3 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
37 * @file constructors_destructor_fn_imps.hpp
38 * Contains an implementation class for bin_search_tree_.
42 typename
PB_DS_CLASS_C_DEC::head_allocator
43 PB_DS_CLASS_C_DEC::s_head_allocator
;
46 typename
PB_DS_CLASS_C_DEC::internal_node_allocator
47 PB_DS_CLASS_C_DEC::s_internal_node_allocator
;
50 typename
PB_DS_CLASS_C_DEC::leaf_allocator
51 PB_DS_CLASS_C_DEC::s_leaf_allocator
;
56 m_p_head(s_head_allocator
.allocate(1)),
60 _GLIBCXX_DEBUG_ONLY(assert_valid();)
65 PB_DS_CLASS_NAME(const e_access_traits
& r_e_access_traits
) :
66 synth_e_access_traits(r_e_access_traits
),
67 m_p_head(s_head_allocator
.allocate(1)),
71 _GLIBCXX_DEBUG_ONLY(assert_valid();)
76 PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC
& other
) :
80 synth_e_access_traits(other
),
82 m_p_head(s_head_allocator
.allocate(1)),
86 m_size
= other
.m_size
;
87 _GLIBCXX_DEBUG_ONLY(other
.assert_valid();)
88 if (other
.m_p_head
->m_p_parent
== NULL
)
90 _GLIBCXX_DEBUG_ONLY(assert_valid();)
95 m_p_head
->m_p_parent
= recursive_copy_node(other
.m_p_head
->m_p_parent
);
99 s_head_allocator
.deallocate(m_p_head
, 1);
100 __throw_exception_again
;
103 m_p_head
->m_p_min
= leftmost_descendant(m_p_head
->m_p_parent
);
104 m_p_head
->m_p_max
= rightmost_descendant(m_p_head
->m_p_parent
);
105 m_p_head
->m_p_parent
->m_p_parent
= m_p_head
;
106 _GLIBCXX_DEBUG_ONLY(assert_valid();)
112 swap(PB_DS_CLASS_C_DEC
& other
)
114 _GLIBCXX_DEBUG_ONLY(assert_valid();)
115 _GLIBCXX_DEBUG_ONLY(other
.assert_valid();)
117 std::swap((e_access_traits
& )(*this), (e_access_traits
& )other
);
118 _GLIBCXX_DEBUG_ONLY(assert_valid();)
119 _GLIBCXX_DEBUG_ONLY(other
.assert_valid();)
125 value_swap(PB_DS_CLASS_C_DEC
& other
)
127 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other
);)
128 std::swap(m_p_head
, other
.m_p_head
);
129 std::swap(m_size
, other
.m_size
);
137 s_head_allocator
.deallocate(m_p_head
, 1);
145 new (m_p_head
) head();
146 m_p_head
->m_p_parent
= NULL
;
147 m_p_head
->m_p_min
= m_p_head
;
148 m_p_head
->m_p_max
= m_p_head
;
153 template<typename It
>
156 copy_from_range(It first_it
, It last_it
)
158 while (first_it
!= last_it
)
159 insert(*(first_it
++));
163 typename
PB_DS_CLASS_C_DEC::node_pointer
165 recursive_copy_node(const_node_pointer p_other_nd
)
167 _GLIBCXX_DEBUG_ASSERT(p_other_nd
!= NULL
);
168 if (p_other_nd
->m_type
== pat_trie_leaf_node_type
)
170 const_leaf_pointer p_other_leaf
= static_cast<const_leaf_pointer
>(p_other_nd
);
172 leaf_pointer p_new_lf
= s_leaf_allocator
.allocate(1);
173 cond_dealtor
cond(p_new_lf
);
174 new (p_new_lf
) leaf(p_other_leaf
->value());
175 apply_update(p_new_lf
, (node_update
* )this);
176 cond
.set_no_action_dtor();
180 _GLIBCXX_DEBUG_ASSERT(p_other_nd
->m_type
== pat_trie_internal_node_type
);
181 node_pointer a_p_children
[internal_node::arr_size
];
182 size_type child_i
= 0;
183 const_internal_node_pointer p_other_internal_nd
=
184 static_cast<const_internal_node_pointer
>(p_other_nd
);
186 typename
internal_node::const_iterator child_it
=
187 p_other_internal_nd
->begin();
189 internal_node_pointer p_ret
;
192 while (child_it
!= p_other_internal_nd
->end())
193 a_p_children
[child_i
++] = recursive_copy_node(*(child_it
++));
194 p_ret
= s_internal_node_allocator
.allocate(1);
198 while (child_i
-- > 0)
199 clear_imp(a_p_children
[child_i
]);
200 __throw_exception_again
;
203 new (p_ret
) internal_node(p_other_internal_nd
->get_e_ind(),
204 pref_begin(a_p_children
[0]));
207 _GLIBCXX_DEBUG_ASSERT(child_i
> 1);
209 p_ret
->add_child(a_p_children
[child_i
], pref_begin(a_p_children
[child_i
]),
210 pref_end(a_p_children
[child_i
]), this);
211 while (child_i
-- > 0);
212 apply_update(p_ret
, (node_update
* )this);