sgtree.hpp 41 KB

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