Chris@16
|
1 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Ion Gaztanaga 2013-2013
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //
|
Chris@16
|
9 // See http://www.boost.org/libs/intrusive for documentation.
|
Chris@16
|
10 //
|
Chris@16
|
11 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
12 #ifndef BOOST_INTRUSIVE_BSTREE_HPP
|
Chris@16
|
13 #define BOOST_INTRUSIVE_BSTREE_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/intrusive/detail/config_begin.hpp>
|
Chris@16
|
16 #include <algorithm>
|
Chris@16
|
17 #include <cstddef>
|
Chris@16
|
18 #include <functional>
|
Chris@16
|
19 #include <iterator>
|
Chris@16
|
20 #include <utility>
|
Chris@16
|
21
|
Chris@16
|
22 #include <boost/intrusive/detail/assert.hpp>
|
Chris@16
|
23 #include <boost/static_assert.hpp>
|
Chris@16
|
24 #include <boost/intrusive/intrusive_fwd.hpp>
|
Chris@16
|
25 #include <boost/intrusive/set_hook.hpp>
|
Chris@16
|
26 #include <boost/intrusive/detail/tree_node.hpp>
|
Chris@16
|
27 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
|
Chris@16
|
28 #include <boost/intrusive/detail/mpl.hpp>
|
Chris@16
|
29 #include <boost/intrusive/pointer_traits.hpp>
|
Chris@16
|
30 #include <boost/intrusive/detail/clear_on_destructor_base.hpp>
|
Chris@16
|
31 #include <boost/intrusive/detail/function_detector.hpp>
|
Chris@16
|
32 #include <boost/intrusive/detail/utilities.hpp>
|
Chris@16
|
33 #include <boost/intrusive/options.hpp>
|
Chris@16
|
34 #include <boost/intrusive/bstree_algorithms.hpp>
|
Chris@16
|
35 #include <boost/intrusive/link_mode.hpp>
|
Chris@16
|
36 #include <boost/move/move.hpp>
|
Chris@16
|
37
|
Chris@16
|
38 namespace boost {
|
Chris@16
|
39 namespace intrusive {
|
Chris@16
|
40
|
Chris@16
|
41 /// @cond
|
Chris@16
|
42
|
Chris@16
|
43 struct bstree_defaults
|
Chris@16
|
44 {
|
Chris@16
|
45 typedef detail::default_bstree_hook proto_value_traits;
|
Chris@16
|
46 static const bool constant_time_size = true;
|
Chris@16
|
47 typedef std::size_t size_type;
|
Chris@16
|
48 typedef void compare;
|
Chris@16
|
49 static const bool floating_point = true; //For sgtree
|
Chris@16
|
50 typedef void priority; //For treap
|
Chris@16
|
51 };
|
Chris@16
|
52
|
Chris@16
|
53 template<class ValueTraits, algo_types AlgoType>
|
Chris@16
|
54 struct bstbase3
|
Chris@16
|
55 : public detail::get_real_value_traits<ValueTraits>::type::node_traits::node
|
Chris@16
|
56 , public ValueTraits
|
Chris@16
|
57 {
|
Chris@16
|
58 typedef ValueTraits value_traits;
|
Chris@16
|
59 typedef typename detail::get_real_value_traits<ValueTraits>::type real_value_traits;
|
Chris@16
|
60 typedef typename real_value_traits::node_traits node_traits;
|
Chris@16
|
61 typedef typename node_traits::node node_type;
|
Chris@16
|
62 typedef typename get_algo<AlgoType, node_traits>::type node_algorithms;
|
Chris@16
|
63 typedef typename node_traits::node_ptr node_ptr;
|
Chris@16
|
64 typedef typename node_traits::const_node_ptr const_node_ptr;
|
Chris@16
|
65
|
Chris@16
|
66 bstbase3(const ValueTraits &vtraits)
|
Chris@16
|
67 : ValueTraits(vtraits)
|
Chris@16
|
68 {}
|
Chris@16
|
69
|
Chris@16
|
70 static const bool external_value_traits =
|
Chris@16
|
71 detail::external_value_traits_bool_is_true<ValueTraits>::value;
|
Chris@16
|
72
|
Chris@16
|
73 node_ptr header_ptr()
|
Chris@16
|
74 { return pointer_traits<node_ptr>::pointer_to(static_cast<node_type&>(*this)); }
|
Chris@16
|
75
|
Chris@16
|
76 const_node_ptr header_ptr() const
|
Chris@16
|
77 { return pointer_traits<const_node_ptr>::pointer_to(static_cast<const node_type&>(*this)); }
|
Chris@16
|
78
|
Chris@16
|
79 const value_traits &val_traits() const
|
Chris@16
|
80 { return *this; }
|
Chris@16
|
81
|
Chris@16
|
82 value_traits &val_traits()
|
Chris@16
|
83 { return *this; }
|
Chris@16
|
84
|
Chris@16
|
85 const real_value_traits &get_real_value_traits(detail::bool_<false>) const
|
Chris@16
|
86 { return *this; }
|
Chris@16
|
87
|
Chris@16
|
88 const real_value_traits &get_real_value_traits(detail::bool_<true>) const
|
Chris@16
|
89 { return this->val_traits().get_value_traits(*this); }
|
Chris@16
|
90
|
Chris@16
|
91 real_value_traits &get_real_value_traits(detail::bool_<false>)
|
Chris@16
|
92 { return *this; }
|
Chris@16
|
93
|
Chris@16
|
94 real_value_traits &get_real_value_traits(detail::bool_<true>)
|
Chris@16
|
95 { return this->val_traits().get_value_traits(*this); }
|
Chris@16
|
96
|
Chris@16
|
97 const real_value_traits &get_real_value_traits() const
|
Chris@16
|
98 { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
|
Chris@16
|
99
|
Chris@16
|
100 real_value_traits &get_real_value_traits()
|
Chris@16
|
101 { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
|
Chris@16
|
102
|
Chris@16
|
103 typedef typename pointer_traits<node_ptr>::template rebind_pointer<const real_value_traits>::type const_real_value_traits_ptr;
|
Chris@16
|
104
|
Chris@16
|
105 const_real_value_traits_ptr real_value_traits_ptr() const
|
Chris@16
|
106 { return pointer_traits<const_real_value_traits_ptr>::pointer_to(this->get_real_value_traits()); }
|
Chris@16
|
107
|
Chris@16
|
108
|
Chris@16
|
109 typedef tree_iterator<real_value_traits, false> iterator;
|
Chris@16
|
110 typedef tree_iterator<real_value_traits, true> const_iterator;
|
Chris@16
|
111 typedef boost::intrusive::detail::reverse_iterator<iterator> reverse_iterator;
|
Chris@16
|
112 typedef boost::intrusive::detail::reverse_iterator<const_iterator> const_reverse_iterator;
|
Chris@16
|
113 typedef BOOST_INTRUSIVE_IMPDEF(typename real_value_traits::pointer) pointer;
|
Chris@16
|
114 typedef BOOST_INTRUSIVE_IMPDEF(typename real_value_traits::const_pointer) const_pointer;
|
Chris@16
|
115 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::element_type) value_type;
|
Chris@16
|
116 typedef BOOST_INTRUSIVE_IMPDEF(value_type) key_type;
|
Chris@16
|
117 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference;
|
Chris@16
|
118 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference;
|
Chris@16
|
119 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type;
|
Chris@16
|
120 static const bool safemode_or_autounlink = is_safe_autounlink<real_value_traits::link_mode>::value;
|
Chris@16
|
121 static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value;
|
Chris@16
|
122
|
Chris@16
|
123 iterator begin()
|
Chris@16
|
124 { return iterator (node_traits::get_left(this->header_ptr()), this->real_value_traits_ptr()); }
|
Chris@16
|
125
|
Chris@16
|
126 const_iterator begin() const
|
Chris@16
|
127 { return cbegin(); }
|
Chris@16
|
128
|
Chris@16
|
129 const_iterator cbegin() const
|
Chris@16
|
130 { return const_iterator (node_traits::get_left(this->header_ptr()), this->real_value_traits_ptr()); }
|
Chris@16
|
131
|
Chris@16
|
132 iterator end()
|
Chris@16
|
133 { return iterator (this->header_ptr(), this->real_value_traits_ptr()); }
|
Chris@16
|
134
|
Chris@16
|
135 const_iterator end() const
|
Chris@16
|
136 { return cend(); }
|
Chris@16
|
137
|
Chris@16
|
138 const_iterator cend() const
|
Chris@16
|
139 { return const_iterator (detail::uncast(this->header_ptr()), this->real_value_traits_ptr()); }
|
Chris@16
|
140
|
Chris@16
|
141 reverse_iterator rbegin()
|
Chris@16
|
142 { return reverse_iterator(end()); }
|
Chris@16
|
143
|
Chris@16
|
144 const_reverse_iterator rbegin() const
|
Chris@16
|
145 { return const_reverse_iterator(end()); }
|
Chris@16
|
146
|
Chris@16
|
147 const_reverse_iterator crbegin() const
|
Chris@16
|
148 { return const_reverse_iterator(end()); }
|
Chris@16
|
149
|
Chris@16
|
150 reverse_iterator rend()
|
Chris@16
|
151 { return reverse_iterator(begin()); }
|
Chris@16
|
152
|
Chris@16
|
153 const_reverse_iterator rend() const
|
Chris@16
|
154 { return const_reverse_iterator(begin()); }
|
Chris@16
|
155
|
Chris@16
|
156 const_reverse_iterator crend() const
|
Chris@16
|
157 { return const_reverse_iterator(begin()); }
|
Chris@16
|
158
|
Chris@16
|
159 void replace_node(iterator replace_this, reference with_this)
|
Chris@16
|
160 {
|
Chris@16
|
161 node_algorithms::replace_node( get_real_value_traits().to_node_ptr(*replace_this)
|
Chris@16
|
162 , this->header_ptr()
|
Chris@16
|
163 , get_real_value_traits().to_node_ptr(with_this));
|
Chris@16
|
164 if(safemode_or_autounlink)
|
Chris@16
|
165 node_algorithms::init(replace_this.pointed_node());
|
Chris@16
|
166 }
|
Chris@16
|
167
|
Chris@16
|
168 void rebalance()
|
Chris@16
|
169 { node_algorithms::rebalance(this->header_ptr()); }
|
Chris@16
|
170
|
Chris@16
|
171 iterator rebalance_subtree(iterator root)
|
Chris@16
|
172 { return iterator(node_algorithms::rebalance_subtree(root.pointed_node()), this->real_value_traits_ptr()); }
|
Chris@16
|
173
|
Chris@16
|
174 static iterator s_iterator_to(reference value)
|
Chris@16
|
175 {
|
Chris@16
|
176 BOOST_STATIC_ASSERT((!stateful_value_traits));
|
Chris@16
|
177 return iterator (value_traits::to_node_ptr(value), const_real_value_traits_ptr());
|
Chris@16
|
178 }
|
Chris@16
|
179
|
Chris@16
|
180 static const_iterator s_iterator_to(const_reference value)
|
Chris@16
|
181 {
|
Chris@16
|
182 BOOST_STATIC_ASSERT((!stateful_value_traits));
|
Chris@16
|
183 return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), const_real_value_traits_ptr());
|
Chris@16
|
184 }
|
Chris@16
|
185
|
Chris@16
|
186 iterator iterator_to(reference value)
|
Chris@16
|
187 { return iterator (value_traits::to_node_ptr(value), this->real_value_traits_ptr()); }
|
Chris@16
|
188
|
Chris@16
|
189 const_iterator iterator_to(const_reference value) const
|
Chris@16
|
190 { return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this->real_value_traits_ptr()); }
|
Chris@16
|
191
|
Chris@16
|
192 static void init_node(reference value)
|
Chris@16
|
193 { node_algorithms::init(value_traits::to_node_ptr(value)); }
|
Chris@16
|
194
|
Chris@16
|
195 };
|
Chris@16
|
196
|
Chris@16
|
197 template<class ValueTraits, class VoidOrKeyComp, algo_types AlgoType>
|
Chris@16
|
198 struct bstbase2
|
Chris@16
|
199 : public bstbase3<ValueTraits, AlgoType>
|
Chris@16
|
200 , public detail::ebo_functor_holder<typename get_less< VoidOrKeyComp
|
Chris@16
|
201 , typename detail::get_real_value_traits<ValueTraits>::type::value_type
|
Chris@16
|
202 >::type>
|
Chris@16
|
203 {
|
Chris@16
|
204 typedef bstbase3<ValueTraits, AlgoType> treeheader_t;
|
Chris@16
|
205 typedef typename treeheader_t::real_value_traits real_value_traits;
|
Chris@16
|
206 typedef typename treeheader_t::node_algorithms node_algorithms;
|
Chris@16
|
207 typedef typename get_less
|
Chris@16
|
208 < VoidOrKeyComp, typename real_value_traits::value_type>::type value_compare;
|
Chris@16
|
209 typedef BOOST_INTRUSIVE_IMPDEF(value_compare) key_compare;
|
Chris@16
|
210 typedef typename treeheader_t::iterator iterator;
|
Chris@16
|
211 typedef typename treeheader_t::const_iterator const_iterator;
|
Chris@16
|
212 typedef typename treeheader_t::node_ptr node_ptr;
|
Chris@16
|
213 typedef typename treeheader_t::const_node_ptr const_node_ptr;
|
Chris@16
|
214
|
Chris@16
|
215 bstbase2(const value_compare &comp, const ValueTraits &vtraits)
|
Chris@16
|
216 : treeheader_t(vtraits), detail::ebo_functor_holder<value_compare>(comp)
|
Chris@16
|
217 {}
|
Chris@16
|
218
|
Chris@16
|
219 const value_compare &comp() const
|
Chris@16
|
220 { return this->get(); }
|
Chris@16
|
221
|
Chris@16
|
222 value_compare &comp()
|
Chris@16
|
223 { return this->get(); }
|
Chris@16
|
224
|
Chris@16
|
225 typedef BOOST_INTRUSIVE_IMPDEF(typename real_value_traits::pointer) pointer;
|
Chris@16
|
226 typedef BOOST_INTRUSIVE_IMPDEF(typename real_value_traits::const_pointer) const_pointer;
|
Chris@16
|
227 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::element_type) value_type;
|
Chris@16
|
228 typedef BOOST_INTRUSIVE_IMPDEF(value_type) key_type;
|
Chris@16
|
229 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference;
|
Chris@16
|
230 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference;
|
Chris@16
|
231 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type;
|
Chris@16
|
232 typedef typename node_algorithms::insert_commit_data insert_commit_data;
|
Chris@16
|
233
|
Chris@16
|
234 value_compare value_comp() const
|
Chris@16
|
235 { return this->comp(); }
|
Chris@16
|
236
|
Chris@16
|
237 key_compare key_comp() const
|
Chris@16
|
238 { return this->comp(); }
|
Chris@16
|
239
|
Chris@16
|
240 iterator lower_bound(const_reference value)
|
Chris@16
|
241 { return this->lower_bound(value, this->comp()); }
|
Chris@16
|
242
|
Chris@16
|
243 const_iterator lower_bound(const_reference value) const
|
Chris@16
|
244 { return this->lower_bound(value, this->comp()); }
|
Chris@16
|
245
|
Chris@16
|
246 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
247 iterator lower_bound(const KeyType &key, KeyValueCompare comp)
|
Chris@16
|
248 {
|
Chris@16
|
249 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
250 key_node_comp(comp, &this->get_real_value_traits());
|
Chris@16
|
251 return iterator(node_algorithms::lower_bound
|
Chris@16
|
252 (this->header_ptr(), key, key_node_comp), this->real_value_traits_ptr());
|
Chris@16
|
253 }
|
Chris@16
|
254
|
Chris@16
|
255 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
256 const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const
|
Chris@16
|
257 {
|
Chris@16
|
258 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
259 key_node_comp(comp, &this->get_real_value_traits());
|
Chris@16
|
260 return const_iterator(node_algorithms::lower_bound
|
Chris@16
|
261 (this->header_ptr(), key, key_node_comp), this->real_value_traits_ptr());
|
Chris@16
|
262 }
|
Chris@16
|
263
|
Chris@16
|
264 iterator upper_bound(const_reference value)
|
Chris@16
|
265 { return this->upper_bound(value, this->comp()); }
|
Chris@16
|
266
|
Chris@16
|
267 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
268 iterator upper_bound(const KeyType &key, KeyValueCompare comp)
|
Chris@16
|
269 {
|
Chris@16
|
270 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
271 key_node_comp(comp, &this->get_real_value_traits());
|
Chris@16
|
272 return iterator(node_algorithms::upper_bound
|
Chris@16
|
273 (this->header_ptr(), key, key_node_comp), this->real_value_traits_ptr());
|
Chris@16
|
274 }
|
Chris@16
|
275
|
Chris@16
|
276 const_iterator upper_bound(const_reference value) const
|
Chris@16
|
277 { return this->upper_bound(value, this->comp()); }
|
Chris@16
|
278
|
Chris@16
|
279 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
280 const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const
|
Chris@16
|
281 {
|
Chris@16
|
282 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
283 key_node_comp(comp, &this->get_real_value_traits());
|
Chris@16
|
284 return const_iterator(node_algorithms::upper_bound
|
Chris@16
|
285 (this->header_ptr(), key, key_node_comp), this->real_value_traits_ptr());
|
Chris@16
|
286 }
|
Chris@16
|
287
|
Chris@16
|
288 iterator find(const_reference value)
|
Chris@16
|
289 { return this->find(value, this->comp()); }
|
Chris@16
|
290
|
Chris@16
|
291 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
292 iterator find(const KeyType &key, KeyValueCompare comp)
|
Chris@16
|
293 {
|
Chris@16
|
294 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
295 key_node_comp(comp, &this->get_real_value_traits());
|
Chris@16
|
296 return iterator
|
Chris@16
|
297 (node_algorithms::find(this->header_ptr(), key, key_node_comp), this->real_value_traits_ptr());
|
Chris@16
|
298 }
|
Chris@16
|
299
|
Chris@16
|
300 const_iterator find(const_reference value) const
|
Chris@16
|
301 { return this->find(value, this->comp()); }
|
Chris@16
|
302
|
Chris@16
|
303 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
304 const_iterator find(const KeyType &key, KeyValueCompare comp) const
|
Chris@16
|
305 {
|
Chris@16
|
306 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
307 key_node_comp(comp, &this->get_real_value_traits());
|
Chris@16
|
308 return const_iterator
|
Chris@16
|
309 (node_algorithms::find(this->header_ptr(), key, key_node_comp), this->real_value_traits_ptr());
|
Chris@16
|
310 }
|
Chris@16
|
311
|
Chris@16
|
312 std::pair<iterator,iterator> equal_range(const_reference value)
|
Chris@16
|
313 { return this->equal_range(value, this->comp()); }
|
Chris@16
|
314
|
Chris@16
|
315 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
316 std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp)
|
Chris@16
|
317 {
|
Chris@16
|
318 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
319 key_node_comp(comp, &this->get_real_value_traits());
|
Chris@16
|
320 std::pair<node_ptr, node_ptr> ret
|
Chris@16
|
321 (node_algorithms::equal_range(this->header_ptr(), key, key_node_comp));
|
Chris@16
|
322 return std::pair<iterator, iterator>( iterator(ret.first, this->real_value_traits_ptr())
|
Chris@16
|
323 , iterator(ret.second, this->real_value_traits_ptr()));
|
Chris@16
|
324 }
|
Chris@16
|
325
|
Chris@16
|
326 std::pair<const_iterator, const_iterator>
|
Chris@16
|
327 equal_range(const_reference value) const
|
Chris@16
|
328 { return this->equal_range(value, this->comp()); }
|
Chris@16
|
329
|
Chris@16
|
330 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
331 std::pair<const_iterator, const_iterator>
|
Chris@16
|
332 equal_range(const KeyType &key, KeyValueCompare comp) const
|
Chris@16
|
333 {
|
Chris@16
|
334 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
335 key_node_comp(comp, &this->get_real_value_traits());
|
Chris@16
|
336 std::pair<node_ptr, node_ptr> ret
|
Chris@16
|
337 (node_algorithms::equal_range(this->header_ptr(), key, key_node_comp));
|
Chris@16
|
338 return std::pair<const_iterator, const_iterator>( const_iterator(ret.first, this->real_value_traits_ptr())
|
Chris@16
|
339 , const_iterator(ret.second, this->real_value_traits_ptr()));
|
Chris@16
|
340 }
|
Chris@16
|
341
|
Chris@16
|
342 std::pair<iterator,iterator> bounded_range
|
Chris@16
|
343 (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed)
|
Chris@16
|
344 { return this->bounded_range(lower_value, upper_value, this->comp(), left_closed, right_closed); }
|
Chris@16
|
345
|
Chris@16
|
346 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
347 std::pair<iterator,iterator> bounded_range
|
Chris@16
|
348 (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed)
|
Chris@16
|
349 {
|
Chris@16
|
350 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
351 key_node_comp(comp, &this->get_real_value_traits());
|
Chris@16
|
352 std::pair<node_ptr, node_ptr> ret
|
Chris@16
|
353 (node_algorithms::bounded_range
|
Chris@16
|
354 (this->header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed));
|
Chris@16
|
355 return std::pair<iterator, iterator>( iterator(ret.first, this->real_value_traits_ptr())
|
Chris@16
|
356 , iterator(ret.second, this->real_value_traits_ptr()));
|
Chris@16
|
357 }
|
Chris@16
|
358
|
Chris@16
|
359 std::pair<const_iterator,const_iterator> bounded_range
|
Chris@16
|
360 (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const
|
Chris@16
|
361 { return this->bounded_range(lower_value, upper_value, this->comp(), left_closed, right_closed); }
|
Chris@16
|
362
|
Chris@16
|
363 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
364 std::pair<const_iterator,const_iterator> bounded_range
|
Chris@16
|
365 (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const
|
Chris@16
|
366 {
|
Chris@16
|
367 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
368 key_node_comp(comp, &this->get_real_value_traits());
|
Chris@16
|
369 std::pair<node_ptr, node_ptr> ret
|
Chris@16
|
370 (node_algorithms::bounded_range
|
Chris@16
|
371 (this->header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed));
|
Chris@16
|
372 return std::pair<const_iterator, const_iterator>( const_iterator(ret.first, this->real_value_traits_ptr())
|
Chris@16
|
373 , const_iterator(ret.second, this->real_value_traits_ptr()));
|
Chris@16
|
374 }
|
Chris@16
|
375
|
Chris@16
|
376 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
377 std::pair<iterator, bool> insert_unique_check
|
Chris@16
|
378 (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data)
|
Chris@16
|
379 {
|
Chris@16
|
380 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
381 ocomp(key_value_comp, &this->get_real_value_traits());
|
Chris@16
|
382 std::pair<node_ptr, bool> ret =
|
Chris@16
|
383 (node_algorithms::insert_unique_check
|
Chris@16
|
384 (this->header_ptr(), key, ocomp, commit_data));
|
Chris@16
|
385 return std::pair<iterator, bool>(iterator(ret.first, this->real_value_traits_ptr()), ret.second);
|
Chris@16
|
386 }
|
Chris@16
|
387
|
Chris@16
|
388 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
389 std::pair<iterator, bool> insert_unique_check
|
Chris@16
|
390 (const_iterator hint, const KeyType &key
|
Chris@16
|
391 ,KeyValueCompare key_value_comp, insert_commit_data &commit_data)
|
Chris@16
|
392 {
|
Chris@16
|
393 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
394 ocomp(key_value_comp, &this->get_real_value_traits());
|
Chris@16
|
395 std::pair<node_ptr, bool> ret =
|
Chris@16
|
396 (node_algorithms::insert_unique_check
|
Chris@16
|
397 (this->header_ptr(), hint.pointed_node(), key, ocomp, commit_data));
|
Chris@16
|
398 return std::pair<iterator, bool>(iterator(ret.first, this->real_value_traits_ptr()), ret.second);
|
Chris@16
|
399 }
|
Chris@16
|
400 };
|
Chris@16
|
401
|
Chris@16
|
402 template<class ValueTraits, class VoidOrKeyComp, bool ConstantTimeSize, class SizeType, algo_types AlgoType>
|
Chris@16
|
403 struct bstbase
|
Chris@16
|
404 : public detail::size_holder<ConstantTimeSize, SizeType>
|
Chris@16
|
405 , public bstbase2 < ValueTraits, VoidOrKeyComp, AlgoType>
|
Chris@16
|
406 {
|
Chris@16
|
407 typedef typename detail::get_real_value_traits<ValueTraits>::type real_value_traits;
|
Chris@16
|
408 typedef bstbase2< ValueTraits, VoidOrKeyComp, AlgoType> base_type;
|
Chris@16
|
409 typedef typename base_type::value_compare value_compare;
|
Chris@16
|
410 typedef BOOST_INTRUSIVE_IMPDEF(value_compare) key_compare;
|
Chris@16
|
411 typedef typename base_type::const_reference const_reference;
|
Chris@16
|
412 typedef typename base_type::reference reference;
|
Chris@16
|
413 typedef typename base_type::iterator iterator;
|
Chris@16
|
414 typedef typename base_type::const_iterator const_iterator;
|
Chris@16
|
415 typedef typename base_type::node_traits node_traits;
|
Chris@16
|
416 typedef typename get_algo
|
Chris@16
|
417 <AlgoType, node_traits>::type algo_type;
|
Chris@16
|
418 typedef SizeType size_type;
|
Chris@16
|
419
|
Chris@16
|
420 bstbase(const value_compare & comp, const ValueTraits &vtraits)
|
Chris@16
|
421 : base_type(comp, vtraits)
|
Chris@16
|
422 {}
|
Chris@16
|
423
|
Chris@16
|
424 public:
|
Chris@16
|
425 typedef detail::size_holder<ConstantTimeSize, SizeType> size_traits;
|
Chris@16
|
426
|
Chris@16
|
427 size_traits &sz_traits()
|
Chris@16
|
428 { return *this; }
|
Chris@16
|
429
|
Chris@16
|
430 const size_traits &sz_traits() const
|
Chris@16
|
431 { return *this; }
|
Chris@16
|
432
|
Chris@16
|
433 size_type count(const_reference value) const
|
Chris@16
|
434 { return size_type(this->count(value, this->comp())); }
|
Chris@16
|
435
|
Chris@16
|
436 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
437 size_type count(const KeyType &key, KeyValueCompare comp) const
|
Chris@16
|
438 {
|
Chris@16
|
439 std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp);
|
Chris@16
|
440 return size_type(std::distance(ret.first, ret.second));
|
Chris@16
|
441 }
|
Chris@16
|
442
|
Chris@16
|
443 bool empty() const
|
Chris@16
|
444 {
|
Chris@16
|
445 if(ConstantTimeSize){
|
Chris@16
|
446 return !this->sz_traits().get_size();
|
Chris@16
|
447 }
|
Chris@16
|
448 else{
|
Chris@16
|
449 return algo_type::unique(this->header_ptr());
|
Chris@16
|
450 }
|
Chris@16
|
451 }
|
Chris@16
|
452 };
|
Chris@16
|
453
|
Chris@16
|
454
|
Chris@16
|
455 /// @endcond
|
Chris@16
|
456
|
Chris@16
|
457 //! The class template bstree is an unbalanced intrusive binary search tree
|
Chris@16
|
458 //! container. The no-throw guarantee holds only, if the value_compare object
|
Chris@16
|
459 //! doesn't throw.
|
Chris@16
|
460 //!
|
Chris@16
|
461 //! The complexity guarantees only hold if the tree is balanced, logarithmic
|
Chris@16
|
462 //! complexity would increase to linear if the tree is totally unbalanced.
|
Chris@16
|
463 //!
|
Chris@16
|
464 //! The template parameter \c T is the type to be managed by the container.
|
Chris@16
|
465 //! The user can specify additional options and if no options are provided
|
Chris@16
|
466 //! default options are used.
|
Chris@16
|
467 //!
|
Chris@16
|
468 //! The container supports the following options:
|
Chris@16
|
469 //! \c base_hook<>/member_hook<>/value_traits<>,
|
Chris@16
|
470 //! \c constant_time_size<>, \c size_type<> and
|
Chris@16
|
471 //! \c compare<>.
|
Chris@16
|
472 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
473 template<class T, class ...Options>
|
Chris@16
|
474 #else
|
Chris@16
|
475 template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType>
|
Chris@16
|
476 #endif
|
Chris@16
|
477 class bstree_impl
|
Chris@16
|
478 : public bstbase<ValueTraits, VoidKeyComp, ConstantTimeSize, SizeType, AlgoType>
|
Chris@16
|
479 , private detail::clear_on_destructor_base
|
Chris@16
|
480 < bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType>
|
Chris@16
|
481 , is_safe_autounlink<detail::get_real_value_traits<ValueTraits>::type::link_mode>::value
|
Chris@16
|
482 >
|
Chris@16
|
483 {
|
Chris@16
|
484 template<class C, bool> friend class detail::clear_on_destructor_base;
|
Chris@16
|
485 public:
|
Chris@16
|
486 typedef ValueTraits value_traits;
|
Chris@16
|
487 /// @cond
|
Chris@16
|
488 static const bool external_value_traits =
|
Chris@16
|
489 detail::external_value_traits_bool_is_true<value_traits>::value;
|
Chris@16
|
490 typedef typename detail::get_real_value_traits<ValueTraits>::type real_value_traits;
|
Chris@16
|
491 typedef bstbase<value_traits, VoidKeyComp, ConstantTimeSize, SizeType, AlgoType> data_type;
|
Chris@16
|
492 typedef tree_iterator<real_value_traits, false> iterator_type;
|
Chris@16
|
493 typedef tree_iterator<real_value_traits, true> const_iterator_type;
|
Chris@16
|
494 /// @endcond
|
Chris@16
|
495
|
Chris@16
|
496 typedef BOOST_INTRUSIVE_IMPDEF(typename real_value_traits::pointer) pointer;
|
Chris@16
|
497 typedef BOOST_INTRUSIVE_IMPDEF(typename real_value_traits::const_pointer) const_pointer;
|
Chris@16
|
498 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::element_type) value_type;
|
Chris@16
|
499 typedef BOOST_INTRUSIVE_IMPDEF(value_type) key_type;
|
Chris@16
|
500 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference;
|
Chris@16
|
501 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference;
|
Chris@16
|
502 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type;
|
Chris@16
|
503 typedef BOOST_INTRUSIVE_IMPDEF(SizeType) size_type;
|
Chris@16
|
504 typedef BOOST_INTRUSIVE_IMPDEF(typename data_type::value_compare) value_compare;
|
Chris@16
|
505 typedef BOOST_INTRUSIVE_IMPDEF(value_compare) key_compare;
|
Chris@16
|
506 typedef BOOST_INTRUSIVE_IMPDEF(iterator_type) iterator;
|
Chris@16
|
507 typedef BOOST_INTRUSIVE_IMPDEF(const_iterator_type) const_iterator;
|
Chris@16
|
508 typedef BOOST_INTRUSIVE_IMPDEF(boost::intrusive::detail::reverse_iterator<iterator>) reverse_iterator;
|
Chris@16
|
509 typedef BOOST_INTRUSIVE_IMPDEF(boost::intrusive::detail::reverse_iterator<const_iterator>) const_reverse_iterator;
|
Chris@16
|
510 typedef BOOST_INTRUSIVE_IMPDEF(typename real_value_traits::node_traits) node_traits;
|
Chris@16
|
511 typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::node) node;
|
Chris@16
|
512 typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::node_ptr) node_ptr;
|
Chris@16
|
513 typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::const_node_ptr) const_node_ptr;
|
Chris@16
|
514 /// @cond
|
Chris@16
|
515 typedef typename get_algo<AlgoType, node_traits>::type algo_type;
|
Chris@16
|
516 /// @endcond
|
Chris@16
|
517 typedef BOOST_INTRUSIVE_IMPDEF(algo_type) node_algorithms;
|
Chris@16
|
518
|
Chris@16
|
519 static const bool constant_time_size = ConstantTimeSize;
|
Chris@16
|
520 static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value;
|
Chris@16
|
521 /// @cond
|
Chris@16
|
522 private:
|
Chris@16
|
523
|
Chris@16
|
524 //noncopyable
|
Chris@16
|
525 BOOST_MOVABLE_BUT_NOT_COPYABLE(bstree_impl)
|
Chris@16
|
526
|
Chris@16
|
527 static const bool safemode_or_autounlink = is_safe_autounlink<real_value_traits::link_mode>::value;
|
Chris@16
|
528
|
Chris@16
|
529 //Constant-time size is incompatible with auto-unlink hooks!
|
Chris@16
|
530 BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink)));
|
Chris@16
|
531
|
Chris@16
|
532
|
Chris@16
|
533 protected:
|
Chris@16
|
534
|
Chris@16
|
535
|
Chris@16
|
536 /// @endcond
|
Chris@16
|
537
|
Chris@16
|
538 public:
|
Chris@16
|
539
|
Chris@16
|
540 typedef typename node_algorithms::insert_commit_data insert_commit_data;
|
Chris@16
|
541
|
Chris@16
|
542 //! <b>Effects</b>: Constructs an empty container.
|
Chris@16
|
543 //!
|
Chris@16
|
544 //! <b>Complexity</b>: Constant.
|
Chris@16
|
545 //!
|
Chris@16
|
546 //! <b>Throws</b>: If value_traits::node_traits::node
|
Chris@16
|
547 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
|
Chris@16
|
548 //! or the copy constructorof the value_compare object throws. Basic guarantee.
|
Chris@16
|
549 explicit bstree_impl( const value_compare &cmp = value_compare()
|
Chris@16
|
550 , const value_traits &v_traits = value_traits())
|
Chris@16
|
551 : data_type(cmp, v_traits)
|
Chris@16
|
552 {
|
Chris@16
|
553 node_algorithms::init_header(this->header_ptr());
|
Chris@16
|
554 this->sz_traits().set_size(size_type(0));
|
Chris@16
|
555 }
|
Chris@16
|
556
|
Chris@16
|
557 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
|
Chris@16
|
558 //! cmp must be a comparison function that induces a strict weak ordering.
|
Chris@16
|
559 //!
|
Chris@16
|
560 //! <b>Effects</b>: Constructs an empty container and inserts elements from
|
Chris@16
|
561 //! [b, e).
|
Chris@16
|
562 //!
|
Chris@16
|
563 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
|
Chris@16
|
564 //! comp and otherwise N * log N, where N is the distance between first and last.
|
Chris@16
|
565 //!
|
Chris@16
|
566 //! <b>Throws</b>: If value_traits::node_traits::node
|
Chris@16
|
567 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
|
Chris@16
|
568 //! or the copy constructor/operator() of the value_compare object throws. Basic guarantee.
|
Chris@16
|
569 template<class Iterator>
|
Chris@16
|
570 bstree_impl( bool unique, Iterator b, Iterator e
|
Chris@16
|
571 , const value_compare &cmp = value_compare()
|
Chris@16
|
572 , const value_traits &v_traits = value_traits())
|
Chris@16
|
573 : data_type(cmp, v_traits)
|
Chris@16
|
574 {
|
Chris@16
|
575 node_algorithms::init_header(this->header_ptr());
|
Chris@16
|
576 this->sz_traits().set_size(size_type(0));
|
Chris@16
|
577 if(unique)
|
Chris@16
|
578 this->insert_unique(b, e);
|
Chris@16
|
579 else
|
Chris@16
|
580 this->insert_equal(b, e);
|
Chris@16
|
581 }
|
Chris@16
|
582
|
Chris@16
|
583 //! <b>Effects</b>: to-do
|
Chris@16
|
584 //!
|
Chris@16
|
585 bstree_impl(BOOST_RV_REF(bstree_impl) x)
|
Chris@16
|
586 : data_type(::boost::move(x.comp()), ::boost::move(x.val_traits()))
|
Chris@16
|
587 {
|
Chris@16
|
588 node_algorithms::init_header(this->header_ptr());
|
Chris@16
|
589 this->sz_traits().set_size(size_type(0));
|
Chris@16
|
590 this->swap(x);
|
Chris@16
|
591 }
|
Chris@16
|
592
|
Chris@16
|
593 //! <b>Effects</b>: to-do
|
Chris@16
|
594 //!
|
Chris@16
|
595 bstree_impl& operator=(BOOST_RV_REF(bstree_impl) x)
|
Chris@16
|
596 { this->swap(x); return *this; }
|
Chris@16
|
597
|
Chris@16
|
598 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
599 //! <b>Effects</b>: Detaches all elements from this. The objects in the set
|
Chris@16
|
600 //! are not deleted (i.e. no destructors are called), but the nodes according to
|
Chris@16
|
601 //! the value_traits template parameter are reinitialized and thus can be reused.
|
Chris@16
|
602 //!
|
Chris@16
|
603 //! <b>Complexity</b>: Linear to elements contained in *this.
|
Chris@16
|
604 //!
|
Chris@16
|
605 //! <b>Throws</b>: Nothing.
|
Chris@16
|
606 ~bstree_impl()
|
Chris@16
|
607 {}
|
Chris@16
|
608
|
Chris@16
|
609 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the container.
|
Chris@16
|
610 //!
|
Chris@16
|
611 //! <b>Complexity</b>: Constant.
|
Chris@16
|
612 //!
|
Chris@16
|
613 //! <b>Throws</b>: Nothing.
|
Chris@16
|
614 iterator begin();
|
Chris@16
|
615
|
Chris@16
|
616 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the container.
|
Chris@16
|
617 //!
|
Chris@16
|
618 //! <b>Complexity</b>: Constant.
|
Chris@16
|
619 //!
|
Chris@16
|
620 //! <b>Throws</b>: Nothing.
|
Chris@16
|
621 const_iterator begin() const;
|
Chris@16
|
622
|
Chris@16
|
623 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the container.
|
Chris@16
|
624 //!
|
Chris@16
|
625 //! <b>Complexity</b>: Constant.
|
Chris@16
|
626 //!
|
Chris@16
|
627 //! <b>Throws</b>: Nothing.
|
Chris@16
|
628 const_iterator cbegin() const;
|
Chris@16
|
629
|
Chris@16
|
630 //! <b>Effects</b>: Returns an iterator pointing to the end of the container.
|
Chris@16
|
631 //!
|
Chris@16
|
632 //! <b>Complexity</b>: Constant.
|
Chris@16
|
633 //!
|
Chris@16
|
634 //! <b>Throws</b>: Nothing.
|
Chris@16
|
635 iterator end();
|
Chris@16
|
636
|
Chris@16
|
637 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the container.
|
Chris@16
|
638 //!
|
Chris@16
|
639 //! <b>Complexity</b>: Constant.
|
Chris@16
|
640 //!
|
Chris@16
|
641 //! <b>Throws</b>: Nothing.
|
Chris@16
|
642 const_iterator end() const;
|
Chris@16
|
643
|
Chris@16
|
644 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the container.
|
Chris@16
|
645 //!
|
Chris@16
|
646 //! <b>Complexity</b>: Constant.
|
Chris@16
|
647 //!
|
Chris@16
|
648 //! <b>Throws</b>: Nothing.
|
Chris@16
|
649 const_iterator cend() const;
|
Chris@16
|
650
|
Chris@16
|
651 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
|
Chris@16
|
652 //! reversed container.
|
Chris@16
|
653 //!
|
Chris@16
|
654 //! <b>Complexity</b>: Constant.
|
Chris@16
|
655 //!
|
Chris@16
|
656 //! <b>Throws</b>: Nothing.
|
Chris@16
|
657 reverse_iterator rbegin();
|
Chris@16
|
658
|
Chris@16
|
659 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
|
Chris@16
|
660 //! of the reversed container.
|
Chris@16
|
661 //!
|
Chris@16
|
662 //! <b>Complexity</b>: Constant.
|
Chris@16
|
663 //!
|
Chris@16
|
664 //! <b>Throws</b>: Nothing.
|
Chris@16
|
665 const_reverse_iterator rbegin() const;
|
Chris@16
|
666
|
Chris@16
|
667 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
|
Chris@16
|
668 //! of the reversed container.
|
Chris@16
|
669 //!
|
Chris@16
|
670 //! <b>Complexity</b>: Constant.
|
Chris@16
|
671 //!
|
Chris@16
|
672 //! <b>Throws</b>: Nothing.
|
Chris@16
|
673 const_reverse_iterator crbegin() const;
|
Chris@16
|
674
|
Chris@16
|
675 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
|
Chris@16
|
676 //! of the reversed container.
|
Chris@16
|
677 //!
|
Chris@16
|
678 //! <b>Complexity</b>: Constant.
|
Chris@16
|
679 //!
|
Chris@16
|
680 //! <b>Throws</b>: Nothing.
|
Chris@16
|
681 reverse_iterator rend();
|
Chris@16
|
682
|
Chris@16
|
683 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
|
Chris@16
|
684 //! of the reversed container.
|
Chris@16
|
685 //!
|
Chris@16
|
686 //! <b>Complexity</b>: Constant.
|
Chris@16
|
687 //!
|
Chris@16
|
688 //! <b>Throws</b>: Nothing.
|
Chris@16
|
689 const_reverse_iterator rend() const;
|
Chris@16
|
690
|
Chris@16
|
691 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
|
Chris@16
|
692 //! of the reversed container.
|
Chris@16
|
693 //!
|
Chris@16
|
694 //! <b>Complexity</b>: Constant.
|
Chris@16
|
695 //!
|
Chris@16
|
696 //! <b>Throws</b>: Nothing.
|
Chris@16
|
697 const_reverse_iterator crend() const;
|
Chris@16
|
698
|
Chris@16
|
699 #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
700
|
Chris@16
|
701 //! <b>Precondition</b>: end_iterator must be a valid end iterator
|
Chris@16
|
702 //! of the container.
|
Chris@16
|
703 //!
|
Chris@16
|
704 //! <b>Effects</b>: Returns a const reference to the container associated to the end iterator
|
Chris@16
|
705 //!
|
Chris@16
|
706 //! <b>Throws</b>: Nothing.
|
Chris@16
|
707 //!
|
Chris@16
|
708 //! <b>Complexity</b>: Constant.
|
Chris@16
|
709 static bstree_impl &container_from_end_iterator(iterator end_iterator)
|
Chris@16
|
710 {
|
Chris@16
|
711 return *static_cast<bstree_impl*>
|
Chris@16
|
712 (boost::intrusive::detail::to_raw_pointer(end_iterator.pointed_node()));
|
Chris@16
|
713 }
|
Chris@16
|
714
|
Chris@16
|
715 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
|
Chris@16
|
716 //! of the container.
|
Chris@16
|
717 //!
|
Chris@16
|
718 //! <b>Effects</b>: Returns a const reference to the container associated to the iterator
|
Chris@16
|
719 //!
|
Chris@16
|
720 //! <b>Throws</b>: Nothing.
|
Chris@16
|
721 //!
|
Chris@16
|
722 //! <b>Complexity</b>: Constant.
|
Chris@16
|
723 static const bstree_impl &container_from_end_iterator(const_iterator end_iterator)
|
Chris@16
|
724 {
|
Chris@16
|
725 return *static_cast<const bstree_impl*>
|
Chris@16
|
726 (boost::intrusive::detail::to_raw_pointer(end_iterator.pointed_node()));
|
Chris@16
|
727 }
|
Chris@16
|
728
|
Chris@16
|
729 //! <b>Precondition</b>: it must be a valid iterator
|
Chris@16
|
730 //! of the container.
|
Chris@16
|
731 //!
|
Chris@16
|
732 //! <b>Effects</b>: Returns a const reference to the container associated to the iterator
|
Chris@16
|
733 //!
|
Chris@16
|
734 //! <b>Throws</b>: Nothing.
|
Chris@16
|
735 //!
|
Chris@16
|
736 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
737 static bstree_impl &container_from_iterator(iterator it)
|
Chris@16
|
738 { return container_from_end_iterator(it.end_iterator_from_it()); }
|
Chris@16
|
739
|
Chris@16
|
740 //! <b>Precondition</b>: it must be a valid end const_iterator
|
Chris@16
|
741 //! of container.
|
Chris@16
|
742 //!
|
Chris@16
|
743 //! <b>Effects</b>: Returns a const reference to the container associated to the end iterator
|
Chris@16
|
744 //!
|
Chris@16
|
745 //! <b>Throws</b>: Nothing.
|
Chris@16
|
746 //!
|
Chris@16
|
747 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
748 static const bstree_impl &container_from_iterator(const_iterator it)
|
Chris@16
|
749 { return container_from_end_iterator(it.end_iterator_from_it()); }
|
Chris@16
|
750
|
Chris@16
|
751 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
752
|
Chris@16
|
753 //! <b>Effects</b>: Returns the key_compare object used by the container.
|
Chris@16
|
754 //!
|
Chris@16
|
755 //! <b>Complexity</b>: Constant.
|
Chris@16
|
756 //!
|
Chris@16
|
757 //! <b>Throws</b>: If value_compare copy-constructor throws.
|
Chris@16
|
758 key_compare key_comp() const;
|
Chris@16
|
759
|
Chris@16
|
760 //! <b>Effects</b>: Returns the value_compare object used by the container.
|
Chris@16
|
761 //!
|
Chris@16
|
762 //! <b>Complexity</b>: Constant.
|
Chris@16
|
763 //!
|
Chris@16
|
764 //! <b>Throws</b>: If value_compare copy-constructor throws.
|
Chris@16
|
765 value_compare value_comp() const;
|
Chris@16
|
766
|
Chris@16
|
767 //! <b>Effects</b>: Returns true if the container is empty.
|
Chris@16
|
768 //!
|
Chris@16
|
769 //! <b>Complexity</b>: Constant.
|
Chris@16
|
770 //!
|
Chris@16
|
771 //! <b>Throws</b>: Nothing.
|
Chris@16
|
772 bool empty() const;
|
Chris@16
|
773
|
Chris@16
|
774 #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
775
|
Chris@16
|
776 //! <b>Effects</b>: Returns the number of elements stored in the container.
|
Chris@16
|
777 //!
|
Chris@16
|
778 //! <b>Complexity</b>: Linear to elements contained in *this
|
Chris@16
|
779 //! if constant-time size option is disabled. Constant time otherwise.
|
Chris@16
|
780 //!
|
Chris@16
|
781 //! <b>Throws</b>: Nothing.
|
Chris@16
|
782 size_type size() const
|
Chris@16
|
783 {
|
Chris@16
|
784 if(constant_time_size)
|
Chris@16
|
785 return this->sz_traits().get_size();
|
Chris@16
|
786 else{
|
Chris@16
|
787 return (size_type)node_algorithms::size(this->header_ptr());
|
Chris@16
|
788 }
|
Chris@16
|
789 }
|
Chris@16
|
790
|
Chris@16
|
791 //! <b>Effects</b>: Swaps the contents of two containers.
|
Chris@16
|
792 //!
|
Chris@16
|
793 //! <b>Complexity</b>: Constant.
|
Chris@16
|
794 //!
|
Chris@16
|
795 //! <b>Throws</b>: If the comparison functor's swap call throws.
|
Chris@16
|
796 void swap(bstree_impl& other)
|
Chris@16
|
797 {
|
Chris@16
|
798 //This can throw
|
Chris@16
|
799 using std::swap;
|
Chris@16
|
800 swap(this->comp(), this->comp());
|
Chris@16
|
801 //These can't throw
|
Chris@16
|
802 node_algorithms::swap_tree(this->header_ptr(), node_ptr(other.header_ptr()));
|
Chris@16
|
803 if(constant_time_size){
|
Chris@16
|
804 size_type backup = this->sz_traits().get_size();
|
Chris@16
|
805 this->sz_traits().set_size(other.sz_traits().get_size());
|
Chris@16
|
806 other.sz_traits().set_size(backup);
|
Chris@16
|
807 }
|
Chris@16
|
808 }
|
Chris@16
|
809
|
Chris@16
|
810 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
811 //! Cloner should yield to nodes equivalent to the original nodes.
|
Chris@16
|
812 //!
|
Chris@16
|
813 //! <b>Effects</b>: Erases all the elements from *this
|
Chris@16
|
814 //! calling Disposer::operator()(pointer), clones all the
|
Chris@16
|
815 //! elements from src calling Cloner::operator()(const_reference )
|
Chris@16
|
816 //! and inserts them on *this. Copies the predicate from the source container.
|
Chris@16
|
817 //!
|
Chris@16
|
818 //! If cloner throws, all cloned elements are unlinked and disposed
|
Chris@16
|
819 //! calling Disposer::operator()(pointer).
|
Chris@16
|
820 //!
|
Chris@16
|
821 //! <b>Complexity</b>: Linear to erased plus inserted elements.
|
Chris@16
|
822 //!
|
Chris@16
|
823 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
|
Chris@16
|
824 template <class Cloner, class Disposer>
|
Chris@16
|
825 void clone_from(const bstree_impl &src, Cloner cloner, Disposer disposer)
|
Chris@16
|
826 {
|
Chris@16
|
827 this->clear_and_dispose(disposer);
|
Chris@16
|
828 if(!src.empty()){
|
Chris@16
|
829 detail::exception_disposer<bstree_impl, Disposer>
|
Chris@16
|
830 rollback(*this, disposer);
|
Chris@16
|
831 node_algorithms::clone
|
Chris@16
|
832 (const_node_ptr(src.header_ptr())
|
Chris@16
|
833 ,node_ptr(this->header_ptr())
|
Chris@16
|
834 ,detail::node_cloner <Cloner, real_value_traits, AlgoType>(cloner, &this->get_real_value_traits())
|
Chris@16
|
835 ,detail::node_disposer<Disposer, real_value_traits, AlgoType>(disposer, &this->get_real_value_traits()));
|
Chris@16
|
836 this->sz_traits().set_size(src.sz_traits().get_size());
|
Chris@16
|
837 this->comp() = src.comp();
|
Chris@16
|
838 rollback.release();
|
Chris@16
|
839 }
|
Chris@16
|
840 }
|
Chris@16
|
841
|
Chris@16
|
842 //! <b>Requires</b>: value must be an lvalue
|
Chris@16
|
843 //!
|
Chris@16
|
844 //! <b>Effects</b>: Inserts value into the container before the upper bound.
|
Chris@16
|
845 //!
|
Chris@16
|
846 //! <b>Complexity</b>: Average complexity for insert element is at
|
Chris@16
|
847 //! most logarithmic.
|
Chris@16
|
848 //!
|
Chris@16
|
849 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
|
Chris@16
|
850 //!
|
Chris@16
|
851 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
852 //! No copy-constructors are called.
|
Chris@16
|
853 iterator insert_equal(reference value)
|
Chris@16
|
854 {
|
Chris@16
|
855 detail::key_nodeptr_comp<value_compare, real_value_traits>
|
Chris@16
|
856 key_node_comp(this->comp(), &this->get_real_value_traits());
|
Chris@16
|
857 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
858 if(safemode_or_autounlink)
|
Chris@16
|
859 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
860 iterator ret(node_algorithms::insert_equal_upper_bound
|
Chris@16
|
861 (this->header_ptr(), to_insert, key_node_comp), this->real_value_traits_ptr());
|
Chris@16
|
862 this->sz_traits().increment();
|
Chris@16
|
863 return ret;
|
Chris@16
|
864 }
|
Chris@16
|
865
|
Chris@16
|
866 //! <b>Requires</b>: value must be an lvalue, and "hint" must be
|
Chris@16
|
867 //! a valid iterator.
|
Chris@16
|
868 //!
|
Chris@16
|
869 //! <b>Effects</b>: Inserts x into the container, using "hint" as a hint to
|
Chris@16
|
870 //! where it will be inserted. If "hint" is the upper_bound
|
Chris@16
|
871 //! the insertion takes constant time (two comparisons in the worst case)
|
Chris@16
|
872 //!
|
Chris@16
|
873 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
|
Chris@16
|
874 //! constant time if t is inserted immediately before hint.
|
Chris@16
|
875 //!
|
Chris@16
|
876 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
|
Chris@16
|
877 //!
|
Chris@16
|
878 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
879 //! No copy-constructors are called.
|
Chris@16
|
880 iterator insert_equal(const_iterator hint, reference value)
|
Chris@16
|
881 {
|
Chris@16
|
882 detail::key_nodeptr_comp<value_compare, real_value_traits>
|
Chris@16
|
883 key_node_comp(this->comp(), &this->get_real_value_traits());
|
Chris@16
|
884 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
885 if(safemode_or_autounlink)
|
Chris@16
|
886 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
887 iterator ret(node_algorithms::insert_equal
|
Chris@16
|
888 (this->header_ptr(), hint.pointed_node(), to_insert, key_node_comp), this->real_value_traits_ptr());
|
Chris@16
|
889 this->sz_traits().increment();
|
Chris@16
|
890 return ret;
|
Chris@16
|
891 }
|
Chris@16
|
892
|
Chris@16
|
893 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
|
Chris@16
|
894 //! of type value_type.
|
Chris@16
|
895 //!
|
Chris@16
|
896 //! <b>Effects</b>: Inserts a each element of a range into the container
|
Chris@16
|
897 //! before the upper bound of the key of each element.
|
Chris@16
|
898 //!
|
Chris@16
|
899 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
|
Chris@16
|
900 //! size of the range. However, it is linear in N if the range is already sorted
|
Chris@16
|
901 //! by value_comp().
|
Chris@16
|
902 //!
|
Chris@16
|
903 //! <b>Throws</b>: Nothing.
|
Chris@16
|
904 //!
|
Chris@16
|
905 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
906 //! No copy-constructors are called.
|
Chris@16
|
907 template<class Iterator>
|
Chris@16
|
908 void insert_equal(Iterator b, Iterator e)
|
Chris@16
|
909 {
|
Chris@16
|
910 iterator iend(this->end());
|
Chris@16
|
911 for (; b != e; ++b)
|
Chris@16
|
912 this->insert_equal(iend, *b);
|
Chris@16
|
913 }
|
Chris@16
|
914
|
Chris@16
|
915 //! <b>Requires</b>: value must be an lvalue
|
Chris@16
|
916 //!
|
Chris@16
|
917 //! <b>Effects</b>: Inserts value into the container if the value
|
Chris@16
|
918 //! is not already present.
|
Chris@16
|
919 //!
|
Chris@16
|
920 //! <b>Complexity</b>: Average complexity for insert element is at
|
Chris@16
|
921 //! most logarithmic.
|
Chris@16
|
922 //!
|
Chris@16
|
923 //! <b>Throws</b>: Nothing.
|
Chris@16
|
924 //!
|
Chris@16
|
925 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
926 //! No copy-constructors are called.
|
Chris@16
|
927 std::pair<iterator, bool> insert_unique(reference value)
|
Chris@16
|
928 {
|
Chris@16
|
929 insert_commit_data commit_data;
|
Chris@16
|
930 std::pair<iterator, bool> ret = this->insert_unique_check(value, this->comp(), commit_data);
|
Chris@16
|
931 if(!ret.second)
|
Chris@16
|
932 return ret;
|
Chris@16
|
933 return std::pair<iterator, bool> (this->insert_unique_commit(value, commit_data), true);
|
Chris@16
|
934 }
|
Chris@16
|
935
|
Chris@16
|
936 //! <b>Requires</b>: value must be an lvalue, and "hint" must be
|
Chris@16
|
937 //! a valid iterator
|
Chris@16
|
938 //!
|
Chris@16
|
939 //! <b>Effects</b>: Tries to insert x into the container, using "hint" as a hint
|
Chris@16
|
940 //! to where it will be inserted.
|
Chris@16
|
941 //!
|
Chris@16
|
942 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
|
Chris@16
|
943 //! constant time (two comparisons in the worst case)
|
Chris@16
|
944 //! if t is inserted immediately before hint.
|
Chris@16
|
945 //!
|
Chris@16
|
946 //! <b>Throws</b>: Nothing.
|
Chris@16
|
947 //!
|
Chris@16
|
948 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
949 //! No copy-constructors are called.
|
Chris@16
|
950 iterator insert_unique(const_iterator hint, reference value)
|
Chris@16
|
951 {
|
Chris@16
|
952 insert_commit_data commit_data;
|
Chris@16
|
953 std::pair<iterator, bool> ret = this->insert_unique_check(hint, value, this->comp(), commit_data);
|
Chris@16
|
954 if(!ret.second)
|
Chris@16
|
955 return ret.first;
|
Chris@16
|
956 return this->insert_unique_commit(value, commit_data);
|
Chris@16
|
957 }
|
Chris@16
|
958
|
Chris@16
|
959 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
|
Chris@16
|
960 //! of type value_type.
|
Chris@16
|
961 //!
|
Chris@16
|
962 //! <b>Effects</b>: Tries to insert each element of a range into the container.
|
Chris@16
|
963 //!
|
Chris@16
|
964 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
|
Chris@16
|
965 //! size of the range. However, it is linear in N if the range is already sorted
|
Chris@16
|
966 //! by value_comp().
|
Chris@16
|
967 //!
|
Chris@16
|
968 //! <b>Throws</b>: Nothing.
|
Chris@16
|
969 //!
|
Chris@16
|
970 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
971 //! No copy-constructors are called.
|
Chris@16
|
972 template<class Iterator>
|
Chris@16
|
973 void insert_unique(Iterator b, Iterator e)
|
Chris@16
|
974 {
|
Chris@16
|
975 if(this->empty()){
|
Chris@16
|
976 iterator iend(this->end());
|
Chris@16
|
977 for (; b != e; ++b)
|
Chris@16
|
978 this->insert_unique(iend, *b);
|
Chris@16
|
979 }
|
Chris@16
|
980 else{
|
Chris@16
|
981 for (; b != e; ++b)
|
Chris@16
|
982 this->insert_unique(*b);
|
Chris@16
|
983 }
|
Chris@16
|
984 }
|
Chris@16
|
985
|
Chris@16
|
986 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
987
|
Chris@16
|
988 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
|
Chris@16
|
989 //! the same strict weak ordering as value_compare. The difference is that
|
Chris@16
|
990 //! key_value_comp compares an arbitrary key with the contained values.
|
Chris@16
|
991 //!
|
Chris@16
|
992 //! <b>Effects</b>: Checks if a value can be inserted in the container, using
|
Chris@16
|
993 //! a user provided key instead of the value itself.
|
Chris@16
|
994 //!
|
Chris@16
|
995 //! <b>Returns</b>: If there is an equivalent value
|
Chris@16
|
996 //! returns a pair containing an iterator to the already present value
|
Chris@16
|
997 //! and false. If the value can be inserted returns true in the returned
|
Chris@16
|
998 //! pair boolean and fills "commit_data" that is meant to be used with
|
Chris@16
|
999 //! the "insert_commit" function.
|
Chris@16
|
1000 //!
|
Chris@16
|
1001 //! <b>Complexity</b>: Average complexity is at most logarithmic.
|
Chris@16
|
1002 //!
|
Chris@16
|
1003 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
|
Chris@16
|
1004 //!
|
Chris@16
|
1005 //! <b>Notes</b>: This function is used to improve performance when constructing
|
Chris@16
|
1006 //! a value_type is expensive: if there is an equivalent value
|
Chris@16
|
1007 //! the constructed object must be discarded. Many times, the part of the
|
Chris@16
|
1008 //! node that is used to impose the order is much cheaper to construct
|
Chris@16
|
1009 //! than the value_type and this function offers the possibility to use that
|
Chris@16
|
1010 //! part to check if the insertion will be successful.
|
Chris@16
|
1011 //!
|
Chris@16
|
1012 //! If the check is successful, the user can construct the value_type and use
|
Chris@16
|
1013 //! "insert_commit" to insert the object in constant-time. This gives a total
|
Chris@16
|
1014 //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
|
Chris@16
|
1015 //!
|
Chris@16
|
1016 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
|
Chris@16
|
1017 //! objects are inserted or erased from the container.
|
Chris@16
|
1018 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1019 std::pair<iterator, bool> insert_unique_check
|
Chris@16
|
1020 (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data);
|
Chris@16
|
1021
|
Chris@16
|
1022 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
|
Chris@16
|
1023 //! the same strict weak ordering as value_compare. The difference is that
|
Chris@16
|
1024 //! key_value_comp compares an arbitrary key with the contained values.
|
Chris@16
|
1025 //!
|
Chris@16
|
1026 //! <b>Effects</b>: Checks if a value can be inserted in the container, using
|
Chris@16
|
1027 //! a user provided key instead of the value itself, using "hint"
|
Chris@16
|
1028 //! as a hint to where it will be inserted.
|
Chris@16
|
1029 //!
|
Chris@16
|
1030 //! <b>Returns</b>: If there is an equivalent value
|
Chris@16
|
1031 //! returns a pair containing an iterator to the already present value
|
Chris@16
|
1032 //! and false. If the value can be inserted returns true in the returned
|
Chris@16
|
1033 //! pair boolean and fills "commit_data" that is meant to be used with
|
Chris@16
|
1034 //! the "insert_commit" function.
|
Chris@16
|
1035 //!
|
Chris@16
|
1036 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
|
Chris@16
|
1037 //! constant time if t is inserted immediately before hint.
|
Chris@16
|
1038 //!
|
Chris@16
|
1039 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
|
Chris@16
|
1040 //!
|
Chris@16
|
1041 //! <b>Notes</b>: This function is used to improve performance when constructing
|
Chris@16
|
1042 //! a value_type is expensive: if there is an equivalent value
|
Chris@16
|
1043 //! the constructed object must be discarded. Many times, the part of the
|
Chris@16
|
1044 //! constructing that is used to impose the order is much cheaper to construct
|
Chris@16
|
1045 //! than the value_type and this function offers the possibility to use that key
|
Chris@16
|
1046 //! to check if the insertion will be successful.
|
Chris@16
|
1047 //!
|
Chris@16
|
1048 //! If the check is successful, the user can construct the value_type and use
|
Chris@16
|
1049 //! "insert_commit" to insert the object in constant-time. This can give a total
|
Chris@16
|
1050 //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
|
Chris@16
|
1051 //!
|
Chris@16
|
1052 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
|
Chris@16
|
1053 //! objects are inserted or erased from the container.
|
Chris@16
|
1054 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1055 std::pair<iterator, bool> insert_unique_check
|
Chris@16
|
1056 (const_iterator hint, const KeyType &key
|
Chris@16
|
1057 ,KeyValueCompare key_value_comp, insert_commit_data &commit_data);
|
Chris@16
|
1058
|
Chris@16
|
1059 #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
1060
|
Chris@16
|
1061 //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
|
Chris@16
|
1062 //! must have been obtained from a previous call to "insert_check".
|
Chris@16
|
1063 //! No objects should have been inserted or erased from the container between
|
Chris@16
|
1064 //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
|
Chris@16
|
1065 //!
|
Chris@16
|
1066 //! <b>Effects</b>: Inserts the value in the container using the information obtained
|
Chris@16
|
1067 //! from the "commit_data" that a previous "insert_check" filled.
|
Chris@16
|
1068 //!
|
Chris@16
|
1069 //! <b>Returns</b>: An iterator to the newly inserted object.
|
Chris@16
|
1070 //!
|
Chris@16
|
1071 //! <b>Complexity</b>: Constant time.
|
Chris@16
|
1072 //!
|
Chris@16
|
1073 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1074 //!
|
Chris@16
|
1075 //! <b>Notes</b>: This function has only sense if a "insert_check" has been
|
Chris@16
|
1076 //! previously executed to fill "commit_data". No value should be inserted or
|
Chris@16
|
1077 //! erased between the "insert_check" and "insert_commit" calls.
|
Chris@16
|
1078 iterator insert_unique_commit(reference value, const insert_commit_data &commit_data)
|
Chris@16
|
1079 {
|
Chris@16
|
1080 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
1081 if(safemode_or_autounlink)
|
Chris@16
|
1082 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
1083 node_algorithms::insert_unique_commit
|
Chris@16
|
1084 (this->header_ptr(), to_insert, commit_data);
|
Chris@16
|
1085 this->sz_traits().increment();
|
Chris@16
|
1086 return iterator(to_insert, this->real_value_traits_ptr());
|
Chris@16
|
1087 }
|
Chris@16
|
1088
|
Chris@16
|
1089 //! <b>Requires</b>: value must be an lvalue, "pos" must be
|
Chris@16
|
1090 //! a valid iterator (or end) and must be the succesor of value
|
Chris@16
|
1091 //! once inserted according to the predicate
|
Chris@16
|
1092 //!
|
Chris@16
|
1093 //! <b>Effects</b>: Inserts x into the container before "pos".
|
Chris@16
|
1094 //!
|
Chris@16
|
1095 //! <b>Complexity</b>: Constant time.
|
Chris@16
|
1096 //!
|
Chris@16
|
1097 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1098 //!
|
Chris@16
|
1099 //! <b>Note</b>: This function does not check preconditions so if "pos" is not
|
Chris@16
|
1100 //! the successor of "value" container ordering invariant will be broken.
|
Chris@16
|
1101 //! This is a low-level function to be used only for performance reasons
|
Chris@16
|
1102 //! by advanced users.
|
Chris@16
|
1103 iterator insert_before(const_iterator pos, reference value)
|
Chris@16
|
1104 {
|
Chris@16
|
1105 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
1106 if(safemode_or_autounlink)
|
Chris@16
|
1107 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
1108 this->sz_traits().increment();
|
Chris@16
|
1109 return iterator(node_algorithms::insert_before
|
Chris@16
|
1110 (this->header_ptr(), pos.pointed_node(), to_insert), this->real_value_traits_ptr());
|
Chris@16
|
1111 }
|
Chris@16
|
1112
|
Chris@16
|
1113 //! <b>Requires</b>: value must be an lvalue, and it must be no less
|
Chris@16
|
1114 //! than the greatest inserted key
|
Chris@16
|
1115 //!
|
Chris@16
|
1116 //! <b>Effects</b>: Inserts x into the container in the last position.
|
Chris@16
|
1117 //!
|
Chris@16
|
1118 //! <b>Complexity</b>: Constant time.
|
Chris@16
|
1119 //!
|
Chris@16
|
1120 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1121 //!
|
Chris@16
|
1122 //! <b>Note</b>: This function does not check preconditions so if value is
|
Chris@16
|
1123 //! less than the greatest inserted key container ordering invariant will be broken.
|
Chris@16
|
1124 //! This function is slightly more efficient than using "insert_before".
|
Chris@16
|
1125 //! This is a low-level function to be used only for performance reasons
|
Chris@16
|
1126 //! by advanced users.
|
Chris@16
|
1127 void push_back(reference value)
|
Chris@16
|
1128 {
|
Chris@16
|
1129 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
1130 if(safemode_or_autounlink)
|
Chris@16
|
1131 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
1132 this->sz_traits().increment();
|
Chris@16
|
1133 node_algorithms::push_back(this->header_ptr(), to_insert);
|
Chris@16
|
1134 }
|
Chris@16
|
1135
|
Chris@16
|
1136 //! <b>Requires</b>: value must be an lvalue, and it must be no greater
|
Chris@16
|
1137 //! than the minimum inserted key
|
Chris@16
|
1138 //!
|
Chris@16
|
1139 //! <b>Effects</b>: Inserts x into the container in the first position.
|
Chris@16
|
1140 //!
|
Chris@16
|
1141 //! <b>Complexity</b>: Constant time.
|
Chris@16
|
1142 //!
|
Chris@16
|
1143 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1144 //!
|
Chris@16
|
1145 //! <b>Note</b>: This function does not check preconditions so if value is
|
Chris@16
|
1146 //! greater than the minimum inserted key container ordering invariant will be broken.
|
Chris@16
|
1147 //! This function is slightly more efficient than using "insert_before".
|
Chris@16
|
1148 //! This is a low-level function to be used only for performance reasons
|
Chris@16
|
1149 //! by advanced users.
|
Chris@16
|
1150 void push_front(reference value)
|
Chris@16
|
1151 {
|
Chris@16
|
1152 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
1153 if(safemode_or_autounlink)
|
Chris@16
|
1154 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
1155 this->sz_traits().increment();
|
Chris@16
|
1156 node_algorithms::push_front(this->header_ptr(), to_insert);
|
Chris@16
|
1157 }
|
Chris@16
|
1158
|
Chris@16
|
1159 //! <b>Effects</b>: Erases the element pointed to by pos.
|
Chris@16
|
1160 //!
|
Chris@16
|
1161 //! <b>Complexity</b>: Average complexity for erase element is constant time.
|
Chris@16
|
1162 //!
|
Chris@16
|
1163 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1164 //!
|
Chris@16
|
1165 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1166 //! to the erased elements. No destructors are called.
|
Chris@16
|
1167 iterator erase(const_iterator i)
|
Chris@16
|
1168 {
|
Chris@16
|
1169 const_iterator ret(i);
|
Chris@16
|
1170 ++ret;
|
Chris@16
|
1171 node_ptr to_erase(i.pointed_node());
|
Chris@16
|
1172 if(safemode_or_autounlink)
|
Chris@16
|
1173 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase));
|
Chris@16
|
1174 node_algorithms::erase(this->header_ptr(), to_erase);
|
Chris@16
|
1175 this->sz_traits().decrement();
|
Chris@16
|
1176 if(safemode_or_autounlink)
|
Chris@16
|
1177 node_algorithms::init(to_erase);
|
Chris@16
|
1178 return ret.unconst();
|
Chris@16
|
1179 }
|
Chris@16
|
1180
|
Chris@16
|
1181 //! <b>Effects</b>: Erases the range pointed to by b end e.
|
Chris@16
|
1182 //!
|
Chris@16
|
1183 //! <b>Complexity</b>: Average complexity for erase range is at most
|
Chris@16
|
1184 //! O(log(size() + N)), where N is the number of elements in the range.
|
Chris@16
|
1185 //!
|
Chris@16
|
1186 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1187 //!
|
Chris@16
|
1188 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1189 //! to the erased elements. No destructors are called.
|
Chris@16
|
1190 iterator erase(const_iterator b, const_iterator e)
|
Chris@16
|
1191 { size_type n; return this->private_erase(b, e, n); }
|
Chris@16
|
1192
|
Chris@16
|
1193 //! <b>Effects</b>: Erases all the elements with the given value.
|
Chris@16
|
1194 //!
|
Chris@16
|
1195 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
1196 //!
|
Chris@16
|
1197 //! <b>Complexity</b>: O(log(size() + N).
|
Chris@16
|
1198 //!
|
Chris@16
|
1199 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1200 //!
|
Chris@16
|
1201 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1202 //! to the erased elements. No destructors are called.
|
Chris@16
|
1203 size_type erase(const_reference value)
|
Chris@16
|
1204 { return this->erase(value, this->comp()); }
|
Chris@16
|
1205
|
Chris@16
|
1206 //! <b>Effects</b>: Erases all the elements with the given key.
|
Chris@16
|
1207 //! according to the comparison functor "comp".
|
Chris@16
|
1208 //!
|
Chris@16
|
1209 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
1210 //!
|
Chris@16
|
1211 //! <b>Complexity</b>: O(log(size() + N).
|
Chris@16
|
1212 //!
|
Chris@16
|
1213 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1214 //!
|
Chris@16
|
1215 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1216 //! to the erased elements. No destructors are called.
|
Chris@16
|
1217 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1218 size_type erase(const KeyType& key, KeyValueCompare comp
|
Chris@16
|
1219 /// @cond
|
Chris@16
|
1220 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
|
Chris@16
|
1221 /// @endcond
|
Chris@16
|
1222 )
|
Chris@16
|
1223 {
|
Chris@16
|
1224 std::pair<iterator,iterator> p = this->equal_range(key, comp);
|
Chris@16
|
1225 size_type n;
|
Chris@16
|
1226 this->private_erase(p.first, p.second, n);
|
Chris@16
|
1227 return n;
|
Chris@16
|
1228 }
|
Chris@16
|
1229
|
Chris@16
|
1230 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
1231 //!
|
Chris@16
|
1232 //! <b>Effects</b>: Erases the element pointed to by pos.
|
Chris@16
|
1233 //! Disposer::operator()(pointer) is called for the removed element.
|
Chris@16
|
1234 //!
|
Chris@16
|
1235 //! <b>Complexity</b>: Average complexity for erase element is constant time.
|
Chris@16
|
1236 //!
|
Chris@16
|
1237 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1238 //!
|
Chris@16
|
1239 //! <b>Note</b>: Invalidates the iterators
|
Chris@16
|
1240 //! to the erased elements.
|
Chris@16
|
1241 template<class Disposer>
|
Chris@16
|
1242 iterator erase_and_dispose(const_iterator i, Disposer disposer)
|
Chris@16
|
1243 {
|
Chris@16
|
1244 node_ptr to_erase(i.pointed_node());
|
Chris@16
|
1245 iterator ret(this->erase(i));
|
Chris@16
|
1246 disposer(this->get_real_value_traits().to_value_ptr(to_erase));
|
Chris@16
|
1247 return ret;
|
Chris@16
|
1248 }
|
Chris@16
|
1249
|
Chris@16
|
1250 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1251 template<class Disposer>
|
Chris@16
|
1252 iterator erase_and_dispose(iterator i, Disposer disposer)
|
Chris@16
|
1253 { return this->erase_and_dispose(const_iterator(i), disposer); }
|
Chris@16
|
1254 #endif
|
Chris@16
|
1255
|
Chris@16
|
1256 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
1257 //!
|
Chris@16
|
1258 //! <b>Effects</b>: Erases all the elements with the given value.
|
Chris@16
|
1259 //! Disposer::operator()(pointer) is called for the removed elements.
|
Chris@16
|
1260 //!
|
Chris@16
|
1261 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
1262 //!
|
Chris@16
|
1263 //! <b>Complexity</b>: O(log(size() + N).
|
Chris@16
|
1264 //!
|
Chris@16
|
1265 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1266 //!
|
Chris@16
|
1267 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1268 //! to the erased elements. No destructors are called.
|
Chris@16
|
1269 template<class Disposer>
|
Chris@16
|
1270 size_type erase_and_dispose(const_reference value, Disposer disposer)
|
Chris@16
|
1271 {
|
Chris@16
|
1272 std::pair<iterator,iterator> p = this->equal_range(value);
|
Chris@16
|
1273 size_type n;
|
Chris@16
|
1274 this->private_erase(p.first, p.second, n, disposer);
|
Chris@16
|
1275 return n;
|
Chris@16
|
1276 }
|
Chris@16
|
1277
|
Chris@16
|
1278 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
1279 //!
|
Chris@16
|
1280 //! <b>Effects</b>: Erases the range pointed to by b end e.
|
Chris@16
|
1281 //! Disposer::operator()(pointer) is called for the removed elements.
|
Chris@16
|
1282 //!
|
Chris@16
|
1283 //! <b>Complexity</b>: Average complexity for erase range is at most
|
Chris@16
|
1284 //! O(log(size() + N)), where N is the number of elements in the range.
|
Chris@16
|
1285 //!
|
Chris@16
|
1286 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1287 //!
|
Chris@16
|
1288 //! <b>Note</b>: Invalidates the iterators
|
Chris@16
|
1289 //! to the erased elements.
|
Chris@16
|
1290 template<class Disposer>
|
Chris@16
|
1291 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
|
Chris@16
|
1292 { size_type n; return this->private_erase(b, e, n, disposer); }
|
Chris@16
|
1293
|
Chris@16
|
1294 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
1295 //!
|
Chris@16
|
1296 //! <b>Effects</b>: Erases all the elements with the given key.
|
Chris@16
|
1297 //! according to the comparison functor "comp".
|
Chris@16
|
1298 //! Disposer::operator()(pointer) is called for the removed elements.
|
Chris@16
|
1299 //!
|
Chris@16
|
1300 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
1301 //!
|
Chris@16
|
1302 //! <b>Complexity</b>: O(log(size() + N).
|
Chris@16
|
1303 //!
|
Chris@16
|
1304 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1305 //!
|
Chris@16
|
1306 //! <b>Note</b>: Invalidates the iterators
|
Chris@16
|
1307 //! to the erased elements.
|
Chris@16
|
1308 template<class KeyType, class KeyValueCompare, class Disposer>
|
Chris@16
|
1309 size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer
|
Chris@16
|
1310 /// @cond
|
Chris@16
|
1311 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
|
Chris@16
|
1312 /// @endcond
|
Chris@16
|
1313 )
|
Chris@16
|
1314 {
|
Chris@16
|
1315 std::pair<iterator,iterator> p = this->equal_range(key, comp);
|
Chris@16
|
1316 size_type n;
|
Chris@16
|
1317 this->private_erase(p.first, p.second, n, disposer);
|
Chris@16
|
1318 return n;
|
Chris@16
|
1319 }
|
Chris@16
|
1320
|
Chris@16
|
1321 //! <b>Effects</b>: Erases all of the elements.
|
Chris@16
|
1322 //!
|
Chris@16
|
1323 //! <b>Complexity</b>: Linear to the number of elements on the container.
|
Chris@16
|
1324 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
|
Chris@16
|
1325 //!
|
Chris@16
|
1326 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1327 //!
|
Chris@16
|
1328 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1329 //! to the erased elements. No destructors are called.
|
Chris@16
|
1330 void clear()
|
Chris@16
|
1331 {
|
Chris@16
|
1332 if(safemode_or_autounlink){
|
Chris@16
|
1333 this->clear_and_dispose(detail::null_disposer());
|
Chris@16
|
1334 }
|
Chris@16
|
1335 else{
|
Chris@16
|
1336 node_algorithms::init_header(this->header_ptr());
|
Chris@16
|
1337 this->sz_traits().set_size(0);
|
Chris@16
|
1338 }
|
Chris@16
|
1339 }
|
Chris@16
|
1340
|
Chris@16
|
1341 //! <b>Effects</b>: Erases all of the elements calling disposer(p) for
|
Chris@16
|
1342 //! each node to be erased.
|
Chris@16
|
1343 //! <b>Complexity</b>: Average complexity for is at most O(log(size() + N)),
|
Chris@16
|
1344 //! where N is the number of elements in the container.
|
Chris@16
|
1345 //!
|
Chris@16
|
1346 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1347 //!
|
Chris@16
|
1348 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1349 //! to the erased elements. Calls N times to disposer functor.
|
Chris@16
|
1350 template<class Disposer>
|
Chris@16
|
1351 void clear_and_dispose(Disposer disposer)
|
Chris@16
|
1352 {
|
Chris@16
|
1353 node_algorithms::clear_and_dispose(this->header_ptr()
|
Chris@16
|
1354 , detail::node_disposer<Disposer, real_value_traits, AlgoType>(disposer, &this->get_real_value_traits()));
|
Chris@16
|
1355 node_algorithms::init_header(this->header_ptr());
|
Chris@16
|
1356 this->sz_traits().set_size(0);
|
Chris@16
|
1357 }
|
Chris@16
|
1358
|
Chris@16
|
1359 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1360
|
Chris@16
|
1361 //! <b>Effects</b>: Returns the number of contained elements with the given value
|
Chris@16
|
1362 //!
|
Chris@16
|
1363 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
|
Chris@16
|
1364 //! to number of objects with the given value.
|
Chris@16
|
1365 //!
|
Chris@16
|
1366 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1367 size_type count(const_reference value) const;
|
Chris@16
|
1368
|
Chris@16
|
1369 //! <b>Effects</b>: Returns the number of contained elements with the given key
|
Chris@16
|
1370 //!
|
Chris@16
|
1371 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
|
Chris@16
|
1372 //! to number of objects with the given key.
|
Chris@16
|
1373 //!
|
Chris@16
|
1374 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1375 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1376 size_type count(const KeyType &key, KeyValueCompare comp) const;
|
Chris@16
|
1377
|
Chris@16
|
1378 //! <b>Effects</b>: Returns an iterator to the first element whose
|
Chris@16
|
1379 //! key is not less than k or end() if that element does not exist.
|
Chris@16
|
1380 //!
|
Chris@16
|
1381 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1382 //!
|
Chris@16
|
1383 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1384 iterator lower_bound(const_reference value);
|
Chris@16
|
1385
|
Chris@16
|
1386 //! <b>Effects</b>: Returns an iterator to the first element whose
|
Chris@16
|
1387 //! key is not less than k or end() if that element does not exist.
|
Chris@16
|
1388 //!
|
Chris@16
|
1389 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1390 //!
|
Chris@16
|
1391 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1392 const_iterator lower_bound(const_reference value) const;
|
Chris@16
|
1393
|
Chris@16
|
1394 //! <b>Effects</b>: Returns an iterator to the first element whose
|
Chris@16
|
1395 //! key is not less than k or end() if that element does not exist.
|
Chris@16
|
1396 //!
|
Chris@16
|
1397 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1398 //!
|
Chris@16
|
1399 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1400 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1401 iterator lower_bound(const KeyType &key, KeyValueCompare comp);
|
Chris@16
|
1402
|
Chris@16
|
1403 //! <b>Effects</b>: Returns a const iterator to the first element whose
|
Chris@16
|
1404 //! key is not less than k or end() if that element does not exist.
|
Chris@16
|
1405 //!
|
Chris@16
|
1406 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1407 //!
|
Chris@16
|
1408 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1409 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1410 const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const;
|
Chris@16
|
1411
|
Chris@16
|
1412 //! <b>Effects</b>: Returns an iterator to the first element whose
|
Chris@16
|
1413 //! key is greater than k or end() if that element does not exist.
|
Chris@16
|
1414 //!
|
Chris@16
|
1415 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1416 //!
|
Chris@16
|
1417 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1418 iterator upper_bound(const_reference value);
|
Chris@16
|
1419
|
Chris@16
|
1420 //! <b>Effects</b>: Returns an iterator to the first element whose
|
Chris@16
|
1421 //! key is greater than k according to comp or end() if that element
|
Chris@16
|
1422 //! does not exist.
|
Chris@16
|
1423 //!
|
Chris@16
|
1424 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1425 //!
|
Chris@16
|
1426 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1427 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1428 iterator upper_bound(const KeyType &key, KeyValueCompare comp);
|
Chris@16
|
1429
|
Chris@16
|
1430 //! <b>Effects</b>: Returns an iterator to the first element whose
|
Chris@16
|
1431 //! key is greater than k or end() if that element does not exist.
|
Chris@16
|
1432 //!
|
Chris@16
|
1433 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1434 //!
|
Chris@16
|
1435 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1436 const_iterator upper_bound(const_reference value) const;
|
Chris@16
|
1437
|
Chris@16
|
1438 //! <b>Effects</b>: Returns an iterator to the first element whose
|
Chris@16
|
1439 //! key is greater than k according to comp or end() if that element
|
Chris@16
|
1440 //! does not exist.
|
Chris@16
|
1441 //!
|
Chris@16
|
1442 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1443 //!
|
Chris@16
|
1444 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1445 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1446 const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const;
|
Chris@16
|
1447
|
Chris@16
|
1448 //! <b>Effects</b>: Finds an iterator to the first element whose key is
|
Chris@16
|
1449 //! k or end() if that element does not exist.
|
Chris@16
|
1450 //!
|
Chris@16
|
1451 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1452 //!
|
Chris@16
|
1453 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1454 iterator find(const_reference value);
|
Chris@16
|
1455
|
Chris@16
|
1456 //! <b>Effects</b>: Finds an iterator to the first element whose key is
|
Chris@16
|
1457 //! k or end() if that element does not exist.
|
Chris@16
|
1458 //!
|
Chris@16
|
1459 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1460 //!
|
Chris@16
|
1461 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1462 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1463 iterator find(const KeyType &key, KeyValueCompare comp);
|
Chris@16
|
1464
|
Chris@16
|
1465 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
|
Chris@16
|
1466 //! k or end() if that element does not exist.
|
Chris@16
|
1467 //!
|
Chris@16
|
1468 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1469 //!
|
Chris@16
|
1470 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1471 const_iterator find(const_reference value) const;
|
Chris@16
|
1472
|
Chris@16
|
1473 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
|
Chris@16
|
1474 //! k or end() if that element does not exist.
|
Chris@16
|
1475 //!
|
Chris@16
|
1476 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1477 //!
|
Chris@16
|
1478 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1479 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1480 const_iterator find(const KeyType &key, KeyValueCompare comp) const;
|
Chris@16
|
1481
|
Chris@16
|
1482 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
|
Chris@16
|
1483 //! an empty range that indicates the position where those elements would be
|
Chris@16
|
1484 //! if they there is no elements with key k.
|
Chris@16
|
1485 //!
|
Chris@16
|
1486 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1487 //!
|
Chris@16
|
1488 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1489 std::pair<iterator,iterator> equal_range(const_reference value);
|
Chris@16
|
1490
|
Chris@16
|
1491 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
|
Chris@16
|
1492 //! an empty range that indicates the position where those elements would be
|
Chris@16
|
1493 //! if they there is no elements with key k.
|
Chris@16
|
1494 //!
|
Chris@16
|
1495 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1496 //!
|
Chris@16
|
1497 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1498 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1499 std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp);
|
Chris@16
|
1500
|
Chris@16
|
1501 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
|
Chris@16
|
1502 //! an empty range that indicates the position where those elements would be
|
Chris@16
|
1503 //! if they there is no elements with key k.
|
Chris@16
|
1504 //!
|
Chris@16
|
1505 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1506 //!
|
Chris@16
|
1507 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1508 std::pair<const_iterator, const_iterator>
|
Chris@16
|
1509 equal_range(const_reference value) const;
|
Chris@16
|
1510
|
Chris@16
|
1511 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
|
Chris@16
|
1512 //! an empty range that indicates the position where those elements would be
|
Chris@16
|
1513 //! if they there is no elements with key k.
|
Chris@16
|
1514 //!
|
Chris@16
|
1515 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1516 //!
|
Chris@16
|
1517 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1518 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1519 std::pair<const_iterator, const_iterator>
|
Chris@16
|
1520 equal_range(const KeyType &key, KeyValueCompare comp) const;
|
Chris@16
|
1521
|
Chris@16
|
1522 //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If
|
Chris@16
|
1523 //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false.
|
Chris@16
|
1524 //!
|
Chris@16
|
1525 //! <b>Effects</b>: Returns an a pair with the following criteria:
|
Chris@16
|
1526 //!
|
Chris@16
|
1527 //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise
|
Chris@16
|
1528 //!
|
Chris@16
|
1529 //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise
|
Chris@16
|
1530 //!
|
Chris@16
|
1531 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1532 //!
|
Chris@16
|
1533 //! <b>Throws</b>: If the predicate throws.
|
Chris@16
|
1534 //!
|
Chris@16
|
1535 //! <b>Note</b>: This function can be more efficient than calling upper_bound
|
Chris@16
|
1536 //! and lower_bound for lower_value and upper_value.
|
Chris@16
|
1537 //!
|
Chris@16
|
1538 //! <b>Note</b>: Experimental function, the interface might change in future releases.
|
Chris@16
|
1539 std::pair<iterator,iterator> bounded_range
|
Chris@16
|
1540 (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed);
|
Chris@16
|
1541
|
Chris@16
|
1542 //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak
|
Chris@16
|
1543 //! ordering compatible with the strict weak ordering used to create the
|
Chris@16
|
1544 //! the container.
|
Chris@16
|
1545 //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If
|
Chris@16
|
1546 //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false.
|
Chris@16
|
1547 //!
|
Chris@16
|
1548 //! <b>Effects</b>: Returns an a pair with the following criteria:
|
Chris@16
|
1549 //!
|
Chris@16
|
1550 //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise
|
Chris@16
|
1551 //!
|
Chris@16
|
1552 //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise
|
Chris@16
|
1553 //!
|
Chris@16
|
1554 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1555 //!
|
Chris@16
|
1556 //! <b>Throws</b>: If "comp" throws.
|
Chris@16
|
1557 //!
|
Chris@16
|
1558 //! <b>Note</b>: This function can be more efficient than calling upper_bound
|
Chris@16
|
1559 //! and lower_bound for lower_key and upper_key.
|
Chris@16
|
1560 //!
|
Chris@16
|
1561 //! <b>Note</b>: Experimental function, the interface might change in future releases.
|
Chris@16
|
1562 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1563 std::pair<iterator,iterator> bounded_range
|
Chris@16
|
1564 (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed);
|
Chris@16
|
1565
|
Chris@16
|
1566 //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If
|
Chris@16
|
1567 //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false.
|
Chris@16
|
1568 //!
|
Chris@16
|
1569 //! <b>Effects</b>: Returns an a pair with the following criteria:
|
Chris@16
|
1570 //!
|
Chris@16
|
1571 //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise
|
Chris@16
|
1572 //!
|
Chris@16
|
1573 //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise
|
Chris@16
|
1574 //!
|
Chris@16
|
1575 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1576 //!
|
Chris@16
|
1577 //! <b>Throws</b>: If the predicate throws.
|
Chris@16
|
1578 //!
|
Chris@16
|
1579 //! <b>Note</b>: This function can be more efficient than calling upper_bound
|
Chris@16
|
1580 //! and lower_bound for lower_value and upper_value.
|
Chris@16
|
1581 //!
|
Chris@16
|
1582 //! <b>Note</b>: Experimental function, the interface might change in future releases.
|
Chris@16
|
1583 std::pair<const_iterator,const_iterator> bounded_range
|
Chris@16
|
1584 (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const;
|
Chris@16
|
1585
|
Chris@16
|
1586 //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak
|
Chris@16
|
1587 //! ordering compatible with the strict weak ordering used to create the
|
Chris@16
|
1588 //! the container.
|
Chris@16
|
1589 //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If
|
Chris@16
|
1590 //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false.
|
Chris@16
|
1591 //!
|
Chris@16
|
1592 //! <b>Effects</b>: Returns an a pair with the following criteria:
|
Chris@16
|
1593 //!
|
Chris@16
|
1594 //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise
|
Chris@16
|
1595 //!
|
Chris@16
|
1596 //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise
|
Chris@16
|
1597 //!
|
Chris@16
|
1598 //! <b>Complexity</b>: Logarithmic.
|
Chris@16
|
1599 //!
|
Chris@16
|
1600 //! <b>Throws</b>: If "comp" throws.
|
Chris@16
|
1601 //!
|
Chris@16
|
1602 //! <b>Note</b>: This function can be more efficient than calling upper_bound
|
Chris@16
|
1603 //! and lower_bound for lower_key and upper_key.
|
Chris@16
|
1604 //!
|
Chris@16
|
1605 //! <b>Note</b>: Experimental function, the interface might change in future releases.
|
Chris@16
|
1606 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1607 std::pair<const_iterator,const_iterator> bounded_range
|
Chris@16
|
1608 (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const;
|
Chris@16
|
1609
|
Chris@16
|
1610 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
|
Chris@16
|
1611 //! appropriate type. Otherwise the behavior is undefined.
|
Chris@16
|
1612 //!
|
Chris@16
|
1613 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
|
Chris@16
|
1614 //! that points to the value
|
Chris@16
|
1615 //!
|
Chris@16
|
1616 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1617 //!
|
Chris@16
|
1618 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1619 //!
|
Chris@16
|
1620 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
|
Chris@16
|
1621 //! is stateless.
|
Chris@16
|
1622 static iterator s_iterator_to(reference value);
|
Chris@16
|
1623
|
Chris@16
|
1624 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
|
Chris@16
|
1625 //! appropriate type. Otherwise the behavior is undefined.
|
Chris@16
|
1626 //!
|
Chris@16
|
1627 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
|
Chris@16
|
1628 //! set that points to the value
|
Chris@16
|
1629 //!
|
Chris@16
|
1630 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1631 //!
|
Chris@16
|
1632 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1633 //!
|
Chris@16
|
1634 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
|
Chris@16
|
1635 //! is stateless.
|
Chris@16
|
1636 static const_iterator s_iterator_to(const_reference value);
|
Chris@16
|
1637
|
Chris@16
|
1638 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
|
Chris@16
|
1639 //! appropriate type. Otherwise the behavior is undefined.
|
Chris@16
|
1640 //!
|
Chris@16
|
1641 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
|
Chris@16
|
1642 //! that points to the value
|
Chris@16
|
1643 //!
|
Chris@16
|
1644 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1645 //!
|
Chris@16
|
1646 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1647 iterator iterator_to(reference value);
|
Chris@16
|
1648
|
Chris@16
|
1649 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
|
Chris@16
|
1650 //! appropriate type. Otherwise the behavior is undefined.
|
Chris@16
|
1651 //!
|
Chris@16
|
1652 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
|
Chris@16
|
1653 //! set that points to the value
|
Chris@16
|
1654 //!
|
Chris@16
|
1655 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1656 //!
|
Chris@16
|
1657 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1658 const_iterator iterator_to(const_reference value) const;
|
Chris@16
|
1659
|
Chris@16
|
1660 //! <b>Requires</b>: value shall not be in a container.
|
Chris@16
|
1661 //!
|
Chris@16
|
1662 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
|
Chris@16
|
1663 //! state.
|
Chris@16
|
1664 //!
|
Chris@16
|
1665 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1666 //!
|
Chris@16
|
1667 //! <b>Complexity</b>: Constant time.
|
Chris@16
|
1668 //!
|
Chris@16
|
1669 //! <b>Note</b>: This function puts the hook in the well-known default state
|
Chris@16
|
1670 //! used by auto_unlink and safe hooks.
|
Chris@16
|
1671 static void init_node(reference value);
|
Chris@16
|
1672
|
Chris@16
|
1673 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1674
|
Chris@16
|
1675 //! <b>Effects</b>: Unlinks the leftmost node from the container.
|
Chris@16
|
1676 //!
|
Chris@16
|
1677 //! <b>Complexity</b>: Average complexity is constant time.
|
Chris@16
|
1678 //!
|
Chris@16
|
1679 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1680 //!
|
Chris@16
|
1681 //! <b>Notes</b>: This function breaks the container and the container can
|
Chris@16
|
1682 //! only be used for more unlink_leftmost_without_rebalance calls.
|
Chris@16
|
1683 //! This function is normally used to achieve a step by step
|
Chris@16
|
1684 //! controlled destruction of the container.
|
Chris@16
|
1685 pointer unlink_leftmost_without_rebalance()
|
Chris@16
|
1686 {
|
Chris@16
|
1687 node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance
|
Chris@16
|
1688 (this->header_ptr()));
|
Chris@16
|
1689 if(!to_be_disposed)
|
Chris@16
|
1690 return 0;
|
Chris@16
|
1691 this->sz_traits().decrement();
|
Chris@16
|
1692 if(safemode_or_autounlink)//If this is commented does not work with normal_link
|
Chris@16
|
1693 node_algorithms::init(to_be_disposed);
|
Chris@16
|
1694 return this->get_real_value_traits().to_value_ptr(to_be_disposed);
|
Chris@16
|
1695 }
|
Chris@16
|
1696
|
Chris@16
|
1697 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1698
|
Chris@16
|
1699 //! <b>Requires</b>: replace_this must be a valid iterator of *this
|
Chris@16
|
1700 //! and with_this must not be inserted in any container.
|
Chris@16
|
1701 //!
|
Chris@16
|
1702 //! <b>Effects</b>: Replaces replace_this in its position in the
|
Chris@16
|
1703 //! container with with_this. The container does not need to be rebalanced.
|
Chris@16
|
1704 //!
|
Chris@16
|
1705 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1706 //!
|
Chris@16
|
1707 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1708 //!
|
Chris@16
|
1709 //! <b>Note</b>: This function will break container ordering invariants if
|
Chris@16
|
1710 //! with_this is not equivalent to *replace_this according to the
|
Chris@16
|
1711 //! ordering rules. This function is faster than erasing and inserting
|
Chris@16
|
1712 //! the node, since no rebalancing or comparison is needed.
|
Chris@16
|
1713 void replace_node(iterator replace_this, reference with_this);
|
Chris@16
|
1714
|
Chris@16
|
1715 //! <b>Effects</b>: Rebalances the tree.
|
Chris@16
|
1716 //!
|
Chris@16
|
1717 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1718 //!
|
Chris@16
|
1719 //! <b>Complexity</b>: Linear.
|
Chris@16
|
1720 void rebalance();
|
Chris@16
|
1721
|
Chris@16
|
1722 //! <b>Requires</b>: old_root is a node of a tree.
|
Chris@16
|
1723 //!
|
Chris@16
|
1724 //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
|
Chris@16
|
1725 //!
|
Chris@16
|
1726 //! <b>Returns</b>: The new root of the subtree.
|
Chris@16
|
1727 //!
|
Chris@16
|
1728 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1729 //!
|
Chris@16
|
1730 //! <b>Complexity</b>: Linear to the elements in the subtree.
|
Chris@16
|
1731 iterator rebalance_subtree(iterator root);
|
Chris@16
|
1732
|
Chris@16
|
1733 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1734
|
Chris@16
|
1735 //! <b>Effects</b>: removes "value" from the container.
|
Chris@16
|
1736 //!
|
Chris@16
|
1737 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1738 //!
|
Chris@16
|
1739 //! <b>Complexity</b>: Logarithmic time.
|
Chris@16
|
1740 //!
|
Chris@16
|
1741 //! <b>Note</b>: This static function is only usable with non-constant
|
Chris@16
|
1742 //! time size containers that have stateless comparison functors.
|
Chris@16
|
1743 //!
|
Chris@16
|
1744 //! If the user calls
|
Chris@16
|
1745 //! this function with a constant time size container or stateful comparison
|
Chris@16
|
1746 //! functor a compilation error will be issued.
|
Chris@16
|
1747 static void remove_node(reference value)
|
Chris@16
|
1748 {
|
Chris@16
|
1749 BOOST_STATIC_ASSERT((!constant_time_size));
|
Chris@16
|
1750 node_ptr to_remove(value_traits::to_node_ptr(value));
|
Chris@16
|
1751 node_algorithms::unlink(to_remove);
|
Chris@16
|
1752 if(safemode_or_autounlink)
|
Chris@16
|
1753 node_algorithms::init(to_remove);
|
Chris@16
|
1754 }
|
Chris@16
|
1755
|
Chris@16
|
1756 /// @cond
|
Chris@16
|
1757 private:
|
Chris@16
|
1758 template<class Disposer>
|
Chris@16
|
1759 iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
|
Chris@16
|
1760 {
|
Chris@16
|
1761 for(n = 0; b != e; ++n)
|
Chris@16
|
1762 this->erase_and_dispose(b++, disposer);
|
Chris@16
|
1763 return b.unconst();
|
Chris@16
|
1764 }
|
Chris@16
|
1765
|
Chris@16
|
1766 iterator private_erase(const_iterator b, const_iterator e, size_type &n)
|
Chris@16
|
1767 {
|
Chris@16
|
1768 for(n = 0; b != e; ++n)
|
Chris@16
|
1769 this->erase(b++);
|
Chris@16
|
1770 return b.unconst();
|
Chris@16
|
1771 }
|
Chris@16
|
1772 /// @endcond
|
Chris@16
|
1773
|
Chris@16
|
1774 private:
|
Chris@16
|
1775 static bstree_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
|
Chris@16
|
1776 {
|
Chris@16
|
1777 return *static_cast<bstree_impl*>
|
Chris@16
|
1778 (boost::intrusive::detail::to_raw_pointer(end_iterator.pointed_node()));
|
Chris@16
|
1779 }
|
Chris@16
|
1780 };
|
Chris@16
|
1781
|
Chris@16
|
1782 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1783 template<class T, class ...Options>
|
Chris@16
|
1784 #else
|
Chris@16
|
1785 template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType>
|
Chris@16
|
1786 #endif
|
Chris@16
|
1787 inline bool operator<
|
Chris@16
|
1788 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1789 (const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y)
|
Chris@16
|
1790 #else
|
Chris@16
|
1791 ( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &x
|
Chris@16
|
1792 , const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &y)
|
Chris@16
|
1793 #endif
|
Chris@16
|
1794 { return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
|
Chris@16
|
1795
|
Chris@16
|
1796 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1797 template<class T, class ...Options>
|
Chris@16
|
1798 #else
|
Chris@16
|
1799 template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType>
|
Chris@16
|
1800 #endif
|
Chris@16
|
1801 bool operator==
|
Chris@16
|
1802 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1803 (const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y)
|
Chris@16
|
1804 #else
|
Chris@16
|
1805 ( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &x
|
Chris@16
|
1806 , const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &y)
|
Chris@16
|
1807 #endif
|
Chris@16
|
1808 {
|
Chris@16
|
1809 typedef bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> tree_type;
|
Chris@16
|
1810 typedef typename tree_type::const_iterator const_iterator;
|
Chris@16
|
1811
|
Chris@16
|
1812 if(tree_type::constant_time_size && x.size() != y.size()){
|
Chris@16
|
1813 return false;
|
Chris@16
|
1814 }
|
Chris@16
|
1815 const_iterator end1 = x.end();
|
Chris@16
|
1816 const_iterator i1 = x.begin();
|
Chris@16
|
1817 const_iterator i2 = y.begin();
|
Chris@16
|
1818 if(tree_type::constant_time_size){
|
Chris@16
|
1819 while (i1 != end1 && *i1 == *i2) {
|
Chris@16
|
1820 ++i1;
|
Chris@16
|
1821 ++i2;
|
Chris@16
|
1822 }
|
Chris@16
|
1823 return i1 == end1;
|
Chris@16
|
1824 }
|
Chris@16
|
1825 else{
|
Chris@16
|
1826 const_iterator end2 = y.end();
|
Chris@16
|
1827 while (i1 != end1 && i2 != end2 && *i1 == *i2) {
|
Chris@16
|
1828 ++i1;
|
Chris@16
|
1829 ++i2;
|
Chris@16
|
1830 }
|
Chris@16
|
1831 return i1 == end1 && i2 == end2;
|
Chris@16
|
1832 }
|
Chris@16
|
1833 }
|
Chris@16
|
1834
|
Chris@16
|
1835 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1836 template<class T, class ...Options>
|
Chris@16
|
1837 #else
|
Chris@16
|
1838 template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType>
|
Chris@16
|
1839 #endif
|
Chris@16
|
1840 inline bool operator!=
|
Chris@16
|
1841 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1842 (const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y)
|
Chris@16
|
1843 #else
|
Chris@16
|
1844 ( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &x
|
Chris@16
|
1845 , const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &y)
|
Chris@16
|
1846 #endif
|
Chris@16
|
1847 { return !(x == y); }
|
Chris@16
|
1848
|
Chris@16
|
1849 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1850 template<class T, class ...Options>
|
Chris@16
|
1851 #else
|
Chris@16
|
1852 template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType>
|
Chris@16
|
1853 #endif
|
Chris@16
|
1854 inline bool operator>
|
Chris@16
|
1855 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1856 (const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y)
|
Chris@16
|
1857 #else
|
Chris@16
|
1858 ( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &x
|
Chris@16
|
1859 , const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &y)
|
Chris@16
|
1860 #endif
|
Chris@16
|
1861 { return y < x; }
|
Chris@16
|
1862
|
Chris@16
|
1863 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1864 template<class T, class ...Options>
|
Chris@16
|
1865 #else
|
Chris@16
|
1866 template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType>
|
Chris@16
|
1867 #endif
|
Chris@16
|
1868 inline bool operator<=
|
Chris@16
|
1869 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1870 (const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y)
|
Chris@16
|
1871 #else
|
Chris@16
|
1872 ( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &x
|
Chris@16
|
1873 , const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &y)
|
Chris@16
|
1874 #endif
|
Chris@16
|
1875 { return !(y < x); }
|
Chris@16
|
1876
|
Chris@16
|
1877 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1878 template<class T, class ...Options>
|
Chris@16
|
1879 #else
|
Chris@16
|
1880 template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType>
|
Chris@16
|
1881 #endif
|
Chris@16
|
1882 inline bool operator>=
|
Chris@16
|
1883 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1884 (const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y)
|
Chris@16
|
1885 #else
|
Chris@16
|
1886 ( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &x
|
Chris@16
|
1887 , const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &y)
|
Chris@16
|
1888 #endif
|
Chris@16
|
1889 { return !(x < y); }
|
Chris@16
|
1890
|
Chris@16
|
1891 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1892 template<class T, class ...Options>
|
Chris@16
|
1893 #else
|
Chris@16
|
1894 template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType>
|
Chris@16
|
1895 #endif
|
Chris@16
|
1896 inline void swap
|
Chris@16
|
1897 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1898 (bstree_impl<T, Options...> &x, bstree_impl<T, Options...> &y)
|
Chris@16
|
1899 #else
|
Chris@16
|
1900 ( bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &x
|
Chris@16
|
1901 , bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType> &y)
|
Chris@16
|
1902 #endif
|
Chris@16
|
1903 { x.swap(y); }
|
Chris@16
|
1904
|
Chris@16
|
1905 //! Helper metafunction to define a \c bstree that yields to the same type when the
|
Chris@16
|
1906 //! same options (either explicitly or implicitly) are used.
|
Chris@16
|
1907 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
1908 template<class T, class ...Options>
|
Chris@16
|
1909 #else
|
Chris@16
|
1910 template<class T, class O1 = void, class O2 = void
|
Chris@16
|
1911 , class O3 = void, class O4 = void>
|
Chris@16
|
1912 #endif
|
Chris@16
|
1913 struct make_bstree
|
Chris@16
|
1914 {
|
Chris@16
|
1915 /// @cond
|
Chris@16
|
1916 typedef typename pack_options
|
Chris@16
|
1917 < bstree_defaults,
|
Chris@16
|
1918 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
1919 O1, O2, O3, O4
|
Chris@16
|
1920 #else
|
Chris@16
|
1921 Options...
|
Chris@16
|
1922 #endif
|
Chris@16
|
1923 >::type packed_options;
|
Chris@16
|
1924
|
Chris@16
|
1925 typedef typename detail::get_value_traits
|
Chris@16
|
1926 <T, typename packed_options::proto_value_traits>::type value_traits;
|
Chris@16
|
1927
|
Chris@16
|
1928 typedef bstree_impl
|
Chris@16
|
1929 < value_traits
|
Chris@16
|
1930 , typename packed_options::compare
|
Chris@16
|
1931 , typename packed_options::size_type
|
Chris@16
|
1932 , packed_options::constant_time_size
|
Chris@16
|
1933 , BsTreeAlgorithms
|
Chris@16
|
1934 > implementation_defined;
|
Chris@16
|
1935 /// @endcond
|
Chris@16
|
1936 typedef implementation_defined type;
|
Chris@16
|
1937 };
|
Chris@16
|
1938
|
Chris@16
|
1939
|
Chris@16
|
1940 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
1941
|
Chris@16
|
1942 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
1943 template<class T, class O1, class O2, class O3, class O4>
|
Chris@16
|
1944 #else
|
Chris@16
|
1945 template<class T, class ...Options>
|
Chris@16
|
1946 #endif
|
Chris@16
|
1947 class bstree
|
Chris@16
|
1948 : public make_bstree<T,
|
Chris@16
|
1949 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
1950 O1, O2, O3, O4
|
Chris@16
|
1951 #else
|
Chris@16
|
1952 Options...
|
Chris@16
|
1953 #endif
|
Chris@16
|
1954 >::type
|
Chris@16
|
1955 {
|
Chris@16
|
1956 typedef typename make_bstree
|
Chris@16
|
1957 <T,
|
Chris@16
|
1958 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
1959 O1, O2, O3, O4
|
Chris@16
|
1960 #else
|
Chris@16
|
1961 Options...
|
Chris@16
|
1962 #endif
|
Chris@16
|
1963 >::type Base;
|
Chris@16
|
1964 BOOST_MOVABLE_BUT_NOT_COPYABLE(bstree)
|
Chris@16
|
1965
|
Chris@16
|
1966 public:
|
Chris@16
|
1967 typedef typename Base::value_compare value_compare;
|
Chris@16
|
1968 typedef typename Base::value_traits value_traits;
|
Chris@16
|
1969 typedef typename Base::real_value_traits real_value_traits;
|
Chris@16
|
1970 typedef typename Base::iterator iterator;
|
Chris@16
|
1971 typedef typename Base::const_iterator const_iterator;
|
Chris@16
|
1972
|
Chris@16
|
1973 //Assert if passed value traits are compatible with the type
|
Chris@16
|
1974 BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
|
Chris@16
|
1975
|
Chris@16
|
1976 bstree( const value_compare &cmp = value_compare()
|
Chris@16
|
1977 , const value_traits &v_traits = value_traits())
|
Chris@16
|
1978 : Base(cmp, v_traits)
|
Chris@16
|
1979 {}
|
Chris@16
|
1980
|
Chris@16
|
1981 template<class Iterator>
|
Chris@16
|
1982 bstree( bool unique, Iterator b, Iterator e
|
Chris@16
|
1983 , const value_compare &cmp = value_compare()
|
Chris@16
|
1984 , const value_traits &v_traits = value_traits())
|
Chris@16
|
1985 : Base(unique, b, e, cmp, v_traits)
|
Chris@16
|
1986 {}
|
Chris@16
|
1987
|
Chris@16
|
1988 bstree(BOOST_RV_REF(bstree) x)
|
Chris@16
|
1989 : Base(::boost::move(static_cast<Base&>(x)))
|
Chris@16
|
1990 {}
|
Chris@16
|
1991
|
Chris@16
|
1992 bstree& operator=(BOOST_RV_REF(bstree) x)
|
Chris@16
|
1993 { return static_cast<bstree &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); }
|
Chris@16
|
1994
|
Chris@16
|
1995 static bstree &container_from_end_iterator(iterator end_iterator)
|
Chris@16
|
1996 { return static_cast<bstree &>(Base::container_from_end_iterator(end_iterator)); }
|
Chris@16
|
1997
|
Chris@16
|
1998 static const bstree &container_from_end_iterator(const_iterator end_iterator)
|
Chris@16
|
1999 { return static_cast<const bstree &>(Base::container_from_end_iterator(end_iterator)); }
|
Chris@16
|
2000
|
Chris@16
|
2001 static bstree &container_from_iterator(iterator it)
|
Chris@16
|
2002 { return static_cast<bstree &>(Base::container_from_iterator(it)); }
|
Chris@16
|
2003
|
Chris@16
|
2004 static const bstree &container_from_iterator(const_iterator it)
|
Chris@16
|
2005 { return static_cast<const bstree &>(Base::container_from_iterator(it)); }
|
Chris@16
|
2006 };
|
Chris@16
|
2007
|
Chris@16
|
2008 #endif
|
Chris@16
|
2009 } //namespace intrusive
|
Chris@16
|
2010 } //namespace boost
|
Chris@16
|
2011
|
Chris@16
|
2012 #include <boost/intrusive/detail/config_end.hpp>
|
Chris@16
|
2013
|
Chris@16
|
2014 #endif //BOOST_INTRUSIVE_BSTREE_HPP
|