3 // Copyright (C) 2005, 2006 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 2, 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 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
43 * @file constructors_destructor_fn_imps.hpp
44 * Contains an implementation class for bin_search_tree_.
48 typename
PB_DS_CLASS_C_DEC::head_allocator
49 PB_DS_CLASS_C_DEC::s_head_allocator
;
52 typename
PB_DS_CLASS_C_DEC::internal_node_allocator
53 PB_DS_CLASS_C_DEC::s_internal_node_allocator
;
56 typename
PB_DS_CLASS_C_DEC::leaf_allocator
57 PB_DS_CLASS_C_DEC::s_leaf_allocator
;
62 m_p_head(s_head_allocator
.allocate(1)),
66 _GLIBCXX_DEBUG_ONLY(assert_valid();)
71 PB_DS_CLASS_NAME(const e_access_traits
& r_e_access_traits
) :
72 synth_e_access_traits(r_e_access_traits
),
73 m_p_head(s_head_allocator
.allocate(1)),
77 _GLIBCXX_DEBUG_ONLY(assert_valid();)
82 PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC
& other
) :
86 synth_e_access_traits(other
),
88 m_p_head(s_head_allocator
.allocate(1)),
92 m_size
= other
.m_size
;
93 _GLIBCXX_DEBUG_ONLY(other
.assert_valid();)
94 if (other
.m_p_head
->m_p_parent
== NULL
)
96 _GLIBCXX_DEBUG_ONLY(assert_valid();)
101 m_p_head
->m_p_parent
= recursive_copy_node(other
.m_p_head
->m_p_parent
);
105 s_head_allocator
.deallocate(m_p_head
, 1);
106 __throw_exception_again
;
109 m_p_head
->m_p_min
= leftmost_descendant(m_p_head
->m_p_parent
);
110 m_p_head
->m_p_max
= rightmost_descendant(m_p_head
->m_p_parent
);
111 m_p_head
->m_p_parent
->m_p_parent
= m_p_head
;
112 _GLIBCXX_DEBUG_ONLY(assert_valid();)
118 swap(PB_DS_CLASS_C_DEC
& other
)
120 _GLIBCXX_DEBUG_ONLY(assert_valid();)
121 _GLIBCXX_DEBUG_ONLY(other
.assert_valid();)
123 std::swap((e_access_traits
& )(*this), (e_access_traits
& )other
);
124 _GLIBCXX_DEBUG_ONLY(assert_valid();)
125 _GLIBCXX_DEBUG_ONLY(other
.assert_valid();)
131 value_swap(PB_DS_CLASS_C_DEC
& other
)
133 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other
);)
134 std::swap(m_p_head
, other
.m_p_head
);
135 std::swap(m_size
, other
.m_size
);
143 s_head_allocator
.deallocate(m_p_head
, 1);
151 new (m_p_head
) head();
152 m_p_head
->m_p_parent
= NULL
;
153 m_p_head
->m_p_min
= m_p_head
;
154 m_p_head
->m_p_max
= m_p_head
;
159 template<typename It
>
162 copy_from_range(It first_it
, It last_it
)
164 while (first_it
!= last_it
)
165 insert(*(first_it
++));
169 typename
PB_DS_CLASS_C_DEC::node_pointer
171 recursive_copy_node(const_node_pointer p_other_nd
)
173 _GLIBCXX_DEBUG_ASSERT(p_other_nd
!= NULL
);
174 if (p_other_nd
->m_type
== pat_trie_leaf_node_type
)
176 const_leaf_pointer p_other_leaf
= static_cast<const_leaf_pointer
>(p_other_nd
);
178 leaf_pointer p_new_lf
= s_leaf_allocator
.allocate(1);
179 cond_dealtor
cond(p_new_lf
);
180 new (p_new_lf
) leaf(p_other_leaf
->value());
181 apply_update(p_new_lf
, (node_update
* )this);
182 cond
.set_no_action_dtor();
186 _GLIBCXX_DEBUG_ASSERT(p_other_nd
->m_type
== pat_trie_internal_node_type
);
187 node_pointer a_p_children
[internal_node::arr_size
];
188 size_type child_i
= 0;
189 const_internal_node_pointer p_other_internal_nd
=
190 static_cast<const_internal_node_pointer
>(p_other_nd
);
192 typename
internal_node::const_iterator child_it
=
193 p_other_internal_nd
->begin();
195 internal_node_pointer p_ret
;
198 while (child_it
!= p_other_internal_nd
->end())
199 a_p_children
[child_i
++] = recursive_copy_node(*(child_it
++));
200 p_ret
= s_internal_node_allocator
.allocate(1);
204 while (child_i
-- > 0)
205 clear_imp(a_p_children
[child_i
]);
206 __throw_exception_again
;
209 new (p_ret
) internal_node(p_other_internal_nd
->get_e_ind(),
210 pref_begin(a_p_children
[0]));
213 _GLIBCXX_DEBUG_ASSERT(child_i
> 1);
215 p_ret
->add_child(a_p_children
[child_i
], pref_begin(a_p_children
[child_i
]),
216 pref_end(a_p_children
[child_i
]), this);
217 while (child_i
-- > 0);
218 apply_update(p_ret
, (node_update
* )this);