Chris@16
|
1 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Ion Gaztanaga 2007-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 //
|
Chris@16
|
13 // The option that yields to non-floating point 1/sqrt(2) alpha is taken
|
Chris@16
|
14 // from the scapegoat tree implementation of the PSPP library.
|
Chris@16
|
15 //
|
Chris@16
|
16 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
17
|
Chris@16
|
18 #ifndef BOOST_INTRUSIVE_SGTREE_HPP
|
Chris@16
|
19 #define BOOST_INTRUSIVE_SGTREE_HPP
|
Chris@16
|
20
|
Chris@16
|
21 #include <boost/intrusive/detail/config_begin.hpp>
|
Chris@16
|
22 #include <algorithm>
|
Chris@16
|
23 #include <cstddef>
|
Chris@16
|
24 #include <functional>
|
Chris@16
|
25 #include <iterator>
|
Chris@16
|
26 #include <utility>
|
Chris@16
|
27 #include <cmath>
|
Chris@16
|
28 #include <cstddef>
|
Chris@16
|
29 #include <boost/intrusive/detail/assert.hpp>
|
Chris@16
|
30 #include <boost/static_assert.hpp>
|
Chris@16
|
31 #include <boost/intrusive/intrusive_fwd.hpp>
|
Chris@16
|
32 #include <boost/intrusive/bs_set_hook.hpp>
|
Chris@16
|
33 #include <boost/intrusive/bstree.hpp>
|
Chris@16
|
34 #include <boost/intrusive/detail/tree_node.hpp>
|
Chris@16
|
35 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
|
Chris@16
|
36 #include <boost/intrusive/pointer_traits.hpp>
|
Chris@16
|
37 #include <boost/intrusive/detail/mpl.hpp>
|
Chris@16
|
38 #include <boost/intrusive/detail/utilities.hpp>
|
Chris@16
|
39 #include <boost/intrusive/options.hpp>
|
Chris@16
|
40 #include <boost/intrusive/sgtree_algorithms.hpp>
|
Chris@16
|
41 #include <boost/intrusive/link_mode.hpp>
|
Chris@16
|
42 #include <boost/move/move.hpp>
|
Chris@16
|
43
|
Chris@16
|
44 namespace boost {
|
Chris@16
|
45 namespace intrusive {
|
Chris@16
|
46
|
Chris@16
|
47 /// @cond
|
Chris@16
|
48
|
Chris@16
|
49 namespace detail{
|
Chris@16
|
50
|
Chris@16
|
51 //! Returns floor(log2(n)/log2(sqrt(2))) -> floor(2*log2(n))
|
Chris@16
|
52 //! Undefined if N is 0.
|
Chris@16
|
53 //!
|
Chris@16
|
54 //! This function does not use float point operations.
|
Chris@16
|
55 inline std::size_t calculate_h_sqrt2 (std::size_t n)
|
Chris@16
|
56 {
|
Chris@16
|
57 std::size_t f_log2 = detail::floor_log2(n);
|
Chris@16
|
58 return (2*f_log2) + (n >= detail::sqrt2_pow_2xplus1 (f_log2));
|
Chris@16
|
59 }
|
Chris@16
|
60
|
Chris@16
|
61 struct h_alpha_sqrt2_t
|
Chris@16
|
62 {
|
Chris@16
|
63 h_alpha_sqrt2_t(void){}
|
Chris@16
|
64 std::size_t operator()(std::size_t n) const
|
Chris@16
|
65 { return calculate_h_sqrt2(n); }
|
Chris@16
|
66 };
|
Chris@16
|
67
|
Chris@16
|
68 struct alpha_0_75_by_max_size_t
|
Chris@16
|
69 {
|
Chris@16
|
70 alpha_0_75_by_max_size_t(void){}
|
Chris@16
|
71
|
Chris@16
|
72 std::size_t operator()(std::size_t max_tree_size) const
|
Chris@16
|
73 {
|
Chris@16
|
74 const std::size_t max_tree_size_limit = ((~std::size_t(0))/std::size_t(3));
|
Chris@16
|
75 return max_tree_size > max_tree_size_limit ? max_tree_size/4*3 : max_tree_size*3/4;
|
Chris@16
|
76 }
|
Chris@16
|
77 };
|
Chris@16
|
78
|
Chris@16
|
79 struct h_alpha_t
|
Chris@16
|
80 {
|
Chris@16
|
81 explicit h_alpha_t(float inv_minus_logalpha)
|
Chris@16
|
82 : inv_minus_logalpha_(inv_minus_logalpha)
|
Chris@16
|
83 {}
|
Chris@16
|
84
|
Chris@16
|
85 std::size_t operator()(std::size_t n) const
|
Chris@16
|
86 {
|
Chris@16
|
87 //Returns floor(log2(1/alpha(n))) ->
|
Chris@16
|
88 // floor(log2(n)/log(1/alpha)) ->
|
Chris@16
|
89 // floor(log2(n)/(-log2(alpha)))
|
Chris@16
|
90 //return static_cast<std::size_t>(std::log(float(n))*inv_minus_logalpha_);
|
Chris@16
|
91 return static_cast<std::size_t>(detail::fast_log2(float(n))*inv_minus_logalpha_);
|
Chris@16
|
92 }
|
Chris@16
|
93
|
Chris@16
|
94 private:
|
Chris@16
|
95 //Since the function will be repeatedly called
|
Chris@16
|
96 //precalculate constant data to avoid repeated
|
Chris@16
|
97 //calls to log and division.
|
Chris@16
|
98 //This will store 1/(-std::log2(alpha_))
|
Chris@16
|
99 float inv_minus_logalpha_;
|
Chris@16
|
100 };
|
Chris@16
|
101
|
Chris@16
|
102 struct alpha_by_max_size_t
|
Chris@16
|
103 {
|
Chris@16
|
104 explicit alpha_by_max_size_t(float alpha)
|
Chris@16
|
105 : alpha_(alpha)
|
Chris@16
|
106 {}
|
Chris@16
|
107
|
Chris@16
|
108 float operator()(std::size_t max_tree_size) const
|
Chris@16
|
109 { return float(max_tree_size)*alpha_; }
|
Chris@16
|
110
|
Chris@16
|
111 private:
|
Chris@16
|
112 float alpha_;
|
Chris@16
|
113 };
|
Chris@16
|
114
|
Chris@16
|
115 template<bool Activate, class SizeType>
|
Chris@16
|
116 struct alpha_holder
|
Chris@16
|
117 {
|
Chris@16
|
118 typedef boost::intrusive::detail::h_alpha_t h_alpha_t;
|
Chris@16
|
119 typedef boost::intrusive::detail::alpha_by_max_size_t multiply_by_alpha_t;
|
Chris@16
|
120
|
Chris@16
|
121 alpha_holder() : max_tree_size_(0)
|
Chris@16
|
122 { set_alpha(0.7f); }
|
Chris@16
|
123
|
Chris@16
|
124 float get_alpha() const
|
Chris@16
|
125 { return alpha_; }
|
Chris@16
|
126
|
Chris@16
|
127 void set_alpha(float alpha)
|
Chris@16
|
128 {
|
Chris@16
|
129 alpha_ = alpha;
|
Chris@16
|
130 inv_minus_logalpha_ = 1/(-detail::fast_log2(alpha));
|
Chris@16
|
131 }
|
Chris@16
|
132
|
Chris@16
|
133 h_alpha_t get_h_alpha_t() const
|
Chris@16
|
134 { return h_alpha_t(/*alpha_, */inv_minus_logalpha_); }
|
Chris@16
|
135
|
Chris@16
|
136 multiply_by_alpha_t get_multiply_by_alpha_t() const
|
Chris@16
|
137 { return multiply_by_alpha_t(alpha_); }
|
Chris@16
|
138
|
Chris@16
|
139 protected:
|
Chris@16
|
140 float alpha_;
|
Chris@16
|
141 float inv_minus_logalpha_;
|
Chris@16
|
142 SizeType max_tree_size_;
|
Chris@16
|
143 };
|
Chris@16
|
144
|
Chris@16
|
145 template<class SizeType>
|
Chris@16
|
146 struct alpha_holder<false, SizeType>
|
Chris@16
|
147 {
|
Chris@16
|
148 //This specialization uses alpha = 1/sqrt(2)
|
Chris@16
|
149 //without using floating point operations
|
Chris@16
|
150 //Downside: alpha CAN't be changed.
|
Chris@16
|
151 typedef boost::intrusive::detail::h_alpha_sqrt2_t h_alpha_t;
|
Chris@16
|
152 typedef boost::intrusive::detail::alpha_0_75_by_max_size_t multiply_by_alpha_t;
|
Chris@16
|
153
|
Chris@16
|
154 float get_alpha() const
|
Chris@16
|
155 { return 0.70710677f; }
|
Chris@16
|
156
|
Chris@16
|
157 void set_alpha(float)
|
Chris@16
|
158 { //alpha CAN't be changed.
|
Chris@16
|
159 BOOST_INTRUSIVE_INVARIANT_ASSERT(0);
|
Chris@16
|
160 }
|
Chris@16
|
161
|
Chris@16
|
162 h_alpha_t get_h_alpha_t() const
|
Chris@16
|
163 { return h_alpha_t(); }
|
Chris@16
|
164
|
Chris@16
|
165 multiply_by_alpha_t get_multiply_by_alpha_t() const
|
Chris@16
|
166 { return multiply_by_alpha_t(); }
|
Chris@16
|
167
|
Chris@16
|
168 SizeType max_tree_size_;
|
Chris@16
|
169 };
|
Chris@16
|
170
|
Chris@16
|
171 } //namespace detail{
|
Chris@16
|
172
|
Chris@16
|
173 struct sgtree_defaults
|
Chris@16
|
174 {
|
Chris@16
|
175 typedef detail::default_bstree_hook proto_value_traits;
|
Chris@16
|
176 static const bool constant_time_size = true;
|
Chris@16
|
177 typedef std::size_t size_type;
|
Chris@16
|
178 typedef void compare;
|
Chris@16
|
179 static const bool floating_point = true;
|
Chris@16
|
180 };
|
Chris@16
|
181
|
Chris@16
|
182 /// @endcond
|
Chris@16
|
183
|
Chris@16
|
184 //! The class template sgtree is an intrusive scapegoat tree container, that
|
Chris@16
|
185 //! is used to construct intrusive sg_set and sg_multiset containers.
|
Chris@16
|
186 //! The no-throw guarantee holds only, if the value_compare object
|
Chris@16
|
187 //! doesn't throw.
|
Chris@16
|
188 //!
|
Chris@16
|
189 //! The template parameter \c T is the type to be managed by the container.
|
Chris@16
|
190 //! The user can specify additional options and if no options are provided
|
Chris@16
|
191 //! default options are used.
|
Chris@16
|
192 //!
|
Chris@16
|
193 //! The container supports the following options:
|
Chris@16
|
194 //! \c base_hook<>/member_hook<>/value_traits<>,
|
Chris@16
|
195 //! \c floating_point<>, \c size_type<> and
|
Chris@16
|
196 //! \c compare<>.
|
Chris@16
|
197 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
198 template<class T, class ...Options>
|
Chris@16
|
199 #else
|
Chris@16
|
200 template<class ValueTraits, class VoidOrKeyComp, class SizeType, bool FloatingPoint>
|
Chris@16
|
201 #endif
|
Chris@16
|
202 class sgtree_impl
|
Chris@16
|
203 /// @cond
|
Chris@16
|
204 : public bstree_impl<ValueTraits, VoidOrKeyComp, SizeType, true, SgTreeAlgorithms>
|
Chris@16
|
205 , public detail::alpha_holder<FloatingPoint, SizeType>
|
Chris@16
|
206 /// @endcond
|
Chris@16
|
207 {
|
Chris@16
|
208 public:
|
Chris@16
|
209 typedef ValueTraits value_traits;
|
Chris@16
|
210 /// @cond
|
Chris@16
|
211 typedef bstree_impl< ValueTraits, VoidOrKeyComp, SizeType
|
Chris@16
|
212 , true, SgTreeAlgorithms> tree_type;
|
Chris@16
|
213 typedef tree_type implementation_defined;
|
Chris@16
|
214 typedef typename tree_type::real_value_traits real_value_traits;
|
Chris@16
|
215
|
Chris@16
|
216 /// @endcond
|
Chris@16
|
217
|
Chris@16
|
218 typedef typename implementation_defined::pointer pointer;
|
Chris@16
|
219 typedef typename implementation_defined::const_pointer const_pointer;
|
Chris@16
|
220 typedef typename implementation_defined::value_type value_type;
|
Chris@16
|
221 typedef typename implementation_defined::key_type key_type;
|
Chris@16
|
222 typedef typename implementation_defined::reference reference;
|
Chris@16
|
223 typedef typename implementation_defined::const_reference const_reference;
|
Chris@16
|
224 typedef typename implementation_defined::difference_type difference_type;
|
Chris@16
|
225 typedef typename implementation_defined::size_type size_type;
|
Chris@16
|
226 typedef typename implementation_defined::value_compare value_compare;
|
Chris@16
|
227 typedef typename implementation_defined::key_compare key_compare;
|
Chris@16
|
228 typedef typename implementation_defined::iterator iterator;
|
Chris@16
|
229 typedef typename implementation_defined::const_iterator const_iterator;
|
Chris@16
|
230 typedef typename implementation_defined::reverse_iterator reverse_iterator;
|
Chris@16
|
231 typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
|
Chris@16
|
232 typedef typename implementation_defined::node_traits node_traits;
|
Chris@16
|
233 typedef typename implementation_defined::node node;
|
Chris@16
|
234 typedef typename implementation_defined::node_ptr node_ptr;
|
Chris@16
|
235 typedef typename implementation_defined::const_node_ptr const_node_ptr;
|
Chris@16
|
236 typedef BOOST_INTRUSIVE_IMPDEF(sgtree_algorithms<node_traits>) node_algorithms;
|
Chris@16
|
237
|
Chris@16
|
238 static const bool constant_time_size = implementation_defined::constant_time_size;
|
Chris@16
|
239 static const bool floating_point = FloatingPoint;
|
Chris@16
|
240 static const bool stateful_value_traits = implementation_defined::stateful_value_traits;
|
Chris@16
|
241
|
Chris@16
|
242 /// @cond
|
Chris@16
|
243 private:
|
Chris@16
|
244
|
Chris@16
|
245 //noncopyable
|
Chris@16
|
246 typedef detail::alpha_holder<FloatingPoint, SizeType> alpha_traits;
|
Chris@16
|
247 typedef typename alpha_traits::h_alpha_t h_alpha_t;
|
Chris@16
|
248 typedef typename alpha_traits::multiply_by_alpha_t multiply_by_alpha_t;
|
Chris@16
|
249
|
Chris@16
|
250 BOOST_MOVABLE_BUT_NOT_COPYABLE(sgtree_impl)
|
Chris@16
|
251 BOOST_STATIC_ASSERT(((int)real_value_traits::link_mode != (int)auto_unlink));
|
Chris@16
|
252
|
Chris@16
|
253 enum { safemode_or_autounlink =
|
Chris@16
|
254 (int)real_value_traits::link_mode == (int)auto_unlink ||
|
Chris@16
|
255 (int)real_value_traits::link_mode == (int)safe_link };
|
Chris@16
|
256
|
Chris@16
|
257 /// @endcond
|
Chris@16
|
258
|
Chris@16
|
259 public:
|
Chris@16
|
260
|
Chris@16
|
261 typedef BOOST_INTRUSIVE_IMPDEF(typename node_algorithms::insert_commit_data) insert_commit_data;
|
Chris@16
|
262
|
Chris@16
|
263 //! @copydoc ::boost::intrusive::bstree::bstree(const value_compare &,const value_traits &)
|
Chris@16
|
264 explicit sgtree_impl( const value_compare &cmp = value_compare()
|
Chris@16
|
265 , const value_traits &v_traits = value_traits())
|
Chris@16
|
266 : tree_type(cmp, v_traits)
|
Chris@16
|
267 {}
|
Chris@16
|
268
|
Chris@16
|
269 //! @copydoc ::boost::intrusive::bstree::bstree(bool,Iterator,Iterator,const value_compare &,const value_traits &)
|
Chris@16
|
270 template<class Iterator>
|
Chris@16
|
271 sgtree_impl( bool unique, Iterator b, Iterator e
|
Chris@16
|
272 , const value_compare &cmp = value_compare()
|
Chris@16
|
273 , const value_traits &v_traits = value_traits())
|
Chris@16
|
274 : tree_type(cmp, v_traits)
|
Chris@16
|
275 {
|
Chris@16
|
276 if(unique)
|
Chris@16
|
277 this->insert_unique(b, e);
|
Chris@16
|
278 else
|
Chris@16
|
279 this->insert_equal(b, e);
|
Chris@16
|
280 }
|
Chris@16
|
281
|
Chris@16
|
282 //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&)
|
Chris@16
|
283 sgtree_impl(BOOST_RV_REF(sgtree_impl) x)
|
Chris@16
|
284 : tree_type(::boost::move(static_cast<tree_type&>(x))), alpha_traits(x.get_alpha_traits())
|
Chris@16
|
285 { std::swap(this->get_alpha_traits(), x.get_alpha_traits()); }
|
Chris@16
|
286
|
Chris@16
|
287 //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&)
|
Chris@16
|
288 sgtree_impl& operator=(BOOST_RV_REF(sgtree_impl) x)
|
Chris@16
|
289 {
|
Chris@16
|
290 this->get_alpha_traits() = x.get_alpha_traits();
|
Chris@16
|
291 return static_cast<sgtree_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x))));
|
Chris@16
|
292 }
|
Chris@16
|
293
|
Chris@16
|
294 /// @cond
|
Chris@16
|
295 private:
|
Chris@16
|
296
|
Chris@16
|
297 const alpha_traits &get_alpha_traits() const
|
Chris@16
|
298 { return *this; }
|
Chris@16
|
299
|
Chris@16
|
300 alpha_traits &get_alpha_traits()
|
Chris@16
|
301 { return *this; }
|
Chris@16
|
302
|
Chris@16
|
303 h_alpha_t get_h_alpha_func() const
|
Chris@16
|
304 { return this->get_alpha_traits().get_h_alpha_t(); }
|
Chris@16
|
305
|
Chris@16
|
306 multiply_by_alpha_t get_alpha_by_max_size_func() const
|
Chris@16
|
307 { return this->get_alpha_traits().get_multiply_by_alpha_t(); }
|
Chris@16
|
308
|
Chris@16
|
309 /// @endcond
|
Chris@16
|
310
|
Chris@16
|
311 public:
|
Chris@16
|
312
|
Chris@16
|
313 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
314 //! @copydoc ::boost::intrusive::bstree::~bstree()
|
Chris@16
|
315 ~sgtree_impl();
|
Chris@16
|
316
|
Chris@16
|
317 //! @copydoc ::boost::intrusive::bstree::begin()
|
Chris@16
|
318 iterator begin();
|
Chris@16
|
319
|
Chris@16
|
320 //! @copydoc ::boost::intrusive::bstree::begin()const
|
Chris@16
|
321 const_iterator begin() const;
|
Chris@16
|
322
|
Chris@16
|
323 //! @copydoc ::boost::intrusive::bstree::cbegin()const
|
Chris@16
|
324 const_iterator cbegin() const;
|
Chris@16
|
325
|
Chris@16
|
326 //! @copydoc ::boost::intrusive::bstree::end()
|
Chris@16
|
327 iterator end();
|
Chris@16
|
328
|
Chris@16
|
329 //! @copydoc ::boost::intrusive::bstree::end()const
|
Chris@16
|
330 const_iterator end() const;
|
Chris@16
|
331
|
Chris@16
|
332 //! @copydoc ::boost::intrusive::bstree::cend()const
|
Chris@16
|
333 const_iterator cend() const;
|
Chris@16
|
334
|
Chris@16
|
335 //! @copydoc ::boost::intrusive::bstree::rbegin()
|
Chris@16
|
336 reverse_iterator rbegin();
|
Chris@16
|
337
|
Chris@16
|
338 //! @copydoc ::boost::intrusive::bstree::rbegin()const
|
Chris@16
|
339 const_reverse_iterator rbegin() const;
|
Chris@16
|
340
|
Chris@16
|
341 //! @copydoc ::boost::intrusive::bstree::crbegin()const
|
Chris@16
|
342 const_reverse_iterator crbegin() const;
|
Chris@16
|
343
|
Chris@16
|
344 //! @copydoc ::boost::intrusive::bstree::rend()
|
Chris@16
|
345 reverse_iterator rend();
|
Chris@16
|
346
|
Chris@16
|
347 //! @copydoc ::boost::intrusive::bstree::rend()const
|
Chris@16
|
348 const_reverse_iterator rend() const;
|
Chris@16
|
349
|
Chris@16
|
350 //! @copydoc ::boost::intrusive::bstree::crend()const
|
Chris@16
|
351 const_reverse_iterator crend() const;
|
Chris@16
|
352
|
Chris@16
|
353 //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator)
|
Chris@16
|
354 static sgtree_impl &container_from_end_iterator(iterator end_iterator);
|
Chris@16
|
355
|
Chris@16
|
356 //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator)
|
Chris@16
|
357 static const sgtree_impl &container_from_end_iterator(const_iterator end_iterator);
|
Chris@16
|
358
|
Chris@16
|
359 //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator)
|
Chris@16
|
360 static sgtree_impl &container_from_iterator(iterator it);
|
Chris@16
|
361
|
Chris@16
|
362 //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator)
|
Chris@16
|
363 static const sgtree_impl &container_from_iterator(const_iterator it);
|
Chris@16
|
364
|
Chris@16
|
365 //! @copydoc ::boost::intrusive::bstree::key_comp()const
|
Chris@16
|
366 key_compare key_comp() const;
|
Chris@16
|
367
|
Chris@16
|
368 //! @copydoc ::boost::intrusive::bstree::value_comp()const
|
Chris@16
|
369 value_compare value_comp() const;
|
Chris@16
|
370
|
Chris@16
|
371 //! @copydoc ::boost::intrusive::bstree::empty()const
|
Chris@16
|
372 bool empty() const;
|
Chris@16
|
373
|
Chris@16
|
374 //! @copydoc ::boost::intrusive::bstree::size()const
|
Chris@16
|
375 size_type size() const;
|
Chris@16
|
376
|
Chris@16
|
377 #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
378
|
Chris@16
|
379 //! @copydoc ::boost::intrusive::bstree::swap
|
Chris@16
|
380 void swap(sgtree_impl& other)
|
Chris@16
|
381 {
|
Chris@16
|
382 //This can throw
|
Chris@16
|
383 using std::swap;
|
Chris@16
|
384 this->tree_type::swap(static_cast<tree_type&>(other));
|
Chris@16
|
385 swap(this->get_alpha_traits(), other.get_alpha_traits());
|
Chris@16
|
386 }
|
Chris@16
|
387
|
Chris@16
|
388 //! @copydoc ::boost::intrusive::bstree::clone_from
|
Chris@16
|
389 //! Additional notes: it also copies the alpha factor from the source container.
|
Chris@16
|
390 template <class Cloner, class Disposer>
|
Chris@16
|
391 void clone_from(const sgtree_impl &src, Cloner cloner, Disposer disposer)
|
Chris@16
|
392 {
|
Chris@16
|
393 this->tree_type::clone_from(src, cloner, disposer);
|
Chris@16
|
394 this->get_alpha_traits() = src.get_alpha_traits();
|
Chris@16
|
395 }
|
Chris@16
|
396
|
Chris@16
|
397 //! @copydoc ::boost::intrusive::bstree::insert_equal(reference)
|
Chris@16
|
398 iterator insert_equal(reference value)
|
Chris@16
|
399 {
|
Chris@16
|
400 detail::key_nodeptr_comp<value_compare, real_value_traits>
|
Chris@16
|
401 key_node_comp(this->value_comp(), &this->get_real_value_traits());
|
Chris@16
|
402 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
403 if(safemode_or_autounlink)
|
Chris@16
|
404 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
405 std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
|
Chris@16
|
406 node_ptr p = node_algorithms::insert_equal_upper_bound
|
Chris@16
|
407 (this->tree_type::header_ptr(), to_insert, key_node_comp
|
Chris@16
|
408 , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size);
|
Chris@16
|
409 this->tree_type::sz_traits().increment();
|
Chris@16
|
410 this->max_tree_size_ = (size_type)max_tree_size;
|
Chris@16
|
411 return iterator(p, this->real_value_traits_ptr());
|
Chris@16
|
412 }
|
Chris@16
|
413
|
Chris@16
|
414 //! @copydoc ::boost::intrusive::bstree::insert_equal(const_iterator,reference)
|
Chris@16
|
415 iterator insert_equal(const_iterator hint, reference value)
|
Chris@16
|
416 {
|
Chris@16
|
417 detail::key_nodeptr_comp<value_compare, real_value_traits>
|
Chris@16
|
418 key_node_comp(this->value_comp(), &this->get_real_value_traits());
|
Chris@16
|
419 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
420 if(safemode_or_autounlink)
|
Chris@16
|
421 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
422 std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
|
Chris@16
|
423 node_ptr p = node_algorithms::insert_equal
|
Chris@16
|
424 (this->tree_type::header_ptr(), hint.pointed_node(), to_insert, key_node_comp
|
Chris@16
|
425 , (std::size_t)this->size(), this->get_h_alpha_func(), max_tree_size);
|
Chris@16
|
426 this->tree_type::sz_traits().increment();
|
Chris@16
|
427 this->max_tree_size_ = (size_type)max_tree_size;
|
Chris@16
|
428 return iterator(p, this->real_value_traits_ptr());
|
Chris@16
|
429 }
|
Chris@16
|
430
|
Chris@16
|
431 //! @copydoc ::boost::intrusive::bstree::insert_equal(Iterator,Iterator)
|
Chris@16
|
432 template<class Iterator>
|
Chris@16
|
433 void insert_equal(Iterator b, Iterator e)
|
Chris@16
|
434 {
|
Chris@16
|
435 iterator iend(this->end());
|
Chris@16
|
436 for (; b != e; ++b)
|
Chris@16
|
437 this->insert_equal(iend, *b);
|
Chris@16
|
438 }
|
Chris@16
|
439
|
Chris@16
|
440 //! @copydoc ::boost::intrusive::bstree::insert_unique(reference)
|
Chris@16
|
441 std::pair<iterator, bool> insert_unique(reference value)
|
Chris@16
|
442 {
|
Chris@16
|
443 insert_commit_data commit_data;
|
Chris@16
|
444 std::pair<iterator, bool> ret = insert_unique_check(value, this->value_comp(), commit_data);
|
Chris@16
|
445 if(!ret.second)
|
Chris@16
|
446 return ret;
|
Chris@16
|
447 return std::pair<iterator, bool> (insert_unique_commit(value, commit_data), true);
|
Chris@16
|
448 }
|
Chris@16
|
449
|
Chris@16
|
450 //! @copydoc ::boost::intrusive::bstree::insert_unique(const_iterator,reference)
|
Chris@16
|
451 iterator insert_unique(const_iterator hint, reference value)
|
Chris@16
|
452 {
|
Chris@16
|
453 insert_commit_data commit_data;
|
Chris@16
|
454 std::pair<iterator, bool> ret = insert_unique_check(hint, value, this->value_comp(), commit_data);
|
Chris@16
|
455 if(!ret.second)
|
Chris@16
|
456 return ret.first;
|
Chris@16
|
457 return insert_unique_commit(value, commit_data);
|
Chris@16
|
458 }
|
Chris@16
|
459
|
Chris@16
|
460 //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const KeyType&,KeyValueCompare,insert_commit_data&)
|
Chris@16
|
461 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
462 std::pair<iterator, bool> insert_unique_check
|
Chris@16
|
463 (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data)
|
Chris@16
|
464 {
|
Chris@16
|
465 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
466 comp(key_value_comp, &this->get_real_value_traits());
|
Chris@16
|
467 std::pair<node_ptr, bool> ret =
|
Chris@16
|
468 (node_algorithms::insert_unique_check
|
Chris@16
|
469 (this->tree_type::header_ptr(), key, comp, commit_data));
|
Chris@16
|
470 return std::pair<iterator, bool>(iterator(ret.first, this->real_value_traits_ptr()), ret.second);
|
Chris@16
|
471 }
|
Chris@16
|
472
|
Chris@16
|
473 //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,insert_commit_data&)
|
Chris@16
|
474 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
475 std::pair<iterator, bool> insert_unique_check
|
Chris@16
|
476 (const_iterator hint, const KeyType &key
|
Chris@16
|
477 ,KeyValueCompare key_value_comp, insert_commit_data &commit_data)
|
Chris@16
|
478 {
|
Chris@16
|
479 detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
|
Chris@16
|
480 comp(key_value_comp, &this->get_real_value_traits());
|
Chris@16
|
481 std::pair<node_ptr, bool> ret =
|
Chris@16
|
482 (node_algorithms::insert_unique_check
|
Chris@16
|
483 (this->tree_type::header_ptr(), hint.pointed_node(), key, comp, commit_data));
|
Chris@16
|
484 return std::pair<iterator, bool>(iterator(ret.first, this->real_value_traits_ptr()), ret.second);
|
Chris@16
|
485 }
|
Chris@16
|
486
|
Chris@16
|
487 //! @copydoc ::boost::intrusive::bstree::insert_unique_commit
|
Chris@16
|
488 iterator insert_unique_commit(reference value, const insert_commit_data &commit_data)
|
Chris@16
|
489 {
|
Chris@16
|
490 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
491 if(safemode_or_autounlink)
|
Chris@16
|
492 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
493 std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
|
Chris@16
|
494 node_algorithms::insert_unique_commit
|
Chris@16
|
495 ( this->tree_type::header_ptr(), to_insert, commit_data
|
Chris@16
|
496 , (std::size_t)this->size(), this->get_h_alpha_func(), max_tree_size);
|
Chris@16
|
497 this->tree_type::sz_traits().increment();
|
Chris@16
|
498 this->max_tree_size_ = (size_type)max_tree_size;
|
Chris@16
|
499 return iterator(to_insert, this->real_value_traits_ptr());
|
Chris@16
|
500 }
|
Chris@16
|
501
|
Chris@16
|
502 //! @copydoc ::boost::intrusive::bstree::insert_unique(Iterator,Iterator)
|
Chris@16
|
503 template<class Iterator>
|
Chris@16
|
504 void insert_unique(Iterator b, Iterator e)
|
Chris@16
|
505 {
|
Chris@16
|
506 if(this->empty()){
|
Chris@16
|
507 iterator iend(this->end());
|
Chris@16
|
508 for (; b != e; ++b)
|
Chris@16
|
509 this->insert_unique(iend, *b);
|
Chris@16
|
510 }
|
Chris@16
|
511 else{
|
Chris@16
|
512 for (; b != e; ++b)
|
Chris@16
|
513 this->insert_unique(*b);
|
Chris@16
|
514 }
|
Chris@16
|
515 }
|
Chris@16
|
516
|
Chris@16
|
517 //! @copydoc ::boost::intrusive::bstree::insert_before
|
Chris@16
|
518 iterator insert_before(const_iterator pos, reference value)
|
Chris@16
|
519 {
|
Chris@16
|
520 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
521 if(safemode_or_autounlink)
|
Chris@16
|
522 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
523 std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
|
Chris@16
|
524 node_ptr p = node_algorithms::insert_before
|
Chris@16
|
525 ( this->tree_type::header_ptr(), pos.pointed_node(), to_insert
|
Chris@16
|
526 , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size);
|
Chris@16
|
527 this->tree_type::sz_traits().increment();
|
Chris@16
|
528 this->max_tree_size_ = (size_type)max_tree_size;
|
Chris@16
|
529 return iterator(p, this->real_value_traits_ptr());
|
Chris@16
|
530 }
|
Chris@16
|
531
|
Chris@16
|
532 //! @copydoc ::boost::intrusive::bstree::push_back
|
Chris@16
|
533 void push_back(reference value)
|
Chris@16
|
534 {
|
Chris@16
|
535 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
536 if(safemode_or_autounlink)
|
Chris@16
|
537 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
538 std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
|
Chris@16
|
539 node_algorithms::push_back
|
Chris@16
|
540 ( this->tree_type::header_ptr(), to_insert
|
Chris@16
|
541 , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size);
|
Chris@16
|
542 this->tree_type::sz_traits().increment();
|
Chris@16
|
543 this->max_tree_size_ = (size_type)max_tree_size;
|
Chris@16
|
544 }
|
Chris@16
|
545
|
Chris@16
|
546 //! @copydoc ::boost::intrusive::bstree::push_front
|
Chris@16
|
547 void push_front(reference value)
|
Chris@16
|
548 {
|
Chris@16
|
549 node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
|
Chris@16
|
550 if(safemode_or_autounlink)
|
Chris@16
|
551 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
552 std::size_t max_tree_size = (std::size_t)this->max_tree_size_;
|
Chris@16
|
553 node_algorithms::push_front
|
Chris@16
|
554 ( this->tree_type::header_ptr(), to_insert
|
Chris@16
|
555 , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size);
|
Chris@16
|
556 this->tree_type::sz_traits().increment();
|
Chris@16
|
557 this->max_tree_size_ = (size_type)max_tree_size;
|
Chris@16
|
558 }
|
Chris@16
|
559
|
Chris@16
|
560
|
Chris@16
|
561 //! @copydoc ::boost::intrusive::bstree::erase(const_iterator)
|
Chris@16
|
562 iterator erase(const_iterator i)
|
Chris@16
|
563 {
|
Chris@16
|
564 const_iterator ret(i);
|
Chris@16
|
565 ++ret;
|
Chris@16
|
566 node_ptr to_erase(i.pointed_node());
|
Chris@16
|
567 if(safemode_or_autounlink)
|
Chris@16
|
568 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase));
|
Chris@16
|
569 std::size_t max_tree_size = this->max_tree_size_;
|
Chris@16
|
570 node_algorithms::erase
|
Chris@16
|
571 ( this->tree_type::header_ptr(), to_erase, (std::size_t)this->size()
|
Chris@16
|
572 , max_tree_size, this->get_alpha_by_max_size_func());
|
Chris@16
|
573 this->max_tree_size_ = (size_type)max_tree_size;
|
Chris@16
|
574 this->tree_type::sz_traits().decrement();
|
Chris@16
|
575 if(safemode_or_autounlink)
|
Chris@16
|
576 node_algorithms::init(to_erase);
|
Chris@16
|
577 return ret.unconst();
|
Chris@16
|
578 }
|
Chris@16
|
579
|
Chris@16
|
580 //! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator)
|
Chris@16
|
581 iterator erase(const_iterator b, const_iterator e)
|
Chris@16
|
582 { size_type n; return private_erase(b, e, n); }
|
Chris@16
|
583
|
Chris@16
|
584 //! @copydoc ::boost::intrusive::bstree::erase(const_reference)
|
Chris@16
|
585 size_type erase(const_reference value)
|
Chris@16
|
586 { return this->erase(value, this->value_comp()); }
|
Chris@16
|
587
|
Chris@16
|
588 //! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyValueCompare)
|
Chris@16
|
589 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
590 size_type erase(const KeyType& key, KeyValueCompare comp
|
Chris@16
|
591 /// @cond
|
Chris@16
|
592 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
|
Chris@16
|
593 /// @endcond
|
Chris@16
|
594 )
|
Chris@16
|
595 {
|
Chris@16
|
596 std::pair<iterator,iterator> p = this->equal_range(key, comp);
|
Chris@16
|
597 size_type n;
|
Chris@16
|
598 private_erase(p.first, p.second, n);
|
Chris@16
|
599 return n;
|
Chris@16
|
600 }
|
Chris@16
|
601
|
Chris@16
|
602 //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer)
|
Chris@16
|
603 template<class Disposer>
|
Chris@16
|
604 iterator erase_and_dispose(const_iterator i, Disposer disposer)
|
Chris@16
|
605 {
|
Chris@16
|
606 node_ptr to_erase(i.pointed_node());
|
Chris@16
|
607 iterator ret(this->erase(i));
|
Chris@16
|
608 disposer(this->get_real_value_traits().to_value_ptr(to_erase));
|
Chris@16
|
609 return ret;
|
Chris@16
|
610 }
|
Chris@16
|
611
|
Chris@16
|
612 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
613 template<class Disposer>
|
Chris@16
|
614 iterator erase_and_dispose(iterator i, Disposer disposer)
|
Chris@16
|
615 { return this->erase_and_dispose(const_iterator(i), disposer); }
|
Chris@16
|
616 #endif
|
Chris@16
|
617
|
Chris@16
|
618 //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer)
|
Chris@16
|
619 template<class Disposer>
|
Chris@16
|
620 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
|
Chris@16
|
621 { size_type n; return private_erase(b, e, n, disposer); }
|
Chris@16
|
622
|
Chris@16
|
623 //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_reference, Disposer)
|
Chris@16
|
624 template<class Disposer>
|
Chris@16
|
625 size_type erase_and_dispose(const_reference value, Disposer disposer)
|
Chris@16
|
626 {
|
Chris@16
|
627 std::pair<iterator,iterator> p = this->equal_range(value);
|
Chris@16
|
628 size_type n;
|
Chris@16
|
629 private_erase(p.first, p.second, n, disposer);
|
Chris@16
|
630 return n;
|
Chris@16
|
631 }
|
Chris@16
|
632
|
Chris@16
|
633 //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer)
|
Chris@16
|
634 template<class KeyType, class KeyValueCompare, class Disposer>
|
Chris@16
|
635 size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer
|
Chris@16
|
636 /// @cond
|
Chris@16
|
637 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
|
Chris@16
|
638 /// @endcond
|
Chris@16
|
639 )
|
Chris@16
|
640 {
|
Chris@16
|
641 std::pair<iterator,iterator> p = this->equal_range(key, comp);
|
Chris@16
|
642 size_type n;
|
Chris@16
|
643 private_erase(p.first, p.second, n, disposer);
|
Chris@16
|
644 return n;
|
Chris@16
|
645 }
|
Chris@16
|
646
|
Chris@16
|
647 //! @copydoc ::boost::intrusive::bstree::clear
|
Chris@16
|
648 void clear()
|
Chris@16
|
649 {
|
Chris@16
|
650 tree_type::clear();
|
Chris@16
|
651 this->max_tree_size_ = 0;
|
Chris@16
|
652 }
|
Chris@16
|
653
|
Chris@16
|
654 //! @copydoc ::boost::intrusive::bstree::clear_and_dispose
|
Chris@16
|
655 template<class Disposer>
|
Chris@16
|
656 void clear_and_dispose(Disposer disposer)
|
Chris@16
|
657 {
|
Chris@16
|
658 tree_type::clear_and_dispose(disposer);
|
Chris@16
|
659 this->max_tree_size_ = 0;
|
Chris@16
|
660 }
|
Chris@16
|
661
|
Chris@16
|
662 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
663 //! @copydoc ::boost::intrusive::bstree::count(const_reference)const
|
Chris@16
|
664 size_type count(const_reference value) const;
|
Chris@16
|
665
|
Chris@16
|
666 //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const
|
Chris@16
|
667 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
668 size_type count(const KeyType& key, KeyValueCompare comp) const;
|
Chris@16
|
669
|
Chris@16
|
670 //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)
|
Chris@16
|
671 iterator lower_bound(const_reference value);
|
Chris@16
|
672
|
Chris@16
|
673 //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)
|
Chris@16
|
674 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
675 iterator lower_bound(const KeyType& key, KeyValueCompare comp);
|
Chris@16
|
676
|
Chris@16
|
677 //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const
|
Chris@16
|
678 const_iterator lower_bound(const_reference value) const;
|
Chris@16
|
679
|
Chris@16
|
680 //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const
|
Chris@16
|
681 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
682 const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const;
|
Chris@16
|
683
|
Chris@16
|
684 //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)
|
Chris@16
|
685 iterator upper_bound(const_reference value);
|
Chris@16
|
686
|
Chris@16
|
687 //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)
|
Chris@16
|
688 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
689 iterator upper_bound(const KeyType& key, KeyValueCompare comp);
|
Chris@16
|
690
|
Chris@16
|
691 //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const
|
Chris@16
|
692 const_iterator upper_bound(const_reference value) const;
|
Chris@16
|
693
|
Chris@16
|
694 //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const
|
Chris@16
|
695 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
696 const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const;
|
Chris@16
|
697
|
Chris@16
|
698 //! @copydoc ::boost::intrusive::bstree::find(const_reference)
|
Chris@16
|
699 iterator find(const_reference value);
|
Chris@16
|
700
|
Chris@16
|
701 //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)
|
Chris@16
|
702 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
703 iterator find(const KeyType& key, KeyValueCompare comp);
|
Chris@16
|
704
|
Chris@16
|
705 //! @copydoc ::boost::intrusive::bstree::find(const_reference)const
|
Chris@16
|
706 const_iterator find(const_reference value) const;
|
Chris@16
|
707
|
Chris@16
|
708 //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const
|
Chris@16
|
709 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
710 const_iterator find(const KeyType& key, KeyValueCompare comp) const;
|
Chris@16
|
711
|
Chris@16
|
712 //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)
|
Chris@16
|
713 std::pair<iterator,iterator> equal_range(const_reference value);
|
Chris@16
|
714
|
Chris@16
|
715 //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)
|
Chris@16
|
716 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
717 std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp);
|
Chris@16
|
718
|
Chris@16
|
719 //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const
|
Chris@16
|
720 std::pair<const_iterator, const_iterator>
|
Chris@16
|
721 equal_range(const_reference value) const;
|
Chris@16
|
722
|
Chris@16
|
723 //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)const
|
Chris@16
|
724 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
725 std::pair<const_iterator, const_iterator>
|
Chris@16
|
726 equal_range(const KeyType& key, KeyValueCompare comp) const;
|
Chris@16
|
727
|
Chris@16
|
728 //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)
|
Chris@16
|
729 std::pair<iterator,iterator> bounded_range
|
Chris@16
|
730 (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed);
|
Chris@16
|
731
|
Chris@16
|
732 //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)
|
Chris@16
|
733 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
734 std::pair<iterator,iterator> bounded_range
|
Chris@16
|
735 (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed);
|
Chris@16
|
736
|
Chris@16
|
737 //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const
|
Chris@16
|
738 std::pair<const_iterator, const_iterator>
|
Chris@16
|
739 bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const;
|
Chris@16
|
740
|
Chris@16
|
741 //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const
|
Chris@16
|
742 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
743 std::pair<const_iterator, const_iterator> bounded_range
|
Chris@16
|
744 (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const;
|
Chris@16
|
745
|
Chris@16
|
746 //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference)
|
Chris@16
|
747 static iterator s_iterator_to(reference value);
|
Chris@16
|
748
|
Chris@16
|
749 //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference)
|
Chris@16
|
750 static const_iterator s_iterator_to(const_reference value);
|
Chris@16
|
751
|
Chris@16
|
752 //! @copydoc ::boost::intrusive::bstree::iterator_to(reference)
|
Chris@16
|
753 iterator iterator_to(reference value);
|
Chris@16
|
754
|
Chris@16
|
755 //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const
|
Chris@16
|
756 const_iterator iterator_to(const_reference value) const;
|
Chris@16
|
757
|
Chris@16
|
758 //! @copydoc ::boost::intrusive::bstree::init_node(reference)
|
Chris@16
|
759 static void init_node(reference value);
|
Chris@16
|
760
|
Chris@16
|
761 //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance
|
Chris@16
|
762 pointer unlink_leftmost_without_rebalance();
|
Chris@16
|
763
|
Chris@16
|
764 //! @copydoc ::boost::intrusive::bstree::replace_node
|
Chris@16
|
765 void replace_node(iterator replace_this, reference with_this);
|
Chris@16
|
766
|
Chris@16
|
767 //! @copydoc ::boost::intrusive::bstree::remove_node
|
Chris@16
|
768 void remove_node(reference value);
|
Chris@16
|
769
|
Chris@16
|
770 //! @copydoc ::boost::intrusive::bstree::rebalance
|
Chris@16
|
771 void rebalance();
|
Chris@16
|
772
|
Chris@16
|
773 //! @copydoc ::boost::intrusive::bstree::rebalance_subtree
|
Chris@16
|
774 iterator rebalance_subtree(iterator root);
|
Chris@16
|
775
|
Chris@16
|
776 #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
777
|
Chris@16
|
778 //! <b>Returns</b>: The balance factor (alpha) used in this tree
|
Chris@16
|
779 //!
|
Chris@16
|
780 //! <b>Throws</b>: Nothing.
|
Chris@16
|
781 //!
|
Chris@16
|
782 //! <b>Complexity</b>: Constant.
|
Chris@16
|
783 float balance_factor() const
|
Chris@16
|
784 { return this->get_alpha_traits().get_alpha(); }
|
Chris@16
|
785
|
Chris@16
|
786 //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
|
Chris@16
|
787 //!
|
Chris@16
|
788 //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
|
Chris@16
|
789 //! the tree if the new balance factor is stricter (less) than the old factor.
|
Chris@16
|
790 //!
|
Chris@16
|
791 //! <b>Throws</b>: Nothing.
|
Chris@16
|
792 //!
|
Chris@16
|
793 //! <b>Complexity</b>: Linear to the elements in the subtree.
|
Chris@16
|
794 void balance_factor(float new_alpha)
|
Chris@16
|
795 {
|
Chris@16
|
796 BOOST_INTRUSIVE_INVARIANT_ASSERT((new_alpha > 0.5f && new_alpha < 1.0f));
|
Chris@16
|
797 if(new_alpha < 0.5f && new_alpha >= 1.0f) return;
|
Chris@16
|
798
|
Chris@16
|
799 //The alpha factor CAN't be changed if the fixed, floating operation-less
|
Chris@16
|
800 //1/sqrt(2) alpha factor option is activated
|
Chris@16
|
801 BOOST_STATIC_ASSERT((floating_point));
|
Chris@16
|
802 float old_alpha = this->get_alpha_traits().get_alpha();
|
Chris@16
|
803 this->get_alpha_traits().set_alpha(new_alpha);
|
Chris@16
|
804
|
Chris@16
|
805 if(new_alpha < old_alpha){
|
Chris@16
|
806 this->max_tree_size_ = this->size();
|
Chris@16
|
807 this->rebalance();
|
Chris@16
|
808 }
|
Chris@16
|
809 }
|
Chris@16
|
810
|
Chris@16
|
811 /// @cond
|
Chris@16
|
812 private:
|
Chris@16
|
813 template<class Disposer>
|
Chris@16
|
814 iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
|
Chris@16
|
815 {
|
Chris@16
|
816 for(n = 0; b != e; ++n)
|
Chris@16
|
817 this->erase_and_dispose(b++, disposer);
|
Chris@16
|
818 return b.unconst();
|
Chris@16
|
819 }
|
Chris@16
|
820
|
Chris@16
|
821 iterator private_erase(const_iterator b, const_iterator e, size_type &n)
|
Chris@16
|
822 {
|
Chris@16
|
823 for(n = 0; b != e; ++n)
|
Chris@16
|
824 this->erase(b++);
|
Chris@16
|
825 return b.unconst();
|
Chris@16
|
826 }
|
Chris@16
|
827 /// @endcond
|
Chris@16
|
828 };
|
Chris@16
|
829
|
Chris@16
|
830 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
831
|
Chris@16
|
832 template<class T, class ...Options>
|
Chris@16
|
833 bool operator< (const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y);
|
Chris@16
|
834
|
Chris@16
|
835 template<class T, class ...Options>
|
Chris@16
|
836 bool operator==(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y);
|
Chris@16
|
837
|
Chris@16
|
838 template<class T, class ...Options>
|
Chris@16
|
839 bool operator!= (const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y);
|
Chris@16
|
840
|
Chris@16
|
841 template<class T, class ...Options>
|
Chris@16
|
842 bool operator>(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y);
|
Chris@16
|
843
|
Chris@16
|
844 template<class T, class ...Options>
|
Chris@16
|
845 bool operator<=(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y);
|
Chris@16
|
846
|
Chris@16
|
847 template<class T, class ...Options>
|
Chris@16
|
848 bool operator>=(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y);
|
Chris@16
|
849
|
Chris@16
|
850 template<class T, class ...Options>
|
Chris@16
|
851 void swap(sgtree_impl<T, Options...> &x, sgtree_impl<T, Options...> &y);
|
Chris@16
|
852
|
Chris@16
|
853 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
854
|
Chris@16
|
855 //! Helper metafunction to define a \c sgtree that yields to the same type when the
|
Chris@16
|
856 //! same options (either explicitly or implicitly) are used.
|
Chris@16
|
857 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
858 template<class T, class ...Options>
|
Chris@16
|
859 #else
|
Chris@16
|
860 template<class T, class O1 = void, class O2 = void
|
Chris@16
|
861 , class O3 = void, class O4 = void>
|
Chris@16
|
862 #endif
|
Chris@16
|
863 struct make_sgtree
|
Chris@16
|
864 {
|
Chris@16
|
865 /// @cond
|
Chris@16
|
866 typedef typename pack_options
|
Chris@16
|
867 < sgtree_defaults,
|
Chris@16
|
868 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
869 O1, O2, O3, O4
|
Chris@16
|
870 #else
|
Chris@16
|
871 Options...
|
Chris@16
|
872 #endif
|
Chris@16
|
873 >::type packed_options;
|
Chris@16
|
874
|
Chris@16
|
875 typedef typename detail::get_value_traits
|
Chris@16
|
876 <T, typename packed_options::proto_value_traits>::type value_traits;
|
Chris@16
|
877
|
Chris@16
|
878 typedef sgtree_impl
|
Chris@16
|
879 < value_traits
|
Chris@16
|
880 , typename packed_options::compare
|
Chris@16
|
881 , typename packed_options::size_type
|
Chris@16
|
882 , packed_options::floating_point
|
Chris@16
|
883 > implementation_defined;
|
Chris@16
|
884 /// @endcond
|
Chris@16
|
885 typedef implementation_defined type;
|
Chris@16
|
886 };
|
Chris@16
|
887
|
Chris@16
|
888
|
Chris@16
|
889 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
890
|
Chris@16
|
891 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
892 template<class T, class O1, class O2, class O3, class O4>
|
Chris@16
|
893 #else
|
Chris@16
|
894 template<class T, class ...Options>
|
Chris@16
|
895 #endif
|
Chris@16
|
896 class sgtree
|
Chris@16
|
897 : public make_sgtree<T,
|
Chris@16
|
898 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
899 O1, O2, O3, O4
|
Chris@16
|
900 #else
|
Chris@16
|
901 Options...
|
Chris@16
|
902 #endif
|
Chris@16
|
903 >::type
|
Chris@16
|
904 {
|
Chris@16
|
905 typedef typename make_sgtree
|
Chris@16
|
906 <T,
|
Chris@16
|
907 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
908 O1, O2, O3, O4
|
Chris@16
|
909 #else
|
Chris@16
|
910 Options...
|
Chris@16
|
911 #endif
|
Chris@16
|
912 >::type Base;
|
Chris@16
|
913 BOOST_MOVABLE_BUT_NOT_COPYABLE(sgtree)
|
Chris@16
|
914
|
Chris@16
|
915 public:
|
Chris@16
|
916 typedef typename Base::value_compare value_compare;
|
Chris@16
|
917 typedef typename Base::value_traits value_traits;
|
Chris@16
|
918 typedef typename Base::real_value_traits real_value_traits;
|
Chris@16
|
919 typedef typename Base::iterator iterator;
|
Chris@16
|
920 typedef typename Base::const_iterator const_iterator;
|
Chris@16
|
921 typedef typename Base::reverse_iterator reverse_iterator;
|
Chris@16
|
922 typedef typename Base::const_reverse_iterator const_reverse_iterator;
|
Chris@16
|
923
|
Chris@16
|
924 //Assert if passed value traits are compatible with the type
|
Chris@16
|
925 BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
|
Chris@16
|
926
|
Chris@16
|
927 explicit sgtree( const value_compare &cmp = value_compare()
|
Chris@16
|
928 , const value_traits &v_traits = value_traits())
|
Chris@16
|
929 : Base(cmp, v_traits)
|
Chris@16
|
930 {}
|
Chris@16
|
931
|
Chris@16
|
932 template<class Iterator>
|
Chris@16
|
933 sgtree( bool unique, Iterator b, Iterator e
|
Chris@16
|
934 , const value_compare &cmp = value_compare()
|
Chris@16
|
935 , const value_traits &v_traits = value_traits())
|
Chris@16
|
936 : Base(unique, b, e, cmp, v_traits)
|
Chris@16
|
937 {}
|
Chris@16
|
938
|
Chris@16
|
939 sgtree(BOOST_RV_REF(sgtree) x)
|
Chris@16
|
940 : Base(::boost::move(static_cast<Base&>(x)))
|
Chris@16
|
941 {}
|
Chris@16
|
942
|
Chris@16
|
943 sgtree& operator=(BOOST_RV_REF(sgtree) x)
|
Chris@16
|
944 { return static_cast<sgtree &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); }
|
Chris@16
|
945
|
Chris@16
|
946 static sgtree &container_from_end_iterator(iterator end_iterator)
|
Chris@16
|
947 { return static_cast<sgtree &>(Base::container_from_end_iterator(end_iterator)); }
|
Chris@16
|
948
|
Chris@16
|
949 static const sgtree &container_from_end_iterator(const_iterator end_iterator)
|
Chris@16
|
950 { return static_cast<const sgtree &>(Base::container_from_end_iterator(end_iterator)); }
|
Chris@16
|
951
|
Chris@16
|
952 static sgtree &container_from_iterator(iterator it)
|
Chris@16
|
953 { return static_cast<sgtree &>(Base::container_from_iterator(it)); }
|
Chris@16
|
954
|
Chris@16
|
955 static const sgtree &container_from_iterator(const_iterator it)
|
Chris@16
|
956 { return static_cast<const sgtree &>(Base::container_from_iterator(it)); }
|
Chris@16
|
957 };
|
Chris@16
|
958
|
Chris@16
|
959 #endif
|
Chris@16
|
960
|
Chris@16
|
961 } //namespace intrusive
|
Chris@16
|
962 } //namespace boost
|
Chris@16
|
963
|
Chris@16
|
964 #include <boost/intrusive/detail/config_end.hpp>
|
Chris@16
|
965
|
Chris@16
|
966 #endif //BOOST_INTRUSIVE_SGTREE_HPP
|