treap.hpp 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2008-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_TREAP_HPP
  13. #define BOOST_INTRUSIVE_TREAP_HPP
  14. #include <boost/intrusive/detail/config_begin.hpp>
  15. #include <algorithm>
  16. #include <cstddef>
  17. #include <functional>
  18. #include <iterator>
  19. #include <utility>
  20. #include <boost/intrusive/detail/assert.hpp>
  21. #include <boost/static_assert.hpp>
  22. #include <boost/intrusive/intrusive_fwd.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/detail/ebo_functor_holder.hpp>
  27. #include <boost/intrusive/pointer_traits.hpp>
  28. #include <boost/intrusive/detail/utilities.hpp>
  29. #include <boost/intrusive/pointer_traits.hpp>
  30. #include <boost/intrusive/options.hpp>
  31. #include <boost/intrusive/detail/mpl.hpp>
  32. #include <boost/intrusive/treap_algorithms.hpp>
  33. #include <boost/intrusive/link_mode.hpp>
  34. #include <boost/move/move.hpp>
  35. #include <boost/intrusive/priority_compare.hpp>
  36. namespace boost {
  37. namespace intrusive {
  38. /// @cond
  39. struct treap_defaults
  40. {
  41. typedef detail::default_bstree_hook proto_value_traits;
  42. static const bool constant_time_size = true;
  43. typedef std::size_t size_type;
  44. typedef void compare;
  45. typedef void priority;
  46. };
  47. /// @endcond
  48. //! The class template treap is an intrusive treap container that
  49. //! is used to construct intrusive set and multiset containers. The no-throw
  50. //! guarantee holds only, if the value_compare object and priority_compare object
  51. //! don't throw.
  52. //!
  53. //! The template parameter \c T is the type to be managed by the container.
  54. //! The user can specify additional options and if no options are provided
  55. //! default options are used.
  56. //!
  57. //! The container supports the following options:
  58. //! \c base_hook<>/member_hook<>/value_traits<>,
  59. //! \c constant_time_size<>, \c size_type<>,
  60. //! \c compare<> and \c priority_compare<>
  61. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  62. template<class T, class ...Options>
  63. #else
  64. template<class ValueTraits, class VoidOrKeyComp, class VoidOrPrioComp, class SizeType, bool ConstantTimeSize>
  65. #endif
  66. class treap_impl
  67. /// @cond
  68. : public bstree_impl<ValueTraits, VoidOrKeyComp, SizeType, ConstantTimeSize, BsTreeAlgorithms>
  69. , public detail::ebo_functor_holder
  70. < typename get_prio
  71. < VoidOrPrioComp
  72. , typename bstree_impl
  73. <ValueTraits, VoidOrKeyComp, SizeType, ConstantTimeSize, BsTreeAlgorithms>::value_type>::type
  74. >
  75. /// @endcond
  76. {
  77. public:
  78. typedef ValueTraits value_traits;
  79. /// @cond
  80. typedef bstree_impl< ValueTraits, VoidOrKeyComp, SizeType
  81. , ConstantTimeSize, BsTreeAlgorithms> tree_type;
  82. typedef tree_type implementation_defined;
  83. typedef typename tree_type::real_value_traits real_value_traits;
  84. typedef get_prio
  85. < VoidOrPrioComp
  86. , typename tree_type::value_type> get_prio_type;
  87. typedef detail::ebo_functor_holder
  88. <typename get_prio_type::type> prio_base;
  89. /// @endcond
  90. typedef typename implementation_defined::pointer pointer;
  91. typedef typename implementation_defined::const_pointer const_pointer;
  92. typedef typename implementation_defined::value_type value_type;
  93. typedef typename implementation_defined::key_type key_type;
  94. typedef typename implementation_defined::reference reference;
  95. typedef typename implementation_defined::const_reference const_reference;
  96. typedef typename implementation_defined::difference_type difference_type;
  97. typedef typename implementation_defined::size_type size_type;
  98. typedef typename implementation_defined::value_compare value_compare;
  99. typedef typename implementation_defined::key_compare key_compare;
  100. typedef typename implementation_defined::iterator iterator;
  101. typedef typename implementation_defined::const_iterator const_iterator;
  102. typedef typename implementation_defined::reverse_iterator reverse_iterator;
  103. typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
  104. typedef typename implementation_defined::node_traits node_traits;
  105. typedef typename implementation_defined::node node;
  106. typedef typename implementation_defined::node_ptr node_ptr;
  107. typedef typename implementation_defined::const_node_ptr const_node_ptr;
  108. typedef BOOST_INTRUSIVE_IMPDEF(treap_algorithms<node_traits>) node_algorithms;
  109. typedef BOOST_INTRUSIVE_IMPDEF(typename get_prio_type::type) priority_compare;
  110. static const bool constant_time_size = implementation_defined::constant_time_size;
  111. static const bool stateful_value_traits = implementation_defined::stateful_value_traits;
  112. static const bool safemode_or_autounlink = is_safe_autounlink<real_value_traits::link_mode>::value;
  113. /// @cond
  114. private:
  115. //noncopyable
  116. BOOST_MOVABLE_BUT_NOT_COPYABLE(treap_impl)
  117. const priority_compare &priv_pcomp() const
  118. { return static_cast<const prio_base&>(*this).get(); }
  119. priority_compare &priv_pcomp()
  120. { return static_cast<prio_base&>(*this).get(); }
  121. /// @endcond
  122. public:
  123. typedef typename node_algorithms::insert_commit_data insert_commit_data;
  124. //! <b>Effects</b>: Constructs an empty container.
  125. //!
  126. //! <b>Complexity</b>: Constant.
  127. //!
  128. //! <b>Throws</b>: If value_traits::node_traits::node
  129. //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
  130. //! or the copy constructor of the value_compare/priority_compare objects throw. Basic guarantee.
  131. explicit treap_impl( const value_compare &cmp = value_compare()
  132. , const priority_compare &pcmp = priority_compare()
  133. , const value_traits &v_traits = value_traits())
  134. : tree_type(cmp, v_traits), prio_base(pcmp)
  135. {}
  136. //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
  137. //! cmp must be a comparison function that induces a strict weak ordering.
  138. //!
  139. //! <b>Effects</b>: Constructs an empty container and inserts elements from
  140. //! [b, e).
  141. //!
  142. //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
  143. //! comp and otherwise N * log N, where N is the distance between first and last.
  144. //!
  145. //! <b>Throws</b>: If value_traits::node_traits::node
  146. //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
  147. //! or the copy constructor/operator() of the value_compare/priority_compare objects
  148. //! throw. Basic guarantee.
  149. template<class Iterator>
  150. treap_impl( bool unique, Iterator b, Iterator e
  151. , const value_compare &cmp = value_compare()
  152. , const priority_compare &pcmp = priority_compare()
  153. , const value_traits &v_traits = value_traits())
  154. : tree_type(cmp, v_traits), prio_base(pcmp)
  155. {
  156. if(unique)
  157. this->insert_unique(b, e);
  158. else
  159. this->insert_equal(b, e);
  160. }
  161. //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&)
  162. treap_impl(BOOST_RV_REF(treap_impl) x)
  163. : tree_type(::boost::move(static_cast<tree_type&>(x)))
  164. , prio_base(::boost::move(x.priv_pcomp()))
  165. {}
  166. //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&)
  167. treap_impl& operator=(BOOST_RV_REF(treap_impl) x)
  168. { this->swap(x); return *this; }
  169. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  170. //! @copydoc ::boost::intrusive::bstree::~bstree()
  171. ~treap_impl();
  172. //! @copydoc ::boost::intrusive::bstree::begin()
  173. iterator begin();
  174. //! @copydoc ::boost::intrusive::bstree::begin()const
  175. const_iterator begin() const;
  176. //! @copydoc ::boost::intrusive::bstree::cbegin()const
  177. const_iterator cbegin() const;
  178. //! @copydoc ::boost::intrusive::bstree::end()
  179. iterator end();
  180. //! @copydoc ::boost::intrusive::bstree::end()const
  181. const_iterator end() const;
  182. //! @copydoc ::boost::intrusive::bstree::cend()const
  183. const_iterator cend() const;
  184. #endif
  185. //! <b>Effects</b>: Returns an iterator pointing to the highest priority object of the treap.
  186. //!
  187. //! <b>Complexity</b>: Constant.
  188. //!
  189. //! <b>Throws</b>: Nothing.
  190. iterator top()
  191. { return this->empty() ? this->end() : iterator(node_traits::get_parent(this->tree_type::header_ptr()), this); }
  192. //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the treap..
  193. //!
  194. //! <b>Complexity</b>: Constant.
  195. //!
  196. //! <b>Throws</b>: Nothing.
  197. const_iterator top() const
  198. { return this->ctop(); }
  199. //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the treap..
  200. //!
  201. //! <b>Complexity</b>: Constant.
  202. //!
  203. //! <b>Throws</b>: Nothing.
  204. const_iterator ctop() const
  205. { return this->empty() ? this->cend() : const_iterator(node_traits::get_parent(this->tree_type::header_ptr()), this); }
  206. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  207. //! @copydoc ::boost::intrusive::bstree::rbegin()
  208. reverse_iterator rbegin();
  209. //! @copydoc ::boost::intrusive::bstree::rbegin()const
  210. const_reverse_iterator rbegin() const;
  211. //! @copydoc ::boost::intrusive::bstree::crbegin()const
  212. const_reverse_iterator crbegin() const;
  213. //! @copydoc ::boost::intrusive::bstree::rend()
  214. reverse_iterator rend();
  215. //! @copydoc ::boost::intrusive::bstree::rend()const
  216. const_reverse_iterator rend() const;
  217. //! @copydoc ::boost::intrusive::bstree::crend()const
  218. const_reverse_iterator crend() const;
  219. #endif
  220. //! <b>Effects</b>: Returns a reverse_iterator pointing to the highest priority object of the
  221. //! reversed treap.
  222. //!
  223. //! <b>Complexity</b>: Constant.
  224. //!
  225. //! <b>Throws</b>: Nothing.
  226. reverse_iterator rtop()
  227. { return reverse_iterator(this->top()); }
  228. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority objec
  229. //! of the reversed treap.
  230. //!
  231. //! <b>Complexity</b>: Constant.
  232. //!
  233. //! <b>Throws</b>: Nothing.
  234. const_reverse_iterator rtop() const
  235. { return const_reverse_iterator(this->top()); }
  236. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority object
  237. //! of the reversed treap.
  238. //!
  239. //! <b>Complexity</b>: Constant.
  240. //!
  241. //! <b>Throws</b>: Nothing.
  242. const_reverse_iterator crtop() const
  243. { return const_reverse_iterator(this->top()); }
  244. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  245. //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator)
  246. static treap_impl &container_from_end_iterator(iterator end_iterator);
  247. //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator)
  248. static const treap_impl &container_from_end_iterator(const_iterator end_iterator);
  249. //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator)
  250. static treap_impl &container_from_iterator(iterator it);
  251. //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator)
  252. static const treap_impl &container_from_iterator(const_iterator it);
  253. //! @copydoc ::boost::intrusive::bstree::key_comp()const
  254. key_compare key_comp() const;
  255. //! @copydoc ::boost::intrusive::bstree::value_comp()const
  256. value_compare value_comp() const;
  257. //! @copydoc ::boost::intrusive::bstree::empty()const
  258. bool empty() const;
  259. //! @copydoc ::boost::intrusive::bstree::size()const
  260. size_type size() const;
  261. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  262. //! <b>Effects</b>: Returns the priority_compare object used by the container.
  263. //!
  264. //! <b>Complexity</b>: Constant.
  265. //!
  266. //! <b>Throws</b>: If priority_compare copy-constructor throws.
  267. priority_compare priority_comp() const
  268. { return this->priv_pcomp(); }
  269. //! <b>Effects</b>: Swaps the contents of two treaps.
  270. //!
  271. //! <b>Complexity</b>: Constant.
  272. //!
  273. //! <b>Throws</b>: If the comparison functor's swap call throws.
  274. void swap(treap_impl& other)
  275. {
  276. tree_type::swap(other);
  277. //This can throw
  278. using std::swap;
  279. swap(this->priv_pcomp(), other.priv_pcomp());
  280. }
  281. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  282. //! Cloner should yield to nodes equivalent to the original nodes.
  283. //!
  284. //! <b>Effects</b>: Erases all the elements from *this
  285. //! calling Disposer::operator()(pointer), clones all the
  286. //! elements from src calling Cloner::operator()(const_reference )
  287. //! and inserts them on *this. Copies the predicate from the source container.
  288. //!
  289. //! If cloner throws, all cloned elements are unlinked and disposed
  290. //! calling Disposer::operator()(pointer).
  291. //!
  292. //! <b>Complexity</b>: Linear to erased plus inserted elements.
  293. //!
  294. //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
  295. template <class Cloner, class Disposer>
  296. void clone_from(const treap_impl &src, Cloner cloner, Disposer disposer)
  297. {
  298. tree_type::clone_from(src, cloner, disposer);
  299. this->priv_pcomp() = src.priv_pcomp();
  300. }
  301. //! <b>Requires</b>: value must be an lvalue
  302. //!
  303. //! <b>Effects</b>: Inserts value into the container before the upper bound.
  304. //!
  305. //! <b>Complexity</b>: Average complexity for insert element is at
  306. //! most logarithmic.
  307. //!
  308. //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw. Strong guarantee.
  309. //!
  310. //! <b>Note</b>: Does not affect the validity of iterators and references.
  311. //! No copy-constructors are called.
  312. iterator insert_equal(reference value)
  313. {
  314. detail::key_nodeptr_comp<value_compare, real_value_traits>
  315. key_node_comp(this->value_comp(), &this->get_real_value_traits());
  316. detail::key_nodeptr_comp<priority_compare, real_value_traits>
  317. key_node_pcomp(this->priv_pcomp(), &this->get_real_value_traits());
  318. node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
  319. if(safemode_or_autounlink)
  320. BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
  321. iterator ret(node_algorithms::insert_equal_upper_bound
  322. (this->tree_type::header_ptr(), to_insert, key_node_comp, key_node_pcomp), this->real_value_traits_ptr());
  323. this->tree_type::sz_traits().increment();
  324. return ret;
  325. }
  326. //! <b>Requires</b>: value must be an lvalue, and "hint" must be
  327. //! a valid iterator.
  328. //!
  329. //! <b>Effects</b>: Inserts x into the container, using "hint" as a hint to
  330. //! where it will be inserted. If "hint" is the upper_bound
  331. //! the insertion takes constant time (two comparisons in the worst case)
  332. //!
  333. //! <b>Complexity</b>: Logarithmic in general, but it is amortized
  334. //! constant time if t is inserted immediately before hint.
  335. //!
  336. //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw. Strong guarantee.
  337. //!
  338. //! <b>Note</b>: Does not affect the validity of iterators and references.
  339. //! No copy-constructors are called.
  340. iterator insert_equal(const_iterator hint, reference value)
  341. {
  342. detail::key_nodeptr_comp<value_compare, real_value_traits>
  343. key_node_comp(this->value_comp(), &this->get_real_value_traits());
  344. detail::key_nodeptr_comp<priority_compare, real_value_traits>
  345. key_node_pcomp(this->priv_pcomp(), &this->get_real_value_traits());
  346. node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
  347. if(safemode_or_autounlink)
  348. BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
  349. iterator ret (node_algorithms::insert_equal
  350. (this->tree_type::header_ptr(), hint.pointed_node(), to_insert, key_node_comp, key_node_pcomp), this->real_value_traits_ptr());
  351. this->tree_type::sz_traits().increment();
  352. return ret;
  353. }
  354. //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
  355. //! of type value_type.
  356. //!
  357. //! <b>Effects</b>: Inserts a each element of a range into the container
  358. //! before the upper bound of the key of each element.
  359. //!
  360. //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
  361. //! size of the range. However, it is linear in N if the range is already sorted
  362. //! by value_comp().
  363. //!
  364. //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw.
  365. //! Strong guarantee.
  366. //!
  367. //! <b>Note</b>: Does not affect the validity of iterators and references.
  368. //! No copy-constructors are called.
  369. template<class Iterator>
  370. void insert_equal(Iterator b, Iterator e)
  371. {
  372. iterator iend(this->end());
  373. for (; b != e; ++b)
  374. this->insert_equal(iend, *b);
  375. }
  376. //! <b>Requires</b>: value must be an lvalue
  377. //!
  378. //! <b>Effects</b>: Inserts value into the container if the value
  379. //! is not already present.
  380. //!
  381. //! <b>Complexity</b>: Average complexity for insert element is at
  382. //! most logarithmic.
  383. //!
  384. //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw.
  385. //! Strong guarantee.
  386. //!
  387. //! <b>Note</b>: Does not affect the validity of iterators and references.
  388. //! No copy-constructors are called.
  389. std::pair<iterator, bool> insert_unique(reference value)
  390. {
  391. insert_commit_data commit_data;
  392. std::pair<iterator, bool> ret = insert_unique_check(value, this->value_comp(), this->priv_pcomp(), commit_data);
  393. if(!ret.second)
  394. return ret;
  395. return std::pair<iterator, bool> (insert_unique_commit(value, commit_data), true);
  396. }
  397. //! <b>Requires</b>: value must be an lvalue, and "hint" must be
  398. //! a valid iterator
  399. //!
  400. //! <b>Effects</b>: Tries to insert x into the container, using "hint" as a hint
  401. //! to where it will be inserted.
  402. //!
  403. //! <b>Complexity</b>: Logarithmic in general, but it is amortized
  404. //! constant time (two comparisons in the worst case)
  405. //! if t is inserted immediately before hint.
  406. //!
  407. //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw.
  408. //! Strong guarantee.
  409. //!
  410. //! <b>Note</b>: Does not affect the validity of iterators and references.
  411. //! No copy-constructors are called.
  412. iterator insert_unique(const_iterator hint, reference value)
  413. {
  414. insert_commit_data commit_data;
  415. std::pair<iterator, bool> ret = insert_unique_check(hint, value, this->value_comp(), this->priv_pcomp(), commit_data);
  416. if(!ret.second)
  417. return ret.first;
  418. return insert_unique_commit(value, commit_data);
  419. }
  420. //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
  421. //! of type value_type.
  422. //!
  423. //! <b>Effects</b>: Tries to insert each element of a range into the container.
  424. //!
  425. //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
  426. //! size of the range. However, it is linear in N if the range is already sorted
  427. //! by value_comp().
  428. //!
  429. //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw.
  430. //! Strong guarantee.
  431. //!
  432. //! <b>Note</b>: Does not affect the validity of iterators and references.
  433. //! No copy-constructors are called.
  434. template<class Iterator>
  435. void insert_unique(Iterator b, Iterator e)
  436. {
  437. if(this->empty()){
  438. iterator iend(this->end());
  439. for (; b != e; ++b)
  440. this->insert_unique(iend, *b);
  441. }
  442. else{
  443. for (; b != e; ++b)
  444. this->insert_unique(*b);
  445. }
  446. }
  447. //! <b>Requires</b>: key_value_comp must be a comparison function that induces
  448. //! the same strict weak ordering as value_compare.
  449. //! key_value_pcomp must be a comparison function that induces
  450. //! the same strict weak ordering as priority_compare. The difference is that
  451. //! key_value_pcomp and key_value_comp compare an arbitrary key with the contained values.
  452. //!
  453. //! <b>Effects</b>: Checks if a value can be inserted in the container, using
  454. //! a user provided key instead of the value itself.
  455. //!
  456. //! <b>Returns</b>: If there is an equivalent value
  457. //! returns a pair containing an iterator to the already present value
  458. //! and false. If the value can be inserted returns true in the returned
  459. //! pair boolean and fills "commit_data" that is meant to be used with
  460. //! the "insert_commit" function.
  461. //!
  462. //! <b>Complexity</b>: Average complexity is at most logarithmic.
  463. //!
  464. //! <b>Throws</b>: If the key_value_comp or key_value_pcomp
  465. //! ordering functions throw. Strong guarantee.
  466. //!
  467. //! <b>Notes</b>: This function is used to improve performance when constructing
  468. //! a value_type is expensive: if there is an equivalent value
  469. //! the constructed object must be discarded. Many times, the part of the
  470. //! node that is used to impose the order is much cheaper to construct
  471. //! than the value_type and this function offers the possibility to use that
  472. //! part to check if the insertion will be successful.
  473. //!
  474. //! If the check is successful, the user can construct the value_type and use
  475. //! "insert_commit" to insert the object in constant-time. This gives a total
  476. //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
  477. //!
  478. //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
  479. //! objects are inserted or erased from the container.
  480. template<class KeyType, class KeyValueCompare, class KeyValuePrioCompare>
  481. std::pair<iterator, bool> insert_unique_check
  482. ( const KeyType &key, KeyValueCompare key_value_comp
  483. , KeyValuePrioCompare key_value_pcomp, insert_commit_data &commit_data)
  484. {
  485. detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
  486. ocomp(key_value_comp, &this->get_real_value_traits());
  487. detail::key_nodeptr_comp<KeyValuePrioCompare, real_value_traits>
  488. pcomp(key_value_pcomp, &this->get_real_value_traits());
  489. std::pair<node_ptr, bool> ret =
  490. (node_algorithms::insert_unique_check
  491. (this->tree_type::header_ptr(), key, ocomp, pcomp, commit_data));
  492. return std::pair<iterator, bool>(iterator(ret.first, this->real_value_traits_ptr()), ret.second);
  493. }
  494. //! <b>Requires</b>: key_value_comp must be a comparison function that induces
  495. //! the same strict weak ordering as value_compare.
  496. //! key_value_pcomp must be a comparison function that induces
  497. //! the same strict weak ordering as priority_compare. The difference is that
  498. //! key_value_pcomp and key_value_comp compare an arbitrary key with the contained values.
  499. //!
  500. //! <b>Effects</b>: Checks if a value can be inserted in the container, using
  501. //! a user provided key instead of the value itself, using "hint"
  502. //! as a hint to where it will be inserted.
  503. //!
  504. //! <b>Returns</b>: If there is an equivalent value
  505. //! returns a pair containing an iterator to the already present value
  506. //! and false. If the value can be inserted returns true in the returned
  507. //! pair boolean and fills "commit_data" that is meant to be used with
  508. //! the "insert_commit" function.
  509. //!
  510. //! <b>Complexity</b>: Logarithmic in general, but it's amortized
  511. //! constant time if t is inserted immediately before hint.
  512. //!
  513. //! <b>Throws</b>: If the key_value_comp or key_value_pcomp
  514. //! ordering functions throw. Strong guarantee.
  515. //!
  516. //! <b>Notes</b>: This function is used to improve performance when constructing
  517. //! a value_type is expensive: if there is an equivalent value
  518. //! the constructed object must be discarded. Many times, the part of the
  519. //! constructing that is used to impose the order is much cheaper to construct
  520. //! than the value_type and this function offers the possibility to use that key
  521. //! to check if the insertion will be successful.
  522. //!
  523. //! If the check is successful, the user can construct the value_type and use
  524. //! "insert_commit" to insert the object in constant-time. This can give a total
  525. //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
  526. //!
  527. //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
  528. //! objects are inserted or erased from the container.
  529. template<class KeyType, class KeyValueCompare, class KeyValuePrioCompare>
  530. std::pair<iterator, bool> insert_unique_check
  531. ( const_iterator hint, const KeyType &key
  532. , KeyValueCompare key_value_comp
  533. , KeyValuePrioCompare key_value_pcomp
  534. , insert_commit_data &commit_data)
  535. {
  536. detail::key_nodeptr_comp<KeyValueCompare, real_value_traits>
  537. ocomp(key_value_comp, &this->get_real_value_traits());
  538. detail::key_nodeptr_comp<KeyValuePrioCompare, real_value_traits>
  539. pcomp(key_value_pcomp, &this->get_real_value_traits());
  540. std::pair<node_ptr, bool> ret =
  541. (node_algorithms::insert_unique_check
  542. (this->tree_type::header_ptr(), hint.pointed_node(), key, ocomp, pcomp, commit_data));
  543. return std::pair<iterator, bool>(iterator(ret.first, this->real_value_traits_ptr()), ret.second);
  544. }
  545. //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
  546. //! must have been obtained from a previous call to "insert_check".
  547. //! No objects should have been inserted or erased from the container between
  548. //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
  549. //!
  550. //! <b>Effects</b>: Inserts the value in the avl_set using the information obtained
  551. //! from the "commit_data" that a previous "insert_check" filled.
  552. //!
  553. //! <b>Returns</b>: An iterator to the newly inserted object.
  554. //!
  555. //! <b>Complexity</b>: Constant time.
  556. //!
  557. //! <b>Throws</b>: Nothing
  558. //!
  559. //! <b>Notes</b>: This function has only sense if a "insert_check" has been
  560. //! previously executed to fill "commit_data". No value should be inserted or
  561. //! erased between the "insert_check" and "insert_commit" calls.
  562. iterator insert_unique_commit(reference value, const insert_commit_data &commit_data)
  563. {
  564. node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
  565. if(safemode_or_autounlink)
  566. BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
  567. node_algorithms::insert_unique_commit(this->tree_type::header_ptr(), to_insert, commit_data);
  568. this->tree_type::sz_traits().increment();
  569. return iterator(to_insert, this->real_value_traits_ptr());
  570. }
  571. //! <b>Requires</b>: value must be an lvalue, "pos" must be
  572. //! a valid iterator (or end) and must be the succesor of value
  573. //! once inserted according to the predicate
  574. //!
  575. //! <b>Effects</b>: Inserts x into the container before "pos".
  576. //!
  577. //! <b>Complexity</b>: Constant time.
  578. //!
  579. //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee.
  580. //!
  581. //! <b>Note</b>: This function does not check preconditions so if "pos" is not
  582. //! the successor of "value" container ordering invariant will be broken.
  583. //! This is a low-level function to be used only for performance reasons
  584. //! by advanced users.
  585. iterator insert_before(const_iterator pos, reference value)
  586. {
  587. node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
  588. if(safemode_or_autounlink)
  589. BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
  590. detail::key_nodeptr_comp<priority_compare, real_value_traits>
  591. pcomp(this->priv_pcomp(), &this->get_real_value_traits());
  592. iterator ret (node_algorithms::insert_before
  593. (this->tree_type::header_ptr(), pos.pointed_node(), to_insert, pcomp), this->real_value_traits_ptr());
  594. this->tree_type::sz_traits().increment();
  595. return ret;
  596. }
  597. //! <b>Requires</b>: value must be an lvalue, and it must be no less
  598. //! than the greatest inserted key
  599. //!
  600. //! <b>Effects</b>: Inserts x into the container in the last position.
  601. //!
  602. //! <b>Complexity</b>: Constant time.
  603. //!
  604. //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee.
  605. //!
  606. //! <b>Note</b>: This function does not check preconditions so if value is
  607. //! less than the greatest inserted key container ordering invariant will be broken.
  608. //! This function is slightly more efficient than using "insert_before".
  609. //! This is a low-level function to be used only for performance reasons
  610. //! by advanced users.
  611. void push_back(reference value)
  612. {
  613. node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
  614. if(safemode_or_autounlink)
  615. BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
  616. detail::key_nodeptr_comp<priority_compare, real_value_traits>
  617. pcomp(this->priv_pcomp(), &this->get_real_value_traits());
  618. node_algorithms::push_back(this->tree_type::header_ptr(), to_insert, pcomp);
  619. this->tree_type::sz_traits().increment();
  620. }
  621. //! <b>Requires</b>: value must be an lvalue, and it must be no greater
  622. //! than the minimum inserted key
  623. //!
  624. //! <b>Effects</b>: Inserts x into the container in the first position.
  625. //!
  626. //! <b>Complexity</b>: Constant time.
  627. //!
  628. //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee.
  629. //!
  630. //! <b>Note</b>: This function does not check preconditions so if value is
  631. //! greater than the minimum inserted key container ordering invariant will be broken.
  632. //! This function is slightly more efficient than using "insert_before".
  633. //! This is a low-level function to be used only for performance reasons
  634. //! by advanced users.
  635. void push_front(reference value)
  636. {
  637. node_ptr to_insert(this->get_real_value_traits().to_node_ptr(value));
  638. if(safemode_or_autounlink)
  639. BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
  640. detail::key_nodeptr_comp<priority_compare, real_value_traits>
  641. pcomp(this->priv_pcomp(), &this->get_real_value_traits());
  642. node_algorithms::push_front(this->tree_type::header_ptr(), to_insert, pcomp);
  643. this->tree_type::sz_traits().increment();
  644. }
  645. //! <b>Effects</b>: Erases the element pointed to by pos.
  646. //!
  647. //! <b>Complexity</b>: Average complexity for erase element is constant time.
  648. //!
  649. //! <b>Throws</b>: if the internal priority_compare function throws. Strong guarantee.
  650. //!
  651. //! <b>Note</b>: Invalidates the iterators (but not the references)
  652. //! to the erased elements. No destructors are called.
  653. iterator erase(const_iterator i)
  654. {
  655. const_iterator ret(i);
  656. ++ret;
  657. node_ptr to_erase(i.pointed_node());
  658. if(safemode_or_autounlink)
  659. BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase));
  660. detail::key_nodeptr_comp<priority_compare, real_value_traits>
  661. key_node_pcomp(this->priv_pcomp(), &this->get_real_value_traits());
  662. node_algorithms::erase(this->tree_type::header_ptr(), to_erase, key_node_pcomp);
  663. this->tree_type::sz_traits().decrement();
  664. if(safemode_or_autounlink)
  665. node_algorithms::init(to_erase);
  666. return ret.unconst();
  667. }
  668. //! <b>Effects</b>: Erases the range pointed to by b end e.
  669. //!
  670. //! <b>Complexity</b>: Average complexity for erase range is at most
  671. //! O(log(size() + N)), where N is the number of elements in the range.
  672. //!
  673. //! <b>Throws</b>: if the internal priority_compare function throws. Strong guarantee.
  674. //!
  675. //! <b>Note</b>: Invalidates the iterators (but not the references)
  676. //! to the erased elements. No destructors are called.
  677. iterator erase(const_iterator b, const_iterator e)
  678. { size_type n; return private_erase(b, e, n); }
  679. //! <b>Effects</b>: Erases all the elements with the given value.
  680. //!
  681. //! <b>Returns</b>: The number of erased elements.
  682. //!
  683. //! <b>Complexity</b>: O(log(size() + N).
  684. //!
  685. //! <b>Throws</b>: if the internal priority_compare function throws. Strong guarantee.
  686. //!
  687. //! <b>Note</b>: Invalidates the iterators (but not the references)
  688. //! to the erased elements. No destructors are called.
  689. size_type erase(const_reference value)
  690. { return this->erase(value, this->value_comp()); }
  691. //! <b>Effects</b>: Erases all the elements with the given key.
  692. //! according to the comparison functor "comp".
  693. //!
  694. //! <b>Returns</b>: The number of erased elements.
  695. //!
  696. //! <b>Complexity</b>: O(log(size() + N).
  697. //!
  698. //! <b>Throws</b>: if the internal priority_compare function throws.
  699. //! Equivalent guarantee to <i>while(beg != end) erase(beg++);</i>
  700. //!
  701. //! <b>Note</b>: Invalidates the iterators (but not the references)
  702. //! to the erased elements. No destructors are called.
  703. template<class KeyType, class KeyValueCompare>
  704. size_type erase(const KeyType& key, KeyValueCompare comp
  705. /// @cond
  706. , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
  707. /// @endcond
  708. )
  709. {
  710. std::pair<iterator,iterator> p = this->equal_range(key, comp);
  711. size_type n;
  712. private_erase(p.first, p.second, n);
  713. return n;
  714. }
  715. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  716. //!
  717. //! <b>Effects</b>: Erases the element pointed to by pos.
  718. //! Disposer::operator()(pointer) is called for the removed element.
  719. //!
  720. //! <b>Complexity</b>: Average complexity for erase element is constant time.
  721. //!
  722. //! <b>Throws</b>: if the internal priority_compare function throws. Strong guarantee.
  723. //!
  724. //! <b>Note</b>: Invalidates the iterators
  725. //! to the erased elements.
  726. template<class Disposer>
  727. iterator erase_and_dispose(const_iterator i, Disposer disposer)
  728. {
  729. node_ptr to_erase(i.pointed_node());
  730. iterator ret(this->erase(i));
  731. disposer(this->get_real_value_traits().to_value_ptr(to_erase));
  732. return ret;
  733. }
  734. #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  735. template<class Disposer>
  736. iterator erase_and_dispose(iterator i, Disposer disposer)
  737. { return this->erase_and_dispose(const_iterator(i), disposer); }
  738. #endif
  739. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  740. //!
  741. //! <b>Effects</b>: Erases the range pointed to by b end e.
  742. //! Disposer::operator()(pointer) is called for the removed elements.
  743. //!
  744. //! <b>Complexity</b>: Average complexity for erase range is at most
  745. //! O(log(size() + N)), where N is the number of elements in the range.
  746. //!
  747. //! <b>Throws</b>: if the internal priority_compare function throws. Strong guarantee.
  748. //!
  749. //! <b>Note</b>: Invalidates the iterators
  750. //! to the erased elements.
  751. template<class Disposer>
  752. iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
  753. { size_type n; return private_erase(b, e, n, disposer); }
  754. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  755. //!
  756. //! <b>Effects</b>: Erases all the elements with the given value.
  757. //! Disposer::operator()(pointer) is called for the removed elements.
  758. //!
  759. //! <b>Returns</b>: The number of erased elements.
  760. //!
  761. //! <b>Complexity</b>: O(log(size() + N).
  762. //!
  763. //! <b>Throws</b>: if the priority_compare function throws then weak guarantee and heap invariants are broken.
  764. //! The safest thing would be to clear or destroy the container.
  765. //!
  766. //! <b>Note</b>: Invalidates the iterators (but not the references)
  767. //! to the erased elements. No destructors are called.
  768. template<class Disposer>
  769. size_type erase_and_dispose(const_reference value, Disposer disposer)
  770. {
  771. std::pair<iterator,iterator> p = this->equal_range(value);
  772. size_type n;
  773. private_erase(p.first, p.second, n, disposer);
  774. return n;
  775. }
  776. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  777. //!
  778. //! <b>Effects</b>: Erases all the elements with the given key.
  779. //! according to the comparison functor "comp".
  780. //! Disposer::operator()(pointer) is called for the removed elements.
  781. //!
  782. //! <b>Returns</b>: The number of erased elements.
  783. //!
  784. //! <b>Complexity</b>: O(log(size() + N).
  785. //!
  786. //! <b>Throws</b>: if the priority_compare function throws then weak guarantee and heap invariants are broken.
  787. //! The safest thing would be to clear or destroy the container.
  788. //!
  789. //! <b>Note</b>: Invalidates the iterators
  790. //! to the erased elements.
  791. template<class KeyType, class KeyValueCompare, class Disposer>
  792. size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer
  793. /// @cond
  794. , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
  795. /// @endcond
  796. )
  797. {
  798. std::pair<iterator,iterator> p = this->equal_range(key, comp);
  799. size_type n;
  800. private_erase(p.first, p.second, n, disposer);
  801. return n;
  802. }
  803. //! <b>Effects</b>: Erases all of the elements.
  804. //!
  805. //! <b>Complexity</b>: Linear to the number of elements on the container.
  806. //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
  807. //!
  808. //! <b>Throws</b>: Nothing.
  809. //!
  810. //! <b>Note</b>: Invalidates the iterators (but not the references)
  811. //! to the erased elements. No destructors are called.
  812. void clear()
  813. { tree_type::clear(); }
  814. //! <b>Effects</b>: Erases all of the elements calling disposer(p) for
  815. //! each node to be erased.
  816. //! <b>Complexity</b>: Average complexity for is at most O(log(size() + N)),
  817. //! where N is the number of elements in the container.
  818. //!
  819. //! <b>Throws</b>: Nothing.
  820. //!
  821. //! <b>Note</b>: Invalidates the iterators (but not the references)
  822. //! to the erased elements. Calls N times to disposer functor.
  823. template<class Disposer>
  824. void clear_and_dispose(Disposer disposer)
  825. {
  826. node_algorithms::clear_and_dispose(this->tree_type::header_ptr()
  827. , detail::node_disposer<Disposer, real_value_traits, TreapAlgorithms>(disposer, &this->get_real_value_traits()));
  828. node_algorithms::init_header(this->tree_type::header_ptr());
  829. this->tree_type::sz_traits().set_size(0);
  830. }
  831. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  832. //! @copydoc ::boost::intrusive::bstree::count(const_reference)const
  833. size_type count(const_reference value) const;
  834. //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const
  835. template<class KeyType, class KeyValueCompare>
  836. size_type count(const KeyType& key, KeyValueCompare comp) const;
  837. //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)
  838. iterator lower_bound(const_reference value);
  839. //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)
  840. template<class KeyType, class KeyValueCompare>
  841. iterator lower_bound(const KeyType& key, KeyValueCompare comp);
  842. //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const
  843. const_iterator lower_bound(const_reference value) const;
  844. //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const
  845. template<class KeyType, class KeyValueCompare>
  846. const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const;
  847. //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)
  848. iterator upper_bound(const_reference value);
  849. //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)
  850. template<class KeyType, class KeyValueCompare>
  851. iterator upper_bound(const KeyType& key, KeyValueCompare comp);
  852. //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const
  853. const_iterator upper_bound(const_reference value) const;
  854. //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const
  855. template<class KeyType, class KeyValueCompare>
  856. const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const;
  857. //! @copydoc ::boost::intrusive::bstree::find(const_reference)
  858. iterator find(const_reference value);
  859. //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)
  860. template<class KeyType, class KeyValueCompare>
  861. iterator find(const KeyType& key, KeyValueCompare comp);
  862. //! @copydoc ::boost::intrusive::bstree::find(const_reference)const
  863. const_iterator find(const_reference value) const;
  864. //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const
  865. template<class KeyType, class KeyValueCompare>
  866. const_iterator find(const KeyType& key, KeyValueCompare comp) const;
  867. //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)
  868. std::pair<iterator,iterator> equal_range(const_reference value);
  869. //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)
  870. template<class KeyType, class KeyValueCompare>
  871. std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp);
  872. //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const
  873. std::pair<const_iterator, const_iterator>
  874. equal_range(const_reference value) const;
  875. //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)const
  876. template<class KeyType, class KeyValueCompare>
  877. std::pair<const_iterator, const_iterator>
  878. equal_range(const KeyType& key, KeyValueCompare comp) const;
  879. //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)
  880. std::pair<iterator,iterator> bounded_range
  881. (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed);
  882. //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)
  883. template<class KeyType, class KeyValueCompare>
  884. std::pair<iterator,iterator> bounded_range
  885. (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed);
  886. //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const
  887. std::pair<const_iterator, const_iterator>
  888. bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const;
  889. //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const
  890. template<class KeyType, class KeyValueCompare>
  891. std::pair<const_iterator, const_iterator> bounded_range
  892. (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const;
  893. //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference)
  894. static iterator s_iterator_to(reference value);
  895. //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference)
  896. static const_iterator s_iterator_to(const_reference value);
  897. //! @copydoc ::boost::intrusive::bstree::iterator_to(reference)
  898. iterator iterator_to(reference value);
  899. //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const
  900. const_iterator iterator_to(const_reference value) const;
  901. //! @copydoc ::boost::intrusive::bstree::init_node(reference)
  902. static void init_node(reference value);
  903. //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance
  904. pointer unlink_leftmost_without_rebalance();
  905. //! @copydoc ::boost::intrusive::bstree::replace_node
  906. void replace_node(iterator replace_this, reference with_this);
  907. //! @copydoc ::boost::intrusive::bstree::remove_node
  908. void remove_node(reference value);
  909. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  910. /// @cond
  911. private:
  912. template<class Disposer>
  913. iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
  914. {
  915. for(n = 0; b != e; ++n)
  916. this->erase_and_dispose(b++, disposer);
  917. return b.unconst();
  918. }
  919. iterator private_erase(const_iterator b, const_iterator e, size_type &n)
  920. {
  921. for(n = 0; b != e; ++n)
  922. this->erase(b++);
  923. return b.unconst();
  924. }
  925. /// @endcond
  926. };
  927. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  928. template<class T, class ...Options>
  929. bool operator< (const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
  930. template<class T, class ...Options>
  931. bool operator==(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
  932. template<class T, class ...Options>
  933. bool operator!= (const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
  934. template<class T, class ...Options>
  935. bool operator>(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
  936. template<class T, class ...Options>
  937. bool operator<=(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
  938. template<class T, class ...Options>
  939. bool operator>=(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
  940. template<class T, class ...Options>
  941. void swap(treap_impl<T, Options...> &x, treap_impl<T, Options...> &y);
  942. #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  943. //! Helper metafunction to define a \c treap that yields to the same type when the
  944. //! same options (either explicitly or implicitly) are used.
  945. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  946. template<class T, class ...Options>
  947. #else
  948. template<class T, class O1 = void, class O2 = void
  949. , class O3 = void, class O4 = void>
  950. #endif
  951. struct make_treap
  952. {
  953. typedef typename pack_options
  954. < treap_defaults,
  955. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  956. O1, O2, O3, O4
  957. #else
  958. Options...
  959. #endif
  960. >::type packed_options;
  961. typedef typename detail::get_value_traits
  962. <T, typename packed_options::proto_value_traits>::type value_traits;
  963. typedef treap_impl
  964. < value_traits
  965. , typename packed_options::compare
  966. , typename packed_options::priority
  967. , typename packed_options::size_type
  968. , packed_options::constant_time_size
  969. > implementation_defined;
  970. /// @endcond
  971. typedef implementation_defined type;
  972. };
  973. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  974. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  975. template<class T, class O1, class O2, class O3, class O4>
  976. #else
  977. template<class T, class ...Options>
  978. #endif
  979. class treap
  980. : public make_treap<T,
  981. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  982. O1, O2, O3, O4
  983. #else
  984. Options...
  985. #endif
  986. >::type
  987. {
  988. typedef typename make_treap
  989. <T,
  990. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  991. O1, O2, O3, O4
  992. #else
  993. Options...
  994. #endif
  995. >::type Base;
  996. BOOST_MOVABLE_BUT_NOT_COPYABLE(treap)
  997. public:
  998. typedef typename Base::value_compare value_compare;
  999. typedef typename Base::priority_compare priority_compare;
  1000. typedef typename Base::value_traits value_traits;
  1001. typedef typename Base::real_value_traits real_value_traits;
  1002. typedef typename Base::iterator iterator;
  1003. typedef typename Base::const_iterator const_iterator;
  1004. typedef typename Base::reverse_iterator reverse_iterator;
  1005. typedef typename Base::const_reverse_iterator const_reverse_iterator;
  1006. //Assert if passed value traits are compatible with the type
  1007. BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
  1008. explicit treap( const value_compare &cmp = value_compare()
  1009. , const priority_compare &pcmp = priority_compare()
  1010. , const value_traits &v_traits = value_traits())
  1011. : Base(cmp, pcmp, v_traits)
  1012. {}
  1013. template<class Iterator>
  1014. treap( bool unique, Iterator b, Iterator e
  1015. , const value_compare &cmp = value_compare()
  1016. , const priority_compare &pcmp = priority_compare()
  1017. , const value_traits &v_traits = value_traits())
  1018. : Base(unique, b, e, cmp, pcmp, v_traits)
  1019. {}
  1020. treap(BOOST_RV_REF(treap) x)
  1021. : Base(::boost::move(static_cast<Base&>(x)))
  1022. {}
  1023. treap& operator=(BOOST_RV_REF(treap) x)
  1024. { return static_cast<treap&>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); }
  1025. static treap &container_from_end_iterator(iterator end_iterator)
  1026. { return static_cast<treap &>(Base::container_from_end_iterator(end_iterator)); }
  1027. static const treap &container_from_end_iterator(const_iterator end_iterator)
  1028. { return static_cast<const treap &>(Base::container_from_end_iterator(end_iterator)); }
  1029. static treap &container_from_iterator(iterator it)
  1030. { return static_cast<treap &>(Base::container_from_iterator(it)); }
  1031. static const treap &container_from_iterator(const_iterator it)
  1032. { return static_cast<const treap &>(Base::container_from_iterator(it)); }
  1033. };
  1034. #endif
  1035. } //namespace intrusive
  1036. } //namespace boost
  1037. #include <boost/intrusive/detail/config_end.hpp>
  1038. #endif //BOOST_INTRUSIVE_TREAP_HPP