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 ov_tree_.
48 typename
PB_DS_CLASS_C_DEC::value_allocator
49 PB_DS_CLASS_C_DEC::s_value_alloc
;
52 typename
PB_DS_CLASS_C_DEC::metadata_allocator
53 PB_DS_CLASS_C_DEC::s_metadata_alloc
;
57 PB_DS_OV_TREE_CLASS_NAME() :
62 { _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) }
66 PB_DS_OV_TREE_CLASS_NAME(const Cmp_Fn
& r_cmp_fn
) :
67 cmp_fn_base(r_cmp_fn
),
72 { _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) }
76 PB_DS_OV_TREE_CLASS_NAME(const Cmp_Fn
& r_cmp_fn
, const node_update
& r_node_update
) :
77 cmp_fn_base(r_cmp_fn
),
78 node_update(r_node_update
),
83 { _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();) }
87 PB_DS_OV_TREE_CLASS_NAME(const PB_DS_CLASS_C_DEC
& other
) :
91 #ifdef PB_DS_TREE_TRACE
92 PB_DS_TREE_TRACE_BASE_C_DEC(other
),
101 copy_from_ordered_range(other
.begin(), other
.end());
102 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
106 template<typename It
>
109 copy_from_range(It first_it
, It last_it
)
111 #ifdef PB_DS_DATA_TRUE_INDICATOR
117 typename
Allocator::template rebind
<
125 typename
Allocator::template rebind
<
130 map_type
m(first_it
, last_it
);
131 copy_from_ordered_range(m
.begin(), m
.end());
135 template<typename It
>
138 copy_from_ordered_range(It first_it
, It last_it
)
140 const size_type len
= std::distance(first_it
, last_it
);
144 value_vector a_values
= s_value_alloc
.allocate(len
);
145 iterator target_it
= a_values
;
146 It source_it
= first_it
;
147 It source_end_it
= last_it
;
149 cond_dtor
<size_type
> cd(a_values
, target_it
, len
);
150 while (source_it
!= source_end_it
)
152 new (const_cast<void* >(static_cast<const void* >(target_it
)))
153 value_type(*source_it
++);
158 reallocate_metadata((node_update
* )this, len
);
160 m_a_values
= a_values
;
162 m_end_it
= m_a_values
+ m_size
;
163 update(PB_DS_node_begin_imp(), (node_update
* )this);
165 #ifdef _GLIBCXX_DEBUG
166 const_iterator dbg_it
= m_a_values
;
167 while (dbg_it
!= m_end_it
)
169 debug_base::insert_new(PB_DS_V2F(*dbg_it
));
172 PB_DS_CLASS_C_DEC::assert_valid();
177 template<typename It
>
180 copy_from_ordered_range(It first_it
, It last_it
, It other_first_it
,
184 const size_type len
= std::distance(first_it
, last_it
)
185 + std::distance(other_first_it
, other_last_it
);
187 value_vector a_values
= s_value_alloc
.allocate(len
);
189 iterator target_it
= a_values
;
190 It source_it
= first_it
;
191 It source_end_it
= last_it
;
193 cond_dtor
<size_type
> cd(a_values
, target_it
, len
);
194 while (source_it
!= source_end_it
)
196 new (const_cast<void* >(static_cast<const void* >(target_it
)))
197 value_type(*source_it
++);
201 source_it
= other_first_it
;
202 source_end_it
= other_last_it
;
204 while (source_it
!= source_end_it
)
206 new (const_cast<void* >(static_cast<const void* >(target_it
)))
207 value_type(*source_it
++);
211 reallocate_metadata((node_update
* )this, len
);
213 m_a_values
= a_values
;
215 m_end_it
= m_a_values
+ m_size
;
216 update(PB_DS_node_begin_imp(), (node_update
* )this);
218 #ifdef _GLIBCXX_DEBUG
219 const_iterator dbg_it
= m_a_values
;
220 while (dbg_it
!= m_end_it
)
222 debug_base::insert_new(PB_DS_V2F(*dbg_it
));
225 PB_DS_CLASS_C_DEC::assert_valid();
232 swap(PB_DS_CLASS_C_DEC
& other
)
234 _GLIBCXX_DEBUG_ONLY(assert_valid();)
236 std::swap((Cmp_Fn
& )(*this), (Cmp_Fn
& )other
);
237 _GLIBCXX_DEBUG_ONLY(assert_valid();)
243 value_swap(PB_DS_CLASS_C_DEC
& other
)
245 std::swap(m_a_values
, other
.m_a_values
);
246 std::swap(m_a_metadata
, other
.m_a_metadata
);
247 std::swap(m_size
, other
.m_size
);
248 std::swap(m_end_it
, other
.m_end_it
);
249 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other
);)
254 ~PB_DS_OV_TREE_CLASS_NAME()
256 _GLIBCXX_DEBUG_ONLY(assert_valid();)
257 cond_dtor
<size_type
> cd(m_a_values
, m_end_it
, m_size
);
258 reallocate_metadata((node_update
* )this, 0);
264 update(node_iterator
/*it*/, null_node_update_pointer
)
268 template<typename Node_Update
>
271 update(node_iterator nd_it
, Node_Update
* p_update
)
273 const_node_iterator end_it
= PB_DS_node_end_imp();
276 update(nd_it
.get_l_child(), p_update
);
277 update(nd_it
.get_r_child(), p_update
);
278 node_update::operator()(nd_it
, end_it
);