annotate DEPENDENCIES/generic/include/boost/intrusive/sgtree.hpp @ 133:4acb5d8d80b6 tip

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