sgtree.hpp 41 KB

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