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