sgtree.hpp 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  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