splaytree.hpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2007-2013
  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. #ifndef BOOST_INTRUSIVE_SPLAYTREE_HPP
  13. #define BOOST_INTRUSIVE_SPLAYTREE_HPP
  14. #include <boost/intrusive/detail/config_begin.hpp>
  15. #include <cstddef>
  16. #include <functional>
  17. #include <iterator>
  18. #include <utility>
  19. #include <boost/intrusive/detail/assert.hpp>
  20. #include <boost/static_assert.hpp>
  21. #include <boost/intrusive/intrusive_fwd.hpp>
  22. #include <boost/intrusive/splay_set_hook.hpp>
  23. #include <boost/intrusive/bstree.hpp>
  24. #include <boost/intrusive/detail/tree_node.hpp>
  25. #include <boost/intrusive/detail/ebo_functor_holder.hpp>
  26. #include <boost/intrusive/detail/mpl.hpp>
  27. #include <boost/intrusive/pointer_traits.hpp>
  28. #include <boost/intrusive/detail/function_detector.hpp>
  29. #include <boost/intrusive/detail/utilities.hpp>
  30. #include <boost/intrusive/options.hpp>
  31. #include <boost/intrusive/splaytree_algorithms.hpp>
  32. #include <boost/intrusive/link_mode.hpp>
  33. #include <boost/move/move.hpp>
  34. namespace boost {
  35. namespace intrusive {
  36. /// @cond
  37. struct splaytree_defaults
  38. {
  39. typedef detail::default_bstree_hook proto_value_traits;
  40. static const bool constant_time_size = true;
  41. typedef std::size_t size_type;
  42. typedef void compare;
  43. };
  44. /// @endcond
  45. //! The class template splaytree is an intrusive splay tree container that
  46. //! is used to construct intrusive splay_set and splay_multiset containers. The no-throw
  47. //! guarantee holds only, if the value_compare object
  48. //! doesn't throw.
  49. //!
  50. //! The template parameter \c T is the type to be managed by the container.
  51. //! The user can specify additional options and if no options are provided
  52. //! default options are used.
  53. //!
  54. //! The container supports the following options:
  55. //! \c base_hook<>/member_hook<>/value_traits<>,
  56. //! \c constant_time_size<>, \c size_type<> and
  57. //! \c compare<>.
  58. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  59. template<class T, class ...Options>
  60. #else
  61. template<class ValueTraits, class VoidOrKeyComp, class SizeType, bool ConstantTimeSize>
  62. #endif
  63. class splaytree_impl
  64. /// @cond
  65. : public bstree_impl<ValueTraits, VoidOrKeyComp, SizeType, ConstantTimeSize, SplayTreeAlgorithms>
  66. /// @endcond
  67. {
  68. public:
  69. typedef ValueTraits value_traits;
  70. /// @cond
  71. typedef bstree_impl< ValueTraits, VoidOrKeyComp, SizeType
  72. , ConstantTimeSize, SplayTreeAlgorithms> tree_type;
  73. typedef typename tree_type::real_value_traits real_value_traits;
  74. typedef tree_type implementation_defined;
  75. /// @endcond
  76. typedef typename implementation_defined::pointer pointer;
  77. typedef typename implementation_defined::const_pointer const_pointer;
  78. typedef typename implementation_defined::value_type value_type;
  79. typedef typename implementation_defined::key_type key_type;
  80. typedef typename implementation_defined::reference reference;
  81. typedef typename implementation_defined::const_reference const_reference;
  82. typedef typename implementation_defined::difference_type difference_type;
  83. typedef typename implementation_defined::size_type size_type;
  84. typedef typename implementation_defined::value_compare value_compare;
  85. typedef typename implementation_defined::key_compare key_compare;
  86. typedef typename implementation_defined::iterator iterator;
  87. typedef typename implementation_defined::const_iterator const_iterator;
  88. typedef typename implementation_defined::reverse_iterator reverse_iterator;
  89. typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
  90. typedef typename implementation_defined::node_traits node_traits;
  91. typedef typename implementation_defined::node node;
  92. typedef typename implementation_defined::node_ptr node_ptr;
  93. typedef typename implementation_defined::const_node_ptr const_node_ptr;
  94. typedef typename implementation_defined::node_algorithms node_algorithms;
  95. static const bool constant_time_size = implementation_defined::constant_time_size;
  96. /// @cond
  97. private:
  98. //noncopyable
  99. BOOST_MOVABLE_BUT_NOT_COPYABLE(splaytree_impl)
  100. /// @endcond
  101. public:
  102. typedef typename implementation_defined::insert_commit_data insert_commit_data;
  103. //! @copydoc ::boost::intrusive::bstree::bstree(const value_compare &,const value_traits &)
  104. explicit splaytree_impl( const value_compare &cmp = value_compare()
  105. , const value_traits &v_traits = value_traits())
  106. : tree_type(cmp, v_traits)
  107. {}
  108. //! @copydoc ::boost::intrusive::bstree::bstree(bool,Iterator,Iterator,const value_compare &,const value_traits &)
  109. template<class Iterator>
  110. splaytree_impl( bool unique, Iterator b, Iterator e
  111. , const value_compare &cmp = value_compare()
  112. , const value_traits &v_traits = value_traits())
  113. : tree_type(cmp, v_traits)
  114. {
  115. if(unique)
  116. this->insert_unique(b, e);
  117. else
  118. this->insert_equal(b, e);
  119. }
  120. //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&)
  121. splaytree_impl(BOOST_RV_REF(splaytree_impl) x)
  122. : tree_type(::boost::move(static_cast<tree_type&>(x)))
  123. {}
  124. //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&)
  125. splaytree_impl& operator=(BOOST_RV_REF(splaytree_impl) x)
  126. { return static_cast<splaytree_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); }
  127. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  128. //! @copydoc ::boost::intrusive::bstree::~bstree()
  129. ~splaytree_impl();
  130. //! @copydoc ::boost::intrusive::bstree::begin()
  131. iterator begin();
  132. //! @copydoc ::boost::intrusive::bstree::begin()const
  133. const_iterator begin() const;
  134. //! @copydoc ::boost::intrusive::bstree::cbegin()const
  135. const_iterator cbegin() const;
  136. //! @copydoc ::boost::intrusive::bstree::end()
  137. iterator end();
  138. //! @copydoc ::boost::intrusive::bstree::end()const
  139. const_iterator end() const;
  140. //! @copydoc ::boost::intrusive::bstree::cend()const
  141. const_iterator cend() const;
  142. //! @copydoc ::boost::intrusive::bstree::rbegin()
  143. reverse_iterator rbegin();
  144. //! @copydoc ::boost::intrusive::bstree::rbegin()const
  145. const_reverse_iterator rbegin() const;
  146. //! @copydoc ::boost::intrusive::bstree::crbegin()const
  147. const_reverse_iterator crbegin() const;
  148. //! @copydoc ::boost::intrusive::bstree::rend()
  149. reverse_iterator rend();
  150. //! @copydoc ::boost::intrusive::bstree::rend()const
  151. const_reverse_iterator rend() const;
  152. //! @copydoc ::boost::intrusive::bstree::crend()const
  153. const_reverse_iterator crend() const;
  154. //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator)
  155. static splaytree_impl &container_from_end_iterator(iterator end_iterator);
  156. //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator)
  157. static const splaytree_impl &container_from_end_iterator(const_iterator end_iterator);
  158. //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator)
  159. static splaytree_impl &container_from_iterator(iterator it);
  160. //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator)
  161. static const splaytree_impl &container_from_iterator(const_iterator it);
  162. //! @copydoc ::boost::intrusive::bstree::key_comp()const
  163. key_compare key_comp() const;
  164. //! @copydoc ::boost::intrusive::bstree::value_comp()const
  165. value_compare value_comp() const;
  166. //! @copydoc ::boost::intrusive::bstree::empty()const
  167. bool empty() const;
  168. //! @copydoc ::boost::intrusive::bstree::size()const
  169. size_type size() const;
  170. //! @copydoc ::boost::intrusive::bstree::swap
  171. void swap(splaytree_impl& other);
  172. //! @copydoc ::boost::intrusive::bstree::clone_from
  173. template <class Cloner, class Disposer>
  174. void clone_from(const splaytree_impl &src, Cloner cloner, Disposer disposer);
  175. //! @copydoc ::boost::intrusive::bstree::insert_equal(reference)
  176. iterator insert_equal(reference value);
  177. //! @copydoc ::boost::intrusive::bstree::insert_equal(const_iterator,reference)
  178. iterator insert_equal(const_iterator hint, reference value);
  179. //! @copydoc ::boost::intrusive::bstree::insert_equal(Iterator,Iterator)
  180. template<class Iterator>
  181. void insert_equal(Iterator b, Iterator e);
  182. //! @copydoc ::boost::intrusive::bstree::insert_unique(reference)
  183. std::pair<iterator, bool> insert_unique(reference value);
  184. //! @copydoc ::boost::intrusive::bstree::insert_unique(const_iterator,reference)
  185. iterator insert_unique(const_iterator hint, reference value);
  186. //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const KeyType&,KeyValueCompare,insert_commit_data&)
  187. template<class KeyType, class KeyValueCompare>
  188. std::pair<iterator, bool> insert_unique_check
  189. (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data);
  190. //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,insert_commit_data&)
  191. template<class KeyType, class KeyValueCompare>
  192. std::pair<iterator, bool> insert_unique_check
  193. (const_iterator hint, const KeyType &key
  194. ,KeyValueCompare key_value_comp, insert_commit_data &commit_data);
  195. //! @copydoc ::boost::intrusive::bstree::insert_unique_commit
  196. iterator insert_unique_commit(reference value, const insert_commit_data &commit_data);
  197. //! @copydoc ::boost::intrusive::bstree::insert_unique(Iterator,Iterator)
  198. template<class Iterator>
  199. void insert_unique(Iterator b, Iterator e);
  200. //! @copydoc ::boost::intrusive::bstree::insert_before
  201. iterator insert_before(const_iterator pos, reference value);
  202. //! @copydoc ::boost::intrusive::bstree::push_back
  203. void push_back(reference value);
  204. //! @copydoc ::boost::intrusive::bstree::push_front
  205. void push_front(reference value);
  206. //! @copydoc ::boost::intrusive::bstree::erase(const_iterator)
  207. iterator erase(const_iterator i);
  208. //! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator)
  209. iterator erase(const_iterator b, const_iterator e);
  210. //! @copydoc ::boost::intrusive::bstree::erase(const_reference)
  211. size_type erase(const_reference value);
  212. //! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyValueCompare)
  213. template<class KeyType, class KeyValueCompare>
  214. size_type erase(const KeyType& key, KeyValueCompare comp);
  215. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer)
  216. template<class Disposer>
  217. iterator erase_and_dispose(const_iterator i, Disposer disposer);
  218. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer)
  219. template<class Disposer>
  220. iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer);
  221. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_reference, Disposer)
  222. template<class Disposer>
  223. size_type erase_and_dispose(const_reference value, Disposer disposer);
  224. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer)
  225. template<class KeyType, class KeyValueCompare, class Disposer>
  226. size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer);
  227. //! @copydoc ::boost::intrusive::bstree::clear
  228. void clear();
  229. //! @copydoc ::boost::intrusive::bstree::clear_and_dispose
  230. template<class Disposer>
  231. void clear_and_dispose(Disposer disposer);
  232. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  233. //! @copydoc ::boost::intrusive::bstree::count(const_reference)const
  234. //! Additional note: non-const function, splaying is performed for the first
  235. //! element of the equal range of "value"
  236. size_type count(const_reference value)
  237. { return this->count(value, this->value_comp()); }
  238. //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const
  239. //! Additional note: non-const function, splaying is performed for the first
  240. //! element of the equal range of "key"
  241. template<class KeyType, class KeyValueCompare>
  242. size_type count(const KeyType &key, KeyValueCompare comp)
  243. {
  244. std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp);
  245. return std::distance(ret.first, ret.second);
  246. }
  247. //! @copydoc ::boost::intrusive::bstree::count(const_reference)const
  248. //! Additional note: Deprecated function, use count const overload instead.
  249. size_type count(const_reference value) const
  250. { return tree_type::count(value); }
  251. //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const
  252. //! Additional note: Deprecated function, use count const overload instead.
  253. template<class KeyType, class KeyValueCompare>
  254. size_type count(const KeyType &key, KeyValueCompare comp) const
  255. { return tree_type::count(key, comp); }
  256. //! @copydoc ::boost::intrusive::bstree::count(const_reference)const
  257. //! Additional note: Deprecated function, use count const overload instead.
  258. size_type count_dont_splay(const_reference value) const
  259. { return tree_type::count(value); }
  260. //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const
  261. //! Additional note: Deprecated function, use count const overload instead.
  262. template<class KeyType, class KeyValueCompare>
  263. size_type count_dont_splay(const KeyType &key, KeyValueCompare comp) const
  264. { return tree_type::count(key, comp); }
  265. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  266. //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)
  267. //! Additional note: non-const function, splaying is performed for the first
  268. //! element of the equal range of "value"
  269. iterator lower_bound(const_reference value);
  270. //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const
  271. //! Additional note: const function, no splaying is performed
  272. const_iterator lower_bound(const_reference value) const;
  273. //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const
  274. //! Additional note: Deprecated function, use lower_bound const overload instead.
  275. const_iterator lower_bound_dont_splay(const_reference value) const;
  276. //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)
  277. //! Additional note: non-const function, splaying is performed for the first
  278. //! element of the equal range of "key"
  279. template<class KeyType, class KeyValueCompare>
  280. iterator lower_bound(const KeyType &key, KeyValueCompare comp);
  281. //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const
  282. //! Additional note: const function, no splaying is performed
  283. template<class KeyType, class KeyValueCompare>
  284. const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const;
  285. //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)
  286. //! Additional note: Deprecated function, use lower_bound const overload instead.
  287. template<class KeyType, class KeyValueCompare>
  288. iterator lower_bound_dont_splay(const KeyType &key, KeyValueCompare comp) const;
  289. //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)
  290. //! Additional note: non-const function, splaying is performed for the first
  291. //! element of the equal range of "value"
  292. iterator upper_bound(const_reference value);
  293. //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const
  294. //! Additional note: const function, no splaying is performed
  295. const_iterator upper_bound(const_reference value) const;
  296. //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const
  297. //! Additional note: Deprecated function, use upper_bound const overload instead.
  298. const_iterator upper_bound_dont_splay(const_reference value) const;
  299. //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)
  300. //! Additional note: non-const function, splaying is performed for the first
  301. //! element of the equal range of "key"
  302. template<class KeyType, class KeyValueCompare>
  303. iterator upper_bound(const KeyType &key, KeyValueCompare comp);
  304. //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const
  305. //! Additional note: const function, no splaying is performed
  306. template<class KeyType, class KeyValueCompare>
  307. const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const;
  308. //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)
  309. //! Additional note: Deprecated function, use upper_bound const overload instead.
  310. template<class KeyType, class KeyValueCompare>
  311. const_iterator upper_bound_dont_splay(const KeyType &key, KeyValueCompare comp) const;
  312. //! @copydoc ::boost::intrusive::bstree::find(const_reference)
  313. //! Additional note: non-const function, splaying is performed for the first
  314. //! element of the equal range of "value"
  315. iterator find(const_reference value);
  316. //! @copydoc ::boost::intrusive::bstree::find(const_reference)const
  317. //! Additional note: const function, no splaying is performed
  318. const_iterator find(const_reference value) const;
  319. //! @copydoc ::boost::intrusive::bstree::find(const_reference)const
  320. //! Additional note: Deprecated function, use find const overload instead.
  321. const_iterator find_dont_splay(const_reference value) const;
  322. //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)
  323. //! Additional note: non-const function, splaying is performed for the first
  324. //! element of the equal range of "key"
  325. template<class KeyType, class KeyValueCompare>
  326. iterator find(const KeyType &key, KeyValueCompare comp);
  327. //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const
  328. //! Additional note: const function, no splaying is performed
  329. template<class KeyType, class KeyValueCompare>
  330. const_iterator find(const KeyType &key, KeyValueCompare comp) const;
  331. //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const
  332. //! Additional note: Deprecated function, use find const overload instead.
  333. template<class KeyType, class KeyValueCompare>
  334. const_iterator find_dont_splay(const KeyType &key, KeyValueCompare comp) const;
  335. //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)
  336. //! Additional note: non-const function, splaying is performed for the first
  337. //! element of the equal range of "value"
  338. std::pair<iterator, iterator> equal_range(const_reference value);
  339. //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const
  340. //! Additional note: const function, no splaying is performed
  341. std::pair<const_iterator, const_iterator> equal_range(const_reference value) const;
  342. //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const
  343. //! Additional note: Deprecated function, use equal_range const overload instead.
  344. std::pair<const_iterator, const_iterator> equal_range_dont_splay(const_reference value) const;
  345. //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)
  346. //! Additional note: non-const function, splaying is performed for the first
  347. //! element of the equal range of "key"
  348. template<class KeyType, class KeyValueCompare>
  349. std::pair<iterator, iterator> equal_range(const KeyType &key, KeyValueCompare comp);
  350. //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)const
  351. //! Additional note: const function, no splaying is performed
  352. template<class KeyType, class KeyValueCompare>
  353. std::pair<const_iterator, const_iterator> equal_range(const KeyType &key, KeyValueCompare comp) const;
  354. //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)
  355. //! Additional note: Deprecated function, use equal_range const overload instead.
  356. template<class KeyType, class KeyValueCompare>
  357. std::pair<const_iterator, const_iterator> equal_range_dont_splay(const KeyType &key, KeyValueCompare comp) const;
  358. //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)
  359. std::pair<iterator,iterator> bounded_range
  360. (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed);
  361. //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)
  362. template<class KeyType, class KeyValueCompare>
  363. std::pair<iterator,iterator> bounded_range
  364. (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed);
  365. //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const
  366. std::pair<const_iterator, const_iterator> bounded_range
  367. (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const;
  368. //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const
  369. template<class KeyType, class KeyValueCompare>
  370. std::pair<const_iterator, const_iterator> bounded_range
  371. (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const;
  372. //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const
  373. //! Additional note: Deprecated function, use bounded_range const overload instead.
  374. std::pair<const_iterator, const_iterator> bounded_range_dont_splay
  375. (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const;
  376. //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const
  377. //! Additional note: Deprecated function, use bounded_range const overload instead.
  378. template<class KeyType, class KeyValueCompare>
  379. std::pair<const_iterator, const_iterator> bounded_range_dont_splay
  380. (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const;
  381. //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference)
  382. static iterator s_iterator_to(reference value);
  383. //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference)
  384. static const_iterator s_iterator_to(const_reference value);
  385. //! @copydoc ::boost::intrusive::bstree::iterator_to(reference)
  386. iterator iterator_to(reference value);
  387. //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const
  388. const_iterator iterator_to(const_reference value) const;
  389. //! @copydoc ::boost::intrusive::bstree::init_node(reference)
  390. static void init_node(reference value);
  391. //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance
  392. pointer unlink_leftmost_without_rebalance();
  393. //! @copydoc ::boost::intrusive::bstree::replace_node
  394. void replace_node(iterator replace_this, reference with_this);
  395. //! @copydoc ::boost::intrusive::bstree::remove_node
  396. void remove_node(reference value);
  397. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  398. //! <b>Requires</b>: i must be a valid iterator of *this.
  399. //!
  400. //! <b>Effects</b>: Rearranges the container so that the element pointed by i
  401. //! is placed as the root of the tree, improving future searches of this value.
  402. //!
  403. //! <b>Complexity</b>: Amortized logarithmic.
  404. //!
  405. //! <b>Throws</b>: Nothing.
  406. void splay_up(iterator i)
  407. { return node_algorithms::splay_up(i.pointed_node(), tree_type::header_ptr()); }
  408. //! <b>Effects</b>: Rearranges the container so that if *this stores an element
  409. //! with a key equivalent to value the element is placed as the root of the
  410. //! tree. If the element is not present returns the last node compared with the key.
  411. //! If the tree is empty, end() is returned.
  412. //!
  413. //! <b>Complexity</b>: Amortized logarithmic.
  414. //!
  415. //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
  416. //!
  417. //! <b>Throws</b>: If the comparison functor throws.
  418. template<class KeyType, class KeyValueCompare>
  419. iterator splay_down(const KeyType &key, KeyValueCompare comp)
  420. {
  421. detail::key_nodeptr_comp<value_compare, real_value_traits>
  422. key_node_comp(comp, &this->get_real_value_traits());
  423. node_ptr r = node_algorithms::splay_down(tree_type::header_ptr(), key, key_node_comp);
  424. return iterator(r, this->real_value_traits_ptr());
  425. }
  426. //! <b>Effects</b>: Rearranges the container so that if *this stores an element
  427. //! with a key equivalent to value the element is placed as the root of the
  428. //! tree.
  429. //!
  430. //! <b>Complexity</b>: Amortized logarithmic.
  431. //!
  432. //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
  433. //!
  434. //! <b>Throws</b>: If the predicate throws.
  435. iterator splay_down(const_reference value)
  436. { return this->splay_down(value, this->value_comp()); }
  437. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  438. //! @copydoc ::boost::intrusive::bstree::rebalance
  439. void rebalance();
  440. //! @copydoc ::boost::intrusive::bstree::rebalance_subtree
  441. iterator rebalance_subtree(iterator root);
  442. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  443. };
  444. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  445. template<class T, class ...Options>
  446. bool operator< (const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y);
  447. template<class T, class ...Options>
  448. bool operator==(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y);
  449. template<class T, class ...Options>
  450. bool operator!= (const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y);
  451. template<class T, class ...Options>
  452. bool operator>(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y);
  453. template<class T, class ...Options>
  454. bool operator<=(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y);
  455. template<class T, class ...Options>
  456. bool operator>=(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y);
  457. template<class T, class ...Options>
  458. void swap(splaytree_impl<T, Options...> &x, splaytree_impl<T, Options...> &y);
  459. #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  460. //! Helper metafunction to define a \c splaytree that yields to the same type when the
  461. //! same options (either explicitly or implicitly) are used.
  462. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  463. template<class T, class ...Options>
  464. #else
  465. template<class T, class O1 = void, class O2 = void
  466. , class O3 = void, class O4 = void>
  467. #endif
  468. struct make_splaytree
  469. {
  470. /// @cond
  471. typedef typename pack_options
  472. < splaytree_defaults,
  473. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  474. O1, O2, O3, O4
  475. #else
  476. Options...
  477. #endif
  478. >::type packed_options;
  479. typedef typename detail::get_value_traits
  480. <T, typename packed_options::proto_value_traits>::type value_traits;
  481. typedef splaytree_impl
  482. < value_traits
  483. , typename packed_options::compare
  484. , typename packed_options::size_type
  485. , packed_options::constant_time_size
  486. > implementation_defined;
  487. /// @endcond
  488. typedef implementation_defined type;
  489. };
  490. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  491. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  492. template<class T, class O1, class O2, class O3, class O4>
  493. #else
  494. template<class T, class ...Options>
  495. #endif
  496. class splaytree
  497. : public make_splaytree<T,
  498. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  499. O1, O2, O3, O4
  500. #else
  501. Options...
  502. #endif
  503. >::type
  504. {
  505. typedef typename make_splaytree
  506. <T,
  507. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  508. O1, O2, O3, O4
  509. #else
  510. Options...
  511. #endif
  512. >::type Base;
  513. BOOST_MOVABLE_BUT_NOT_COPYABLE(splaytree)
  514. public:
  515. typedef typename Base::value_compare value_compare;
  516. typedef typename Base::value_traits value_traits;
  517. typedef typename Base::real_value_traits real_value_traits;
  518. typedef typename Base::iterator iterator;
  519. typedef typename Base::const_iterator const_iterator;
  520. typedef typename Base::reverse_iterator reverse_iterator;
  521. typedef typename Base::const_reverse_iterator const_reverse_iterator;
  522. //Assert if passed value traits are compatible with the type
  523. BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
  524. explicit splaytree( const value_compare &cmp = value_compare()
  525. , const value_traits &v_traits = value_traits())
  526. : Base(cmp, v_traits)
  527. {}
  528. template<class Iterator>
  529. splaytree( bool unique, Iterator b, Iterator e
  530. , const value_compare &cmp = value_compare()
  531. , const value_traits &v_traits = value_traits())
  532. : Base(unique, b, e, cmp, v_traits)
  533. {}
  534. splaytree(BOOST_RV_REF(splaytree) x)
  535. : Base(::boost::move(static_cast<Base&>(x)))
  536. {}
  537. splaytree& operator=(BOOST_RV_REF(splaytree) x)
  538. { return static_cast<splaytree &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); }
  539. static splaytree &container_from_end_iterator(iterator end_iterator)
  540. { return static_cast<splaytree &>(Base::container_from_end_iterator(end_iterator)); }
  541. static const splaytree &container_from_end_iterator(const_iterator end_iterator)
  542. { return static_cast<const splaytree &>(Base::container_from_end_iterator(end_iterator)); }
  543. static splaytree &container_from_iterator(iterator it)
  544. { return static_cast<splaytree &>(Base::container_from_iterator(it)); }
  545. static const splaytree &container_from_iterator(const_iterator it)
  546. { return static_cast<const splaytree &>(Base::container_from_iterator(it)); }
  547. };
  548. #endif
  549. } //namespace intrusive
  550. } //namespace boost
  551. #include <boost/intrusive/detail/config_end.hpp>
  552. #endif //BOOST_INTRUSIVE_SPLAYTREE_HPP