1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2007-2008
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)
9 // See http://www.boost.org/libs/intrusive for documentation.
11 /////////////////////////////////////////////////////////////////////////////
12 #ifndef BOOST_INTRUSIVE_TRIE_SET_HPP
13 #define BOOST_INTRUSIVE_TRIE_SET_HPP
15 #include <boost/intrusive/detail/config_begin.hpp>
16 #include <boost/intrusive/intrusive_fwd.hpp>
17 #include <boost/intrusive/treap.hpp>
18 #include <boost/intrusive/detail/mpl.hpp>
24 //! The class template treap_set is an intrusive container, that mimics most of
25 //! the interface of std::set as described in the C++ standard.
27 //! The template parameter \c T is the type to be managed by the container.
28 //! The user can specify additional options and if no options are provided
29 //! default options are used.
31 //! The container supports the following options:
32 //! \c base_hook<>/member_hook<>/value_traits<>,
33 //! \c constant_time_size<>, \c size_type<>,
34 //! \c compare<> and \c priority_compare<>
35 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
36 template<class T
, class ...Options
>
38 template<class Config
>
43 typedef treap_impl
<Config
> tree_type
;
46 treap_set_impl (const treap_set_impl
&);
50 treap_set_impl
&operator =(const treap_set_impl
&);
52 typedef tree_type implementation_defined
;
56 typedef typename
implementation_defined::value_type value_type
;
57 typedef typename
implementation_defined::value_traits value_traits
;
58 typedef typename
implementation_defined::pointer pointer
;
59 typedef typename
implementation_defined::const_pointer const_pointer
;
60 typedef typename
implementation_defined::reference reference
;
61 typedef typename
implementation_defined::const_reference const_reference
;
62 typedef typename
implementation_defined::difference_type difference_type
;
63 typedef typename
implementation_defined::size_type size_type
;
64 typedef typename
implementation_defined::value_compare value_compare
;
65 typedef typename
implementation_defined::priority_compare priority_compare
;
66 typedef typename
implementation_defined::key_compare key_compare
;
67 typedef typename
implementation_defined::iterator iterator
;
68 typedef typename
implementation_defined::const_iterator const_iterator
;
69 typedef typename
implementation_defined::reverse_iterator reverse_iterator
;
70 typedef typename
implementation_defined::const_reverse_iterator const_reverse_iterator
;
71 typedef typename
implementation_defined::insert_commit_data insert_commit_data
;
72 typedef typename
implementation_defined::node_traits node_traits
;
73 typedef typename
implementation_defined::node node
;
74 typedef typename
implementation_defined::node_ptr node_ptr
;
75 typedef typename
implementation_defined::const_node_ptr const_node_ptr
;
76 typedef typename
implementation_defined::node_algorithms node_algorithms
;
84 //! <b>Effects</b>: Constructs an empty treap_set.
86 //! <b>Complexity</b>: Constant.
88 //! <b>Throws</b>: If value_traits::node_traits::node
89 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
90 //! or the copy constructor of the value_compare object throws.
91 treap_set_impl( const value_compare
&cmp
= value_compare()
92 , const priority_compare
&pcmp
= priority_compare()
93 , const value_traits
&v_traits
= value_traits())
94 : tree_(cmp
, pcmp
, v_traits
)
97 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
98 //! cmp must be a comparison function that induces a strict weak ordering.
100 //! <b>Effects</b>: Constructs an empty treap_set and inserts elements from
103 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
104 //! comp and otherwise N * log N, where N is std::distance(last, first).
106 //! <b>Throws</b>: If value_traits::node_traits::node
107 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
108 //! or the copy constructor/operator() of the value_compare object throws.
109 template<class Iterator
>
110 treap_set_impl( Iterator b
, Iterator e
111 , const value_compare
&cmp
= value_compare()
112 , const priority_compare
&pcmp
= priority_compare()
113 , const value_traits
&v_traits
= value_traits())
114 : tree_(true, b
, e
, cmp
, pcmp
, v_traits
)
117 //! <b>Effects</b>: Detaches all elements from this. The objects in the treap_set
118 //! are not deleted (i.e. no destructors are called).
120 //! <b>Complexity</b>: Linear to the number of elements on the container.
121 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
123 //! <b>Throws</b>: Nothing.
127 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the treap_set.
129 //! <b>Complexity</b>: Constant.
131 //! <b>Throws</b>: Nothing.
133 { return tree_
.begin(); }
135 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_set.
137 //! <b>Complexity</b>: Constant.
139 //! <b>Throws</b>: Nothing.
140 const_iterator
begin() const
141 { return tree_
.begin(); }
143 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_set.
145 //! <b>Complexity</b>: Constant.
147 //! <b>Throws</b>: Nothing.
148 const_iterator
cbegin() const
149 { return tree_
.cbegin(); }
151 //! <b>Effects</b>: Returns an iterator pointing to the end of the treap_set.
153 //! <b>Complexity</b>: Constant.
155 //! <b>Throws</b>: Nothing.
157 { return tree_
.end(); }
159 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_set.
161 //! <b>Complexity</b>: Constant.
163 //! <b>Throws</b>: Nothing.
164 const_iterator
end() const
165 { return tree_
.end(); }
167 //! <b>Effects</b>: Returns an iterator pointing to the highest priority object of the tree.
169 //! <b>Complexity</b>: Constant.
171 //! <b>Throws</b>: Nothing.
173 { return tree_
.top(); }
175 //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree..
177 //! <b>Complexity</b>: Constant.
179 //! <b>Throws</b>: Nothing.
180 const_iterator
top() const
181 { return this->ctop(); }
183 //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree..
185 //! <b>Complexity</b>: Constant.
187 //! <b>Throws</b>: Nothing.
188 const_iterator
ctop() const
189 { return tree_
.ctop(); }
191 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_set.
193 //! <b>Complexity</b>: Constant.
195 //! <b>Throws</b>: Nothing.
196 const_iterator
cend() const
197 { return tree_
.cend(); }
199 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
200 //! reversed treap_set.
202 //! <b>Complexity</b>: Constant.
204 //! <b>Throws</b>: Nothing.
205 reverse_iterator
rbegin()
206 { return tree_
.rbegin(); }
208 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
209 //! of the reversed treap_set.
211 //! <b>Complexity</b>: Constant.
213 //! <b>Throws</b>: Nothing.
214 const_reverse_iterator
rbegin() const
215 { return tree_
.rbegin(); }
217 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
218 //! of the reversed treap_set.
220 //! <b>Complexity</b>: Constant.
222 //! <b>Throws</b>: Nothing.
223 const_reverse_iterator
crbegin() const
224 { return tree_
.crbegin(); }
226 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
227 //! of the reversed treap_set.
229 //! <b>Complexity</b>: Constant.
231 //! <b>Throws</b>: Nothing.
232 reverse_iterator
rend()
233 { return tree_
.rend(); }
235 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
236 //! of the reversed treap_set.
238 //! <b>Complexity</b>: Constant.
240 //! <b>Throws</b>: Nothing.
241 const_reverse_iterator
rend() const
242 { return tree_
.rend(); }
244 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
245 //! of the reversed treap_set.
247 //! <b>Complexity</b>: Constant.
249 //! <b>Throws</b>: Nothing.
250 const_reverse_iterator
crend() const
251 { return tree_
.crend(); }
253 //! <b>Effects</b>: Returns a reverse_iterator pointing to the highest priority object of the
256 //! <b>Complexity</b>: Constant.
258 //! <b>Throws</b>: Nothing.
259 reverse_iterator
rtop()
260 { return tree_
.rtop(); }
262 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority objec
263 //! of the reversed tree.
265 //! <b>Complexity</b>: Constant.
267 //! <b>Throws</b>: Nothing.
268 const_reverse_iterator
rtop() const
269 { return tree_
.crtop(); }
271 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority object
272 //! of the reversed tree.
274 //! <b>Complexity</b>: Constant.
276 //! <b>Throws</b>: Nothing.
277 const_reverse_iterator
crtop() const
278 { return tree_
.crtop(); }
280 //! <b>Precondition</b>: end_iterator must be a valid end iterator
283 //! <b>Effects</b>: Returns a const reference to the treap_set associated to the end iterator
285 //! <b>Throws</b>: Nothing.
287 //! <b>Complexity</b>: Constant.
288 static treap_set_impl
&container_from_end_iterator(iterator end_iterator
)
290 return *detail::parent_from_member
<treap_set_impl
, tree_type
>
291 ( &tree_type::container_from_end_iterator(end_iterator
)
292 , &treap_set_impl::tree_
);
295 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
298 //! <b>Effects</b>: Returns a const reference to the treap_set associated to the end iterator
300 //! <b>Throws</b>: Nothing.
302 //! <b>Complexity</b>: Constant.
303 static const treap_set_impl
&container_from_end_iterator(const_iterator end_iterator
)
305 return *detail::parent_from_member
<treap_set_impl
, tree_type
>
306 ( &tree_type::container_from_end_iterator(end_iterator
)
307 , &treap_set_impl::tree_
);
310 //! <b>Precondition</b>: it must be a valid iterator of set.
312 //! <b>Effects</b>: Returns a reference to the set associated to the iterator
314 //! <b>Throws</b>: Nothing.
316 //! <b>Complexity</b>: Logarithmic.
317 static treap_set_impl
&container_from_iterator(iterator it
)
319 return *detail::parent_from_member
<treap_set_impl
, tree_type
>
320 ( &tree_type::container_from_iterator(it
)
321 , &treap_set_impl::tree_
);
324 //! <b>Precondition</b>: it must be a valid const_iterator of set.
326 //! <b>Effects</b>: Returns a const reference to the set associated to the iterator
328 //! <b>Throws</b>: Nothing.
330 //! <b>Complexity</b>: Logarithmic.
331 static const treap_set_impl
&container_from_iterator(const_iterator it
)
333 return *detail::parent_from_member
<treap_set_impl
, tree_type
>
334 ( &tree_type::container_from_iterator(it
)
335 , &treap_set_impl::tree_
);
338 //! <b>Effects</b>: Returns the key_compare object used by the treap_set.
340 //! <b>Complexity</b>: Constant.
342 //! <b>Throws</b>: If key_compare copy-constructor throws.
343 key_compare
key_comp() const
344 { return tree_
.value_comp(); }
346 //! <b>Effects</b>: Returns the value_compare object used by the treap_set.
348 //! <b>Complexity</b>: Constant.
350 //! <b>Throws</b>: If value_compare copy-constructor throws.
351 value_compare
value_comp() const
352 { return tree_
.value_comp(); }
354 //! <b>Effects</b>: Returns true if the container is empty.
356 //! <b>Complexity</b>: Constant.
358 //! <b>Throws</b>: Nothing.
360 { return tree_
.empty(); }
362 //! <b>Effects</b>: Returns the number of elements stored in the treap_set.
364 //! <b>Complexity</b>: Linear to elements contained in *this if,
365 //! constant-time size option is enabled. Constant-time otherwise.
367 //! <b>Throws</b>: Nothing.
368 size_type
size() const
369 { return tree_
.size(); }
371 //! <b>Effects</b>: Swaps the contents of two sets.
373 //! <b>Complexity</b>: Constant.
375 //! <b>Throws</b>: If the swap() call for the comparison functor
376 //! found using ADL throws. Strong guarantee.
377 void swap(treap_set_impl
& other
)
378 { tree_
.swap(other
.tree_
); }
380 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
381 //! Cloner should yield to nodes equivalent to the original nodes.
383 //! <b>Effects</b>: Erases all the elements from *this
384 //! calling Disposer::operator()(pointer), clones all the
385 //! elements from src calling Cloner::operator()(const_reference )
386 //! and inserts them on *this. Copies the predicate from the source container.
388 //! If cloner throws, all cloned elements are unlinked and disposed
389 //! calling Disposer::operator()(pointer).
391 //! <b>Complexity</b>: Linear to erased plus inserted elements.
393 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
394 template <class Cloner
, class Disposer
>
395 void clone_from(const treap_set_impl
&src
, Cloner cloner
, Disposer disposer
)
396 { tree_
.clone_from(src
.tree_
, cloner
, disposer
); }
398 //! <b>Requires</b>: value must be an lvalue
400 //! <b>Effects</b>: Tries to inserts value into the treap_set.
402 //! <b>Returns</b>: If the value
403 //! is not already present inserts it and returns a pair containing the
404 //! iterator to the new value and true. If there is an equivalent value
405 //! returns a pair containing an iterator to the already present value
408 //! <b>Complexity</b>: Average complexity for insert element is at
409 //! most logarithmic.
411 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
413 //! <b>Note</b>: Does not affect the validity of iterators and references.
414 //! No copy-constructors are called.
415 std::pair
<iterator
, bool> insert(reference value
)
416 { return tree_
.insert_unique(value
); }
418 //! <b>Requires</b>: value must be an lvalue
420 //! <b>Effects</b>: Tries to to insert x into the treap_set, using "hint"
421 //! as a hint to where it will be inserted.
423 //! <b>Returns</b>: An iterator that points to the position where the
424 //! new element was inserted into the treap_set.
426 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
427 //! constant time if t is inserted immediately before hint.
429 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
431 //! <b>Note</b>: Does not affect the validity of iterators and references.
432 //! No copy-constructors are called.
433 iterator
insert(const_iterator hint
, reference value
)
434 { return tree_
.insert_unique(hint
, value
); }
436 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
437 //! the same strict weak ordering as value_compare. The difference is that
438 //! key_value_comp compares an ascapegoatitrary key with the contained values.
440 //! <b>Effects</b>: Checks if a value can be inserted in the treap_set, using
441 //! a user provided key instead of the value itself.
443 //! <b>Returns</b>: If there is an equivalent value
444 //! returns a pair containing an iterator to the already present value
445 //! and false. If the value can be inserted returns true in the returned
446 //! pair boolean and fills "commit_data" that is meant to be used with
447 //! the "insert_commit" function.
449 //! <b>Complexity</b>: Average complexity is at most logarithmic.
451 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
453 //! <b>Notes</b>: This function is used to improve performance when constructing
454 //! a value_type is expensive: if there is an equivalent value
455 //! the constructed object must be discarded. Many times, the part of the
456 //! node that is used to impose the order is much cheaper to construct
457 //! than the value_type and this function offers the possibility to use that
458 //! part to check if the insertion will be successful.
460 //! If the check is successful, the user can construct the value_type and use
461 //! "insert_commit" to insert the object in constant-time. This gives a total
462 //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
464 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
465 //! objects are inserted or erased from the treap_set.
466 template<class KeyType
, class KeyValueCompare
>
467 std::pair
<iterator
, bool> insert_check
468 (const KeyType
&key
, KeyValueCompare key_value_comp
, insert_commit_data
&commit_data
)
469 { return tree_
.insert_unique_check(key
, key_value_comp
, commit_data
); }
471 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
472 //! the same strict weak ordering as value_compare. The difference is that
473 //! key_value_comp compares an ascapegoatitrary key with the contained values.
475 //! <b>Effects</b>: Checks if a value can be inserted in the treap_set, using
476 //! a user provided key instead of the value itself, using "hint"
477 //! as a hint to where it will be inserted.
479 //! <b>Returns</b>: If there is an equivalent value
480 //! returns a pair containing an iterator to the already present value
481 //! and false. If the value can be inserted returns true in the returned
482 //! pair boolean and fills "commit_data" that is meant to be used with
483 //! the "insert_commit" function.
485 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
486 //! constant time if t is inserted immediately before hint.
488 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
490 //! <b>Notes</b>: This function is used to improve performance when constructing
491 //! a value_type is expensive: if there is an equivalent value
492 //! the constructed object must be discarded. Many times, the part of the
493 //! constructing that is used to impose the order is much cheaper to construct
494 //! than the value_type and this function offers the possibility to use that key
495 //! to check if the insertion will be successful.
497 //! If the check is successful, the user can construct the value_type and use
498 //! "insert_commit" to insert the object in constant-time. This can give a total
499 //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
501 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
502 //! objects are inserted or erased from the treap_set.
503 template<class KeyType
, class KeyValueCompare
>
504 std::pair
<iterator
, bool> insert_check
505 (const_iterator hint
, const KeyType
&key
506 ,KeyValueCompare key_value_comp
, insert_commit_data
&commit_data
)
507 { return tree_
.insert_unique_check(hint
, key
, key_value_comp
, commit_data
); }
509 //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
510 //! must have been obtained from a previous call to "insert_check".
511 //! No objects should have been inserted or erased from the treap_set between
512 //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
514 //! <b>Effects</b>: Inserts the value in the treap_set using the information obtained
515 //! from the "commit_data" that a previous "insert_check" filled.
517 //! <b>Returns</b>: An iterator to the newly inserted object.
519 //! <b>Complexity</b>: Constant time.
521 //! <b>Throws</b>: Nothing.
523 //! <b>Notes</b>: This function has only sense if a "insert_check" has been
524 //! previously executed to fill "commit_data". No value should be inserted or
525 //! erased between the "insert_check" and "insert_commit" calls.
526 iterator
insert_commit(reference value
, const insert_commit_data
&commit_data
)
527 { return tree_
.insert_unique_commit(value
, commit_data
); }
529 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
530 //! of type value_type.
532 //! <b>Effects</b>: Inserts a range into the treap_set.
534 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
535 //! size of the range. However, it is linear in N if the range is already sorted
538 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
540 //! <b>Note</b>: Does not affect the validity of iterators and references.
541 //! No copy-constructors are called.
542 template<class Iterator
>
543 void insert(Iterator b
, Iterator e
)
544 { tree_
.insert_unique(b
, e
); }
546 //! <b>Effects</b>: Erases the element pointed to by pos.
548 //! <b>Complexity</b>: Average complexity is constant time.
550 //! <b>Returns</b>: An iterator to the element after the erased element.
552 //! <b>Throws</b>: Nothing.
554 //! <b>Note</b>: Invalidates the iterators (but not the references)
555 //! to the erased elements. No destructors are called.
556 iterator
erase(const_iterator i
)
557 { return tree_
.erase(i
); }
559 //! <b>Effects</b>: Erases the range pointed to by b end e.
561 //! <b>Complexity</b>: Average complexity for erase range is at most
562 //! O(log(size() + N)), where N is the number of elements in the range.
564 //! <b>Returns</b>: An iterator to the element after the erased elements.
566 //! <b>Throws</b>: Nothing.
568 //! <b>Note</b>: Invalidates the iterators (but not the references)
569 //! to the erased elements. No destructors are called.
570 iterator
erase(const_iterator b
, const_iterator e
)
571 { return tree_
.erase(b
, e
); }
573 //! <b>Effects</b>: Erases all the elements with the given value.
575 //! <b>Returns</b>: The number of erased elements.
577 //! <b>Complexity</b>: O(log(size()) + this->count(value)).
579 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
581 //! <b>Note</b>: Invalidates the iterators (but not the references)
582 //! to the erased elements. No destructors are called.
583 size_type
erase(const_reference value
)
584 { return tree_
.erase(value
); }
586 //! <b>Effects</b>: Erases all the elements that compare equal with
587 //! the given key and the given comparison functor.
589 //! <b>Returns</b>: The number of erased elements.
591 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
593 //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee.
595 //! <b>Note</b>: Invalidates the iterators (but not the references)
596 //! to the erased elements. No destructors are called.
597 template<class KeyType
, class KeyValueCompare
>
598 size_type
erase(const KeyType
& key
, KeyValueCompare comp
600 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
603 { return tree_
.erase(key
, comp
); }
605 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
607 //! <b>Effects</b>: Erases the element pointed to by pos.
608 //! Disposer::operator()(pointer) is called for the removed element.
610 //! <b>Complexity</b>: Average complexity for erase element is constant time.
612 //! <b>Returns</b>: An iterator to the element after the erased element.
614 //! <b>Throws</b>: Nothing.
616 //! <b>Note</b>: Invalidates the iterators
617 //! to the erased elements.
618 template<class Disposer
>
619 iterator
erase_and_dispose(const_iterator i
, Disposer disposer
)
620 { return tree_
.erase_and_dispose(i
, disposer
); }
622 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
623 template<class Disposer
>
624 iterator
erase_and_dispose(iterator i
, Disposer disposer
)
625 { return this->erase_and_dispose(const_iterator(i
), disposer
); }
628 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
630 //! <b>Effects</b>: Erases the range pointed to by b end e.
631 //! Disposer::operator()(pointer) is called for the removed elements.
633 //! <b>Complexity</b>: Average complexity for erase range is at most
634 //! O(log(size() + N)), where N is the number of elements in the range.
636 //! <b>Returns</b>: An iterator to the element after the erased elements.
638 //! <b>Throws</b>: Nothing.
640 //! <b>Note</b>: Invalidates the iterators
641 //! to the erased elements.
642 template<class Disposer
>
643 iterator
erase_and_dispose(const_iterator b
, const_iterator e
, Disposer disposer
)
644 { return tree_
.erase_and_dispose(b
, e
, disposer
); }
646 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
648 //! <b>Effects</b>: Erases all the elements with the given value.
649 //! Disposer::operator()(pointer) is called for the removed elements.
651 //! <b>Throws</b>: If the internal value_compare ordering function throws.
653 //! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee.
655 //! <b>Throws</b>: Nothing.
657 //! <b>Note</b>: Invalidates the iterators (but not the references)
658 //! to the erased elements. No destructors are called.
659 template<class Disposer
>
660 size_type
erase_and_dispose(const_reference value
, Disposer disposer
)
661 { return tree_
.erase_and_dispose(value
, disposer
); }
663 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
665 //! <b>Effects</b>: Erases all the elements with the given key.
666 //! according to the comparison functor "comp".
667 //! Disposer::operator()(pointer) is called for the removed elements.
669 //! <b>Returns</b>: The number of erased elements.
671 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
673 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
675 //! <b>Note</b>: Invalidates the iterators
676 //! to the erased elements.
677 template<class KeyType
, class KeyValueCompare
, class Disposer
>
678 size_type
erase_and_dispose(const KeyType
& key
, KeyValueCompare comp
, Disposer disposer
680 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
683 { return tree_
.erase_and_dispose(key
, comp
, disposer
); }
685 //! <b>Effects</b>: Erases all the elements of the container.
687 //! <b>Complexity</b>: Linear to the number of elements on the container.
688 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
690 //! <b>Throws</b>: Nothing.
692 //! <b>Note</b>: Invalidates the iterators (but not the references)
693 //! to the erased elements. No destructors are called.
695 { return tree_
.clear(); }
697 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
699 //! <b>Effects</b>: Erases all the elements of the container.
701 //! <b>Complexity</b>: Linear to the number of elements on the container.
702 //! Disposer::operator()(pointer) is called for the removed elements.
704 //! <b>Throws</b>: Nothing.
706 //! <b>Note</b>: Invalidates the iterators (but not the references)
707 //! to the erased elements. No destructors are called.
708 template<class Disposer
>
709 void clear_and_dispose(Disposer disposer
)
710 { return tree_
.clear_and_dispose(disposer
); }
712 //! <b>Effects</b>: Returns the number of contained elements with the given key
714 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
715 //! to number of objects with the given key.
717 //! <b>Throws</b>: If the internal value_compare ordering function throws.
718 size_type
count(const_reference value
) const
719 { return tree_
.find(value
) != end(); }
721 //! <b>Effects</b>: Returns the number of contained elements with the same key
722 //! compared with the given comparison functor.
724 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
725 //! to number of objects with the given key.
727 //! <b>Throws</b>: If comp ordering function throws.
728 template<class KeyType
, class KeyValueCompare
>
729 size_type
count(const KeyType
& key
, KeyValueCompare comp
) const
730 { return tree_
.find(key
, comp
) != end(); }
732 //! <b>Effects</b>: Returns an iterator to the first element whose
733 //! key is not less than k or end() if that element does not exist.
735 //! <b>Complexity</b>: Logarithmic.
737 //! <b>Throws</b>: If the internal value_compare ordering function throws.
738 iterator
lower_bound(const_reference value
)
739 { return tree_
.lower_bound(value
); }
741 //! <b>Requires</b>: comp must imply the same element order as
742 //! value_compare. Usually key is the part of the value_type
743 //! that is used in the ordering functor.
745 //! <b>Effects</b>: Returns an iterator to the first element whose
746 //! key according to the comparison functor is not less than k or
747 //! end() if that element does not exist.
749 //! <b>Complexity</b>: Logarithmic.
751 //! <b>Throws</b>: If comp ordering function throws.
753 //! <b>Note</b>: This function is used when constructing a value_type
754 //! is expensive and the value_type can be compared with a cheaper
755 //! key type. Usually this key is part of the value_type.
756 template<class KeyType
, class KeyValueCompare
>
757 iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
)
758 { return tree_
.lower_bound(key
, comp
); }
760 //! <b>Effects</b>: Returns a const iterator to the first element whose
761 //! key is not less than k or end() if that element does not exist.
763 //! <b>Complexity</b>: Logarithmic.
765 //! <b>Throws</b>: If the internal value_compare ordering function throws.
766 const_iterator
lower_bound(const_reference value
) const
767 { return tree_
.lower_bound(value
); }
769 //! <b>Requires</b>: comp must imply the same element order as
770 //! value_compare. Usually key is the part of the value_type
771 //! that is used in the ordering functor.
773 //! <b>Effects</b>: Returns a const_iterator to the first element whose
774 //! key according to the comparison functor is not less than k or
775 //! end() if that element does not exist.
777 //! <b>Complexity</b>: Logarithmic.
779 //! <b>Throws</b>: If comp ordering function throws.
781 //! <b>Note</b>: This function is used when constructing a value_type
782 //! is expensive and the value_type can be compared with a cheaper
783 //! key type. Usually this key is part of the value_type.
784 template<class KeyType
, class KeyValueCompare
>
785 const_iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
) const
786 { return tree_
.lower_bound(key
, comp
); }
788 //! <b>Effects</b>: Returns an iterator to the first element whose
789 //! key is greater than k or end() if that element does not exist.
791 //! <b>Complexity</b>: Logarithmic.
793 //! <b>Throws</b>: If the internal value_compare ordering function throws.
794 iterator
upper_bound(const_reference value
)
795 { return tree_
.upper_bound(value
); }
797 //! <b>Requires</b>: comp must imply the same element order as
798 //! value_compare. Usually key is the part of the value_type
799 //! that is used in the ordering functor.
801 //! <b>Effects</b>: Returns an iterator to the first element whose
802 //! key according to the comparison functor is greater than key or
803 //! end() if that element does not exist.
805 //! <b>Complexity</b>: Logarithmic.
807 //! <b>Throws</b>: If comp ordering function throws.
809 //! <b>Note</b>: This function is used when constructing a value_type
810 //! is expensive and the value_type can be compared with a cheaper
811 //! key type. Usually this key is part of the value_type.
812 template<class KeyType
, class KeyValueCompare
>
813 iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
)
814 { return tree_
.upper_bound(key
, comp
); }
816 //! <b>Effects</b>: Returns an iterator to the first element whose
817 //! key is greater than k or end() if that element does not exist.
819 //! <b>Complexity</b>: Logarithmic.
821 //! <b>Throws</b>: If the internal value_compare ordering function throws.
822 const_iterator
upper_bound(const_reference value
) const
823 { return tree_
.upper_bound(value
); }
825 //! <b>Requires</b>: comp must imply the same element order as
826 //! value_compare. Usually key is the part of the value_type
827 //! that is used in the ordering functor.
829 //! <b>Effects</b>: Returns a const_iterator to the first element whose
830 //! key according to the comparison functor is greater than key or
831 //! end() if that element does not exist.
833 //! <b>Complexity</b>: Logarithmic.
835 //! <b>Throws</b>: If comp ordering function throws.
837 //! <b>Note</b>: This function is used when constructing a value_type
838 //! is expensive and the value_type can be compared with a cheaper
839 //! key type. Usually this key is part of the value_type.
840 template<class KeyType
, class KeyValueCompare
>
841 const_iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
) const
842 { return tree_
.upper_bound(key
, comp
); }
844 //! <b>Effects</b>: Finds an iterator to the first element whose value is
845 //! "value" or end() if that element does not exist.
847 //! <b>Complexity</b>: Logarithmic.
849 //! <b>Throws</b>: If the internal value_compare ordering function throws.
850 iterator
find(const_reference value
)
851 { return tree_
.find(value
); }
853 //! <b>Requires</b>: comp must imply the same element order as
854 //! value_compare. Usually key is the part of the value_type
855 //! that is used in the ordering functor.
857 //! <b>Effects</b>: Finds an iterator to the first element whose key is
858 //! "key" according to the comparison functor or end() if that element
861 //! <b>Complexity</b>: Logarithmic.
863 //! <b>Throws</b>: If comp ordering function throws.
865 //! <b>Note</b>: This function is used when constructing a value_type
866 //! is expensive and the value_type can be compared with a cheaper
867 //! key type. Usually this key is part of the value_type.
868 template<class KeyType
, class KeyValueCompare
>
869 iterator
find(const KeyType
& key
, KeyValueCompare comp
)
870 { return tree_
.find(key
, comp
); }
872 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
873 //! "value" or end() if that element does not exist.
875 //! <b>Complexity</b>: Logarithmic.
877 //! <b>Throws</b>: If the internal value_compare ordering function throws.
878 const_iterator
find(const_reference value
) const
879 { return tree_
.find(value
); }
881 //! <b>Requires</b>: comp must imply the same element order as
882 //! value_compare. Usually key is the part of the value_type
883 //! that is used in the ordering functor.
885 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
886 //! "key" according to the comparison functor or end() if that element
889 //! <b>Complexity</b>: Logarithmic.
891 //! <b>Throws</b>: If comp ordering function throws.
893 //! <b>Note</b>: This function is used when constructing a value_type
894 //! is expensive and the value_type can be compared with a cheaper
895 //! key type. Usually this key is part of the value_type.
896 template<class KeyType
, class KeyValueCompare
>
897 const_iterator
find(const KeyType
& key
, KeyValueCompare comp
) const
898 { return tree_
.find(key
, comp
); }
900 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
901 //! an empty range that indicates the position where those elements would be
902 //! if they there is no elements with key k.
904 //! <b>Complexity</b>: Logarithmic.
906 //! <b>Throws</b>: If the internal value_compare ordering function throws.
907 std::pair
<iterator
,iterator
> equal_range(const_reference value
)
908 { return tree_
.equal_range(value
); }
910 //! <b>Requires</b>: comp must imply the same element order as
911 //! value_compare. Usually key is the part of the value_type
912 //! that is used in the ordering functor.
914 //! <b>Effects</b>: Finds a range containing all elements whose key is k
915 //! according to the comparison functor or an empty range
916 //! that indicates the position where those elements would be
917 //! if they there is no elements with key k.
919 //! <b>Complexity</b>: Logarithmic.
921 //! <b>Throws</b>: If comp ordering function throws.
923 //! <b>Note</b>: This function is used when constructing a value_type
924 //! is expensive and the value_type can be compared with a cheaper
925 //! key type. Usually this key is part of the value_type.
926 template<class KeyType
, class KeyValueCompare
>
927 std::pair
<iterator
,iterator
> equal_range(const KeyType
& key
, KeyValueCompare comp
)
928 { return tree_
.equal_range(key
, comp
); }
930 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
931 //! an empty range that indicates the position where those elements would be
932 //! if they there is no elements with key k.
934 //! <b>Complexity</b>: Logarithmic.
936 //! <b>Throws</b>: If the internal value_compare ordering function throws.
937 std::pair
<const_iterator
, const_iterator
>
938 equal_range(const_reference value
) const
939 { return tree_
.equal_range(value
); }
941 //! <b>Requires</b>: comp must imply the same element order as
942 //! value_compare. Usually key is the part of the value_type
943 //! that is used in the ordering functor.
945 //! <b>Effects</b>: Finds a range containing all elements whose key is k
946 //! according to the comparison functor or an empty range
947 //! that indicates the position where those elements would be
948 //! if they there is no elements with key k.
950 //! <b>Complexity</b>: Logarithmic.
952 //! <b>Throws</b>: If comp ordering function throws.
954 //! <b>Note</b>: This function is used when constructing a value_type
955 //! is expensive and the value_type can be compared with a cheaper
956 //! key type. Usually this key is part of the value_type.
957 template<class KeyType
, class KeyValueCompare
>
958 std::pair
<const_iterator
, const_iterator
>
959 equal_range(const KeyType
& key
, KeyValueCompare comp
) const
960 { return tree_
.equal_range(key
, comp
); }
962 //! <b>Requires</b>: value must be an lvalue and shall be in a treap_set of
963 //! appropriate type. Otherwise the behavior is undefined.
965 //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_set
966 //! that points to the value
968 //! <b>Complexity</b>: Constant.
970 //! <b>Throws</b>: Nothing.
972 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
974 static iterator
s_iterator_to(reference value
)
975 { return tree_type::s_iterator_to(value
); }
977 //! <b>Requires</b>: value must be an lvalue and shall be in a treap_set of
978 //! appropriate type. Otherwise the behavior is undefined.
980 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
981 //! treap_set that points to the value
983 //! <b>Complexity</b>: Constant.
985 //! <b>Throws</b>: Nothing.
987 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
989 static const_iterator
s_iterator_to(const_reference value
)
990 { return tree_type::s_iterator_to(value
); }
992 //! <b>Requires</b>: value must be an lvalue and shall be in a treap_set of
993 //! appropriate type. Otherwise the behavior is undefined.
995 //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_set
996 //! that points to the value
998 //! <b>Complexity</b>: Constant.
1000 //! <b>Throws</b>: Nothing.
1001 iterator
iterator_to(reference value
)
1002 { return tree_
.iterator_to(value
); }
1004 //! <b>Requires</b>: value must be an lvalue and shall be in a treap_set of
1005 //! appropriate type. Otherwise the behavior is undefined.
1007 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1008 //! treap_set that points to the value
1010 //! <b>Complexity</b>: Constant.
1012 //! <b>Throws</b>: Nothing.
1013 const_iterator
iterator_to(const_reference value
) const
1014 { return tree_
.iterator_to(value
); }
1016 //! <b>Requires</b>: value shall not be in a treap_set/treap_multiset.
1018 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
1021 //! <b>Throws</b>: Nothing.
1023 //! <b>Complexity</b>: Constant time.
1025 //! <b>Note</b>: This function puts the hook in the well-known default state
1026 //! used by auto_unlink and safe hooks.
1027 static void init_node(reference value
)
1028 { tree_type::init_node(value
); }
1030 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
1032 //! <b>Complexity</b>: Average complexity is constant time.
1034 //! <b>Throws</b>: Nothing.
1036 //! <b>Notes</b>: This function breaks the tree and the tree can
1037 //! only be used for more unlink_leftmost_without_rebalance calls.
1038 //! This function is normally used to achieve a step by step
1039 //! controlled destruction of the tree.
1040 pointer
unlink_leftmost_without_rebalance()
1041 { return tree_
.unlink_leftmost_without_rebalance(); }
1043 //! <b>Requires</b>: replace_this must be a valid iterator of *this
1044 //! and with_this must not be inserted in any tree.
1046 //! <b>Effects</b>: Replaces replace_this in its position in the
1047 //! tree with with_this. The tree does not need to be rebalanced.
1049 //! <b>Complexity</b>: Constant.
1051 //! <b>Throws</b>: Nothing.
1053 //! <b>Note</b>: This function will break container ordering invariants if
1054 //! with_this is not equivalent to *replace_this according to the
1055 //! ordering rules. This function is faster than erasing and inserting
1056 //! the node, since no rebalancing or comparison is needed.
1057 void replace_node(iterator replace_this
, reference with_this
)
1058 { tree_
.replace_node(replace_this
, with_this
); }
1060 //! <b>Effects</b>: Rebalances the tree.
1062 //! <b>Throws</b>: Nothing.
1064 //! <b>Complexity</b>: Linear.
1066 { tree_
.rebalance(); }
1068 //! <b>Requires</b>: old_root is a node of a tree.
1070 //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
1072 //! <b>Returns</b>: The new root of the subtree.
1074 //! <b>Throws</b>: Nothing.
1076 //! <b>Complexity</b>: Linear to the elements in the subtree.
1077 iterator
rebalance_subtree(iterator root
)
1078 { return tree_
.rebalance_subtree(root
); }
1080 //! <b>Returns</b>: The balance factor (alpha) used in this tree
1082 //! <b>Throws</b>: Nothing.
1084 //! <b>Complexity</b>: Constant.
1085 float balance_factor() const
1086 { return tree_
.balance_factor(); }
1088 //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
1090 //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
1091 //! the tree if the new balance factor is stricter (less) than the old factor.
1093 //! <b>Throws</b>: Nothing.
1095 //! <b>Complexity</b>: Linear to the elements in the subtree.
1096 void balance_factor(float new_alpha
)
1097 { tree_
.balance_factor(new_alpha
); }
1100 friend bool operator==(const treap_set_impl
&x
, const treap_set_impl
&y
)
1101 { return x
.tree_
== y
.tree_
; }
1103 friend bool operator<(const treap_set_impl
&x
, const treap_set_impl
&y
)
1104 { return x
.tree_
< y
.tree_
; }
1108 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1109 template<class T
, class ...Options
>
1111 template<class Config
>
1113 inline bool operator!=
1114 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1115 (const treap_set_impl
<T
, Options
...> &x
, const treap_set_impl
<T
, Options
...> &y
)
1117 (const treap_set_impl
<Config
> &x
, const treap_set_impl
<Config
> &y
)
1119 { return !(x
== y
); }
1121 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1122 template<class T
, class ...Options
>
1124 template<class Config
>
1126 inline bool operator>
1127 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1128 (const treap_set_impl
<T
, Options
...> &x
, const treap_set_impl
<T
, Options
...> &y
)
1130 (const treap_set_impl
<Config
> &x
, const treap_set_impl
<Config
> &y
)
1134 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1135 template<class T
, class ...Options
>
1137 template<class Config
>
1139 inline bool operator<=
1140 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1141 (const treap_set_impl
<T
, Options
...> &x
, const treap_set_impl
<T
, Options
...> &y
)
1143 (const treap_set_impl
<Config
> &x
, const treap_set_impl
<Config
> &y
)
1145 { return !(y
< x
); }
1147 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1148 template<class T
, class ...Options
>
1150 template<class Config
>
1152 inline bool operator>=
1153 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1154 (const treap_set_impl
<T
, Options
...> &x
, const treap_set_impl
<T
, Options
...> &y
)
1156 (const treap_set_impl
<Config
> &x
, const treap_set_impl
<Config
> &y
)
1158 { return !(x
< y
); }
1160 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1161 template<class T
, class ...Options
>
1163 template<class Config
>
1166 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1167 (treap_set_impl
<T
, Options
...> &x
, treap_set_impl
<T
, Options
...> &y
)
1169 (treap_set_impl
<Config
> &x
, treap_set_impl
<Config
> &y
)
1173 //! Helper metafunction to define a \c treap_set that yields to the same type when the
1174 //! same options (either explicitly or implicitly) are used.
1175 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1176 template<class T
, class ...Options
>
1178 template<class T
, class O1
= none
, class O2
= none
1179 , class O3
= none
, class O4
= none
>
1181 struct make_treap_set
1184 typedef treap_set_impl
1185 < typename make_treap_opt
<T
,
1186 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1192 > implementation_defined
;
1194 typedef implementation_defined type
;
1197 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1199 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1200 template<class T
, class O1
, class O2
, class O3
, class O4
>
1202 template<class T
, class ...Options
>
1205 : public make_treap_set
<T
,
1206 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1213 typedef typename make_treap_set
1215 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1223 typedef typename
Base::value_compare value_compare
;
1224 typedef typename
Base::priority_compare priority_compare
;
1225 typedef typename
Base::value_traits value_traits
;
1226 typedef typename
Base::iterator iterator
;
1227 typedef typename
Base::const_iterator const_iterator
;
1229 //Assert if passed value traits are compatible with the type
1230 BOOST_STATIC_ASSERT((detail::is_same
<typename
value_traits::value_type
, T
>::value
));
1232 treap_set( const value_compare
&cmp
= value_compare()
1233 , const priority_compare
&pcmp
= priority_compare()
1234 , const value_traits
&v_traits
= value_traits())
1235 : Base(cmp
, pcmp
, v_traits
)
1238 template<class Iterator
>
1239 treap_set( Iterator b
, Iterator e
1240 , const value_compare
&cmp
= value_compare()
1241 , const priority_compare
&pcmp
= priority_compare()
1242 , const value_traits
&v_traits
= value_traits())
1243 : Base(b
, e
, cmp
, pcmp
, v_traits
)
1246 static treap_set
&container_from_end_iterator(iterator end_iterator
)
1247 { return static_cast<treap_set
&>(Base::container_from_end_iterator(end_iterator
)); }
1249 static const treap_set
&container_from_end_iterator(const_iterator end_iterator
)
1250 { return static_cast<const treap_set
&>(Base::container_from_end_iterator(end_iterator
)); }
1252 static treap_set
&container_from_iterator(iterator it
)
1253 { return static_cast<treap_set
&>(Base::container_from_iterator(it
)); }
1255 static const treap_set
&container_from_iterator(const_iterator it
)
1256 { return static_cast<const treap_set
&>(Base::container_from_iterator(it
)); }
1261 //! The class template treap_multiset is an intrusive container, that mimics most of
1262 //! the interface of std::treap_multiset as described in the C++ standard.
1264 //! The template parameter \c T is the type to be managed by the container.
1265 //! The user can specify additional options and if no options are provided
1266 //! default options are used.
1268 //! The container supports the following options:
1269 //! \c base_hook<>/member_hook<>/value_traits<>,
1270 //! \c constant_time_size<>, \c size_type<>,
1271 //! \c compare<> and \c priority_compare<>
1272 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1273 template<class T
, class ...Options
>
1275 template<class Config
>
1277 class treap_multiset_impl
1280 typedef treap_impl
<Config
> tree_type
;
1282 //Non-copyable and non-assignable
1283 treap_multiset_impl (const treap_multiset_impl
&);
1284 treap_multiset_impl
&operator =(const treap_multiset_impl
&);
1285 typedef tree_type implementation_defined
;
1289 typedef typename
implementation_defined::value_type value_type
;
1290 typedef typename
implementation_defined::value_traits value_traits
;
1291 typedef typename
implementation_defined::pointer pointer
;
1292 typedef typename
implementation_defined::const_pointer const_pointer
;
1293 typedef typename
implementation_defined::reference reference
;
1294 typedef typename
implementation_defined::const_reference const_reference
;
1295 typedef typename
implementation_defined::difference_type difference_type
;
1296 typedef typename
implementation_defined::size_type size_type
;
1297 typedef typename
implementation_defined::value_compare value_compare
;
1298 typedef typename
implementation_defined::priority_compare priority_compare
;
1299 typedef typename
implementation_defined::key_compare key_compare
;
1300 typedef typename
implementation_defined::iterator iterator
;
1301 typedef typename
implementation_defined::const_iterator const_iterator
;
1302 typedef typename
implementation_defined::reverse_iterator reverse_iterator
;
1303 typedef typename
implementation_defined::const_reverse_iterator const_reverse_iterator
;
1304 typedef typename
implementation_defined::insert_commit_data insert_commit_data
;
1305 typedef typename
implementation_defined::node_traits node_traits
;
1306 typedef typename
implementation_defined::node node
;
1307 typedef typename
implementation_defined::node_ptr node_ptr
;
1308 typedef typename
implementation_defined::const_node_ptr const_node_ptr
;
1309 typedef typename
implementation_defined::node_algorithms node_algorithms
;
1317 //! <b>Effects</b>: Constructs an empty treap_multiset.
1319 //! <b>Complexity</b>: Constant.
1321 //! <b>Throws</b>: If value_traits::node_traits::node
1322 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1323 //! or the copy constructor of the value_compare/priority_compare objects throw.
1324 treap_multiset_impl( const value_compare
&cmp
= value_compare()
1325 , const priority_compare
&pcmp
= priority_compare()
1326 , const value_traits
&v_traits
= value_traits())
1327 : tree_(cmp
, pcmp
, v_traits
)
1330 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
1331 //! cmp must be a comparison function that induces a strict weak ordering.
1333 //! <b>Effects</b>: Constructs an empty treap_multiset and inserts elements from
1336 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
1337 //! comp and otherwise N * log N, where N is the distance between first and last
1339 //! <b>Throws</b>: If value_traits::node_traits::node
1340 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1341 //! or the copy constructor/operator() of the value_compare/priority_compare objects throw.
1342 template<class Iterator
>
1343 treap_multiset_impl( Iterator b
, Iterator e
1344 , const value_compare
&cmp
= value_compare()
1345 , const priority_compare
&pcmp
= priority_compare()
1346 , const value_traits
&v_traits
= value_traits())
1347 : tree_(false, b
, e
, cmp
, pcmp
, v_traits
)
1350 //! <b>Effects</b>: Detaches all elements from this. The objects in the treap_multiset
1351 //! are not deleted (i.e. no destructors are called).
1353 //! <b>Complexity</b>: Linear to the number of elements on the container.
1354 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1356 //! <b>Throws</b>: Nothing.
1357 ~treap_multiset_impl()
1360 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the treap_multiset.
1362 //! <b>Complexity</b>: Constant.
1364 //! <b>Throws</b>: Nothing.
1366 { return tree_
.begin(); }
1368 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_multiset.
1370 //! <b>Complexity</b>: Constant.
1372 //! <b>Throws</b>: Nothing.
1373 const_iterator
begin() const
1374 { return tree_
.begin(); }
1376 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_multiset.
1378 //! <b>Complexity</b>: Constant.
1380 //! <b>Throws</b>: Nothing.
1381 const_iterator
cbegin() const
1382 { return tree_
.cbegin(); }
1384 //! <b>Effects</b>: Returns an iterator pointing to the end of the treap_multiset.
1386 //! <b>Complexity</b>: Constant.
1388 //! <b>Throws</b>: Nothing.
1390 { return tree_
.end(); }
1392 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_multiset.
1394 //! <b>Complexity</b>: Constant.
1396 //! <b>Throws</b>: Nothing.
1397 const_iterator
end() const
1398 { return tree_
.end(); }
1400 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_multiset.
1402 //! <b>Complexity</b>: Constant.
1404 //! <b>Throws</b>: Nothing.
1405 const_iterator
cend() const
1406 { return tree_
.cend(); }
1408 //! <b>Effects</b>: Returns an iterator pointing to the highest priority object of the tree.
1410 //! <b>Complexity</b>: Constant.
1412 //! <b>Throws</b>: Nothing.
1414 { return tree_
.top(); }
1416 //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree..
1418 //! <b>Complexity</b>: Constant.
1420 //! <b>Throws</b>: Nothing.
1421 const_iterator
top() const
1422 { return this->ctop(); }
1424 //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree..
1426 //! <b>Complexity</b>: Constant.
1428 //! <b>Throws</b>: Nothing.
1429 const_iterator
ctop() const
1430 { return tree_
.ctop(); }
1432 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
1433 //! reversed treap_multiset.
1435 //! <b>Complexity</b>: Constant.
1437 //! <b>Throws</b>: Nothing.
1438 reverse_iterator
rbegin()
1439 { return tree_
.rbegin(); }
1441 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1442 //! of the reversed treap_multiset.
1444 //! <b>Complexity</b>: Constant.
1446 //! <b>Throws</b>: Nothing.
1447 const_reverse_iterator
rbegin() const
1448 { return tree_
.rbegin(); }
1450 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1451 //! of the reversed treap_multiset.
1453 //! <b>Complexity</b>: Constant.
1455 //! <b>Throws</b>: Nothing.
1456 const_reverse_iterator
crbegin() const
1457 { return tree_
.crbegin(); }
1459 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
1460 //! of the reversed treap_multiset.
1462 //! <b>Complexity</b>: Constant.
1464 //! <b>Throws</b>: Nothing.
1465 reverse_iterator
rend()
1466 { return tree_
.rend(); }
1468 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1469 //! of the reversed treap_multiset.
1471 //! <b>Complexity</b>: Constant.
1473 //! <b>Throws</b>: Nothing.
1474 const_reverse_iterator
rend() const
1475 { return tree_
.rend(); }
1477 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1478 //! of the reversed treap_multiset.
1480 //! <b>Complexity</b>: Constant.
1482 //! <b>Throws</b>: Nothing.
1483 const_reverse_iterator
crend() const
1484 { return tree_
.crend(); }
1486 //! <b>Effects</b>: Returns a reverse_iterator pointing to the highest priority object of the
1489 //! <b>Complexity</b>: Constant.
1491 //! <b>Throws</b>: Nothing.
1492 reverse_iterator
rtop()
1493 { return tree_
.rtop(); }
1495 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority objec
1496 //! of the reversed tree.
1498 //! <b>Complexity</b>: Constant.
1500 //! <b>Throws</b>: Nothing.
1501 const_reverse_iterator
rtop() const
1502 { return tree_
.crtop(); }
1504 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority object
1505 //! of the reversed tree.
1507 //! <b>Complexity</b>: Constant.
1509 //! <b>Throws</b>: Nothing.
1510 const_reverse_iterator
crtop() const
1511 { return tree_
.crtop(); }
1513 //! <b>Precondition</b>: end_iterator must be a valid end iterator
1514 //! of treap_multiset.
1516 //! <b>Effects</b>: Returns a const reference to the treap_multiset associated to the end iterator
1518 //! <b>Throws</b>: Nothing.
1520 //! <b>Complexity</b>: Constant.
1521 static treap_multiset_impl
&container_from_end_iterator(iterator end_iterator
)
1523 return *detail::parent_from_member
<treap_multiset_impl
, tree_type
>
1524 ( &tree_type::container_from_end_iterator(end_iterator
)
1525 , &treap_multiset_impl::tree_
);
1528 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
1529 //! of treap_multiset.
1531 //! <b>Effects</b>: Returns a const reference to the treap_multiset associated to the end iterator
1533 //! <b>Throws</b>: Nothing.
1535 //! <b>Complexity</b>: Constant.
1536 static const treap_multiset_impl
&container_from_end_iterator(const_iterator end_iterator
)
1538 return *detail::parent_from_member
<treap_multiset_impl
, tree_type
>
1539 ( &tree_type::container_from_end_iterator(end_iterator
)
1540 , &treap_multiset_impl::tree_
);
1543 //! <b>Precondition</b>: it must be a valid iterator of multiset.
1545 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1547 //! <b>Throws</b>: Nothing.
1549 //! <b>Complexity</b>: Constant.
1550 static treap_multiset_impl
&container_from_iterator(iterator it
)
1552 return *detail::parent_from_member
<treap_multiset_impl
, tree_type
>
1553 ( &tree_type::container_from_iterator(it
)
1554 , &treap_multiset_impl::tree_
);
1557 //! <b>Precondition</b>: it must be a valid const_iterator of multiset.
1559 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1561 //! <b>Throws</b>: Nothing.
1563 //! <b>Complexity</b>: Constant.
1564 static const treap_multiset_impl
&container_from_iterator(const_iterator it
)
1566 return *detail::parent_from_member
<treap_multiset_impl
, tree_type
>
1567 ( &tree_type::container_from_iterator(it
)
1568 , &treap_multiset_impl::tree_
);
1571 //! <b>Effects</b>: Returns the key_compare object used by the treap_multiset.
1573 //! <b>Complexity</b>: Constant.
1575 //! <b>Throws</b>: If key_compare copy-constructor throws.
1576 key_compare
key_comp() const
1577 { return tree_
.value_comp(); }
1579 //! <b>Effects</b>: Returns the value_compare object used by the treap_multiset.
1581 //! <b>Complexity</b>: Constant.
1583 //! <b>Throws</b>: If value_compare copy-constructor throws.
1584 value_compare
value_comp() const
1585 { return tree_
.value_comp(); }
1587 //! <b>Effects</b>: Returns true if the container is empty.
1589 //! <b>Complexity</b>: Constant.
1591 //! <b>Throws</b>: Nothing.
1593 { return tree_
.empty(); }
1595 //! <b>Effects</b>: Returns the number of elements stored in the treap_multiset.
1597 //! <b>Complexity</b>: Linear to elements contained in *this if,
1598 //! constant-time size option is enabled. Constant-time otherwise.
1600 //! <b>Throws</b>: Nothing.
1601 size_type
size() const
1602 { return tree_
.size(); }
1604 //! <b>Effects</b>: Swaps the contents of two treap_multisets.
1606 //! <b>Complexity</b>: Constant.
1608 //! <b>Throws</b>: If the swap() call for the comparison functor
1609 //! found using ADL throws. Strong guarantee.
1610 void swap(treap_multiset_impl
& other
)
1611 { tree_
.swap(other
.tree_
); }
1613 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1614 //! Cloner should yield to nodes equivalent to the original nodes.
1616 //! <b>Effects</b>: Erases all the elements from *this
1617 //! calling Disposer::operator()(pointer), clones all the
1618 //! elements from src calling Cloner::operator()(const_reference )
1619 //! and inserts them on *this. Copies the predicate from the source container.
1621 //! If cloner throws, all cloned elements are unlinked and disposed
1622 //! calling Disposer::operator()(pointer).
1624 //! <b>Complexity</b>: Linear to erased plus inserted elements.
1626 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
1627 template <class Cloner
, class Disposer
>
1628 void clone_from(const treap_multiset_impl
&src
, Cloner cloner
, Disposer disposer
)
1629 { tree_
.clone_from(src
.tree_
, cloner
, disposer
); }
1631 //! <b>Requires</b>: value must be an lvalue
1633 //! <b>Effects</b>: Inserts value into the treap_multiset.
1635 //! <b>Returns</b>: An iterator that points to the position where the new
1636 //! element was inserted.
1638 //! <b>Complexity</b>: Average complexity for insert element is at
1639 //! most logarithmic.
1641 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1643 //! <b>Note</b>: Does not affect the validity of iterators and references.
1644 //! No copy-constructors are called.
1645 iterator
insert(reference value
)
1646 { return tree_
.insert_equal(value
); }
1648 //! <b>Requires</b>: value must be an lvalue
1650 //! <b>Effects</b>: Inserts x into the treap_multiset, using pos as a hint to
1651 //! where it will be inserted.
1653 //! <b>Returns</b>: An iterator that points to the position where the new
1654 //! element was inserted.
1656 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
1657 //! constant time if t is inserted immediately before hint.
1659 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1661 //! <b>Note</b>: Does not affect the validity of iterators and references.
1662 //! No copy-constructors are called.
1663 iterator
insert(const_iterator hint
, reference value
)
1664 { return tree_
.insert_equal(hint
, value
); }
1666 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
1667 //! of type value_type.
1669 //! <b>Effects</b>: Inserts a range into the treap_multiset.
1671 //! <b>Returns</b>: An iterator that points to the position where the new
1672 //! element was inserted.
1674 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
1675 //! size of the range. However, it is linear in N if the range is already sorted
1676 //! by value_comp().
1678 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1680 //! <b>Note</b>: Does not affect the validity of iterators and references.
1681 //! No copy-constructors are called.
1682 template<class Iterator
>
1683 void insert(Iterator b
, Iterator e
)
1684 { tree_
.insert_equal(b
, e
); }
1686 //! <b>Effects</b>: Erases the element pointed to by pos.
1688 //! <b>Complexity</b>: Average complexity is constant time.
1690 //! <b>Returns</b>: An iterator to the element after the erased element.
1692 //! <b>Throws</b>: Nothing.
1694 //! <b>Note</b>: Invalidates the iterators (but not the references)
1695 //! to the erased elements. No destructors are called.
1696 iterator
erase(const_iterator i
)
1697 { return tree_
.erase(i
); }
1699 //! <b>Effects</b>: Erases the range pointed to by b end e.
1701 //! <b>Returns</b>: An iterator to the element after the erased elements.
1703 //! <b>Complexity</b>: Average complexity for erase range is at most
1704 //! O(log(size() + N)), where N is the number of elements in the range.
1706 //! <b>Throws</b>: Nothing.
1708 //! <b>Note</b>: Invalidates the iterators (but not the references)
1709 //! to the erased elements. No destructors are called.
1710 iterator
erase(const_iterator b
, const_iterator e
)
1711 { return tree_
.erase(b
, e
); }
1713 //! <b>Effects</b>: Erases all the elements with the given value.
1715 //! <b>Returns</b>: The number of erased elements.
1717 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1719 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1721 //! <b>Note</b>: Invalidates the iterators (but not the references)
1722 //! to the erased elements. No destructors are called.
1723 size_type
erase(const_reference value
)
1724 { return tree_
.erase(value
); }
1726 //! <b>Effects</b>: Erases all the elements that compare equal with
1727 //! the given key and the given comparison functor.
1729 //! <b>Returns</b>: The number of erased elements.
1731 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1733 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1735 //! <b>Note</b>: Invalidates the iterators (but not the references)
1736 //! to the erased elements. No destructors are called.
1737 template<class KeyType
, class KeyValueCompare
>
1738 size_type
erase(const KeyType
& key
, KeyValueCompare comp
1740 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
1743 { return tree_
.erase(key
, comp
); }
1745 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1747 //! <b>Returns</b>: An iterator to the element after the erased element.
1749 //! <b>Effects</b>: Erases the element pointed to by pos.
1750 //! Disposer::operator()(pointer) is called for the removed element.
1752 //! <b>Complexity</b>: Average complexity for erase element is constant time.
1754 //! <b>Throws</b>: Nothing.
1756 //! <b>Note</b>: Invalidates the iterators
1757 //! to the erased elements.
1758 template<class Disposer
>
1759 iterator
erase_and_dispose(const_iterator i
, Disposer disposer
)
1760 { return tree_
.erase_and_dispose(i
, disposer
); }
1762 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1763 template<class Disposer
>
1764 iterator
erase_and_dispose(iterator i
, Disposer disposer
)
1765 { return this->erase_and_dispose(const_iterator(i
), disposer
); }
1768 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1770 //! <b>Returns</b>: An iterator to the element after the erased elements.
1772 //! <b>Effects</b>: Erases the range pointed to by b end e.
1773 //! Disposer::operator()(pointer) is called for the removed elements.
1775 //! <b>Complexity</b>: Average complexity for erase range is at most
1776 //! O(log(size() + N)), where N is the number of elements in the range.
1778 //! <b>Throws</b>: Nothing.
1780 //! <b>Note</b>: Invalidates the iterators
1781 //! to the erased elements.
1782 template<class Disposer
>
1783 iterator
erase_and_dispose(const_iterator b
, const_iterator e
, Disposer disposer
)
1784 { return tree_
.erase_and_dispose(b
, e
, disposer
); }
1786 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1788 //! <b>Effects</b>: Erases all the elements with the given value.
1789 //! Disposer::operator()(pointer) is called for the removed elements.
1791 //! <b>Returns</b>: The number of erased elements.
1793 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1795 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1797 //! <b>Note</b>: Invalidates the iterators (but not the references)
1798 //! to the erased elements. No destructors are called.
1799 template<class Disposer
>
1800 size_type
erase_and_dispose(const_reference value
, Disposer disposer
)
1801 { return tree_
.erase_and_dispose(value
, disposer
); }
1803 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1805 //! <b>Effects</b>: Erases all the elements with the given key.
1806 //! according to the comparison functor "comp".
1807 //! Disposer::operator()(pointer) is called for the removed elements.
1809 //! <b>Returns</b>: The number of erased elements.
1811 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1813 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1815 //! <b>Note</b>: Invalidates the iterators
1816 //! to the erased elements.
1817 template<class KeyType
, class KeyValueCompare
, class Disposer
>
1818 size_type
erase_and_dispose(const KeyType
& key
, KeyValueCompare comp
, Disposer disposer
1820 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
1823 { return tree_
.erase_and_dispose(key
, comp
, disposer
); }
1825 //! <b>Effects</b>: Erases all the elements of the container.
1827 //! <b>Complexity</b>: Linear to the number of elements on the container.
1828 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1830 //! <b>Throws</b>: Nothing.
1832 //! <b>Note</b>: Invalidates the iterators (but not the references)
1833 //! to the erased elements. No destructors are called.
1835 { return tree_
.clear(); }
1837 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1839 //! <b>Effects</b>: Erases all the elements of the container.
1841 //! <b>Complexity</b>: Linear to the number of elements on the container.
1842 //! Disposer::operator()(pointer) is called for the removed elements.
1844 //! <b>Throws</b>: Nothing.
1846 //! <b>Note</b>: Invalidates the iterators (but not the references)
1847 //! to the erased elements. No destructors are called.
1848 template<class Disposer
>
1849 void clear_and_dispose(Disposer disposer
)
1850 { return tree_
.clear_and_dispose(disposer
); }
1852 //! <b>Effects</b>: Returns the number of contained elements with the given key
1854 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1855 //! to number of objects with the given key.
1857 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1858 size_type
count(const_reference value
) const
1859 { return tree_
.count(value
); }
1861 //! <b>Effects</b>: Returns the number of contained elements with the same key
1862 //! compared with the given comparison functor.
1864 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1865 //! to number of objects with the given key.
1867 //! <b>Throws</b>: If comp ordering function throws.
1868 template<class KeyType
, class KeyValueCompare
>
1869 size_type
count(const KeyType
& key
, KeyValueCompare comp
) const
1870 { return tree_
.count(key
, comp
); }
1872 //! <b>Effects</b>: Returns an iterator to the first element whose
1873 //! key is not less than k or end() if that element does not exist.
1875 //! <b>Complexity</b>: Logarithmic.
1877 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1878 iterator
lower_bound(const_reference value
)
1879 { return tree_
.lower_bound(value
); }
1881 //! <b>Requires</b>: comp must imply the same element order as
1882 //! value_compare. Usually key is the part of the value_type
1883 //! that is used in the ordering functor.
1885 //! <b>Effects</b>: Returns an iterator to the first element whose
1886 //! key according to the comparison functor is not less than k or
1887 //! end() if that element does not exist.
1889 //! <b>Complexity</b>: Logarithmic.
1891 //! <b>Throws</b>: If comp ordering function throws.
1893 //! <b>Note</b>: This function is used when constructing a value_type
1894 //! is expensive and the value_type can be compared with a cheaper
1895 //! key type. Usually this key is part of the value_type.
1896 template<class KeyType
, class KeyValueCompare
>
1897 iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
)
1898 { return tree_
.lower_bound(key
, comp
); }
1900 //! <b>Effects</b>: Returns a const iterator to the first element whose
1901 //! key is not less than k or end() if that element does not exist.
1903 //! <b>Complexity</b>: Logarithmic.
1905 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1906 const_iterator
lower_bound(const_reference value
) const
1907 { return tree_
.lower_bound(value
); }
1909 //! <b>Requires</b>: comp must imply the same element order as
1910 //! value_compare. Usually key is the part of the value_type
1911 //! that is used in the ordering functor.
1913 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1914 //! key according to the comparison functor is not less than k or
1915 //! end() if that element does not exist.
1917 //! <b>Complexity</b>: Logarithmic.
1919 //! <b>Throws</b>: If comp ordering function throws.
1921 //! <b>Note</b>: This function is used when constructing a value_type
1922 //! is expensive and the value_type can be compared with a cheaper
1923 //! key type. Usually this key is part of the value_type.
1924 template<class KeyType
, class KeyValueCompare
>
1925 const_iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
) const
1926 { return tree_
.lower_bound(key
, comp
); }
1928 //! <b>Effects</b>: Returns an iterator to the first element whose
1929 //! key is greater than k or end() if that element does not exist.
1931 //! <b>Complexity</b>: Logarithmic.
1933 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1934 iterator
upper_bound(const_reference value
)
1935 { return tree_
.upper_bound(value
); }
1937 //! <b>Requires</b>: comp must imply the same element order as
1938 //! value_compare. Usually key is the part of the value_type
1939 //! that is used in the ordering functor.
1941 //! <b>Effects</b>: Returns an iterator to the first element whose
1942 //! key according to the comparison functor is greater than key or
1943 //! end() if that element does not exist.
1945 //! <b>Complexity</b>: Logarithmic.
1947 //! <b>Throws</b>: If comp ordering function throws.
1949 //! <b>Note</b>: This function is used when constructing a value_type
1950 //! is expensive and the value_type can be compared with a cheaper
1951 //! key type. Usually this key is part of the value_type.
1952 template<class KeyType
, class KeyValueCompare
>
1953 iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
)
1954 { return tree_
.upper_bound(key
, comp
); }
1956 //! <b>Effects</b>: Returns an iterator to the first element whose
1957 //! key is greater than k or end() if that element does not exist.
1959 //! <b>Complexity</b>: Logarithmic.
1961 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1962 const_iterator
upper_bound(const_reference value
) const
1963 { return tree_
.upper_bound(value
); }
1965 //! <b>Requires</b>: comp must imply the same element order as
1966 //! value_compare. Usually key is the part of the value_type
1967 //! that is used in the ordering functor.
1969 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1970 //! key according to the comparison functor is greater than key or
1971 //! end() if that element does not exist.
1973 //! <b>Complexity</b>: Logarithmic.
1975 //! <b>Throws</b>: If comp ordering function throws.
1977 //! <b>Note</b>: This function is used when constructing a value_type
1978 //! is expensive and the value_type can be compared with a cheaper
1979 //! key type. Usually this key is part of the value_type.
1980 template<class KeyType
, class KeyValueCompare
>
1981 const_iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
) const
1982 { return tree_
.upper_bound(key
, comp
); }
1984 //! <b>Effects</b>: Finds an iterator to the first element whose value is
1985 //! "value" or end() if that element does not exist.
1987 //! <b>Complexity</b>: Logarithmic.
1989 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1990 iterator
find(const_reference value
)
1991 { return tree_
.find(value
); }
1993 //! <b>Requires</b>: comp must imply the same element order as
1994 //! value_compare. Usually key is the part of the value_type
1995 //! that is used in the ordering functor.
1997 //! <b>Effects</b>: Finds an iterator to the first element whose key is
1998 //! "key" according to the comparison functor or end() if that element
2001 //! <b>Complexity</b>: Logarithmic.
2003 //! <b>Throws</b>: If comp ordering function throws.
2005 //! <b>Note</b>: This function is used when constructing a value_type
2006 //! is expensive and the value_type can be compared with a cheaper
2007 //! key type. Usually this key is part of the value_type.
2008 template<class KeyType
, class KeyValueCompare
>
2009 iterator
find(const KeyType
& key
, KeyValueCompare comp
)
2010 { return tree_
.find(key
, comp
); }
2012 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
2013 //! "value" or end() if that element does not exist.
2015 //! <b>Complexity</b>: Logarithmic.
2017 //! <b>Throws</b>: If the internal value_compare ordering function throws.
2018 const_iterator
find(const_reference value
) const
2019 { return tree_
.find(value
); }
2021 //! <b>Requires</b>: comp must imply the same element order as
2022 //! value_compare. Usually key is the part of the value_type
2023 //! that is used in the ordering functor.
2025 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
2026 //! "key" according to the comparison functor or end() if that element
2029 //! <b>Complexity</b>: Logarithmic.
2031 //! <b>Throws</b>: If comp ordering function throws.
2033 //! <b>Note</b>: This function is used when constructing a value_type
2034 //! is expensive and the value_type can be compared with a cheaper
2035 //! key type. Usually this key is part of the value_type.
2036 template<class KeyType
, class KeyValueCompare
>
2037 const_iterator
find(const KeyType
& key
, KeyValueCompare comp
) const
2038 { return tree_
.find(key
, comp
); }
2040 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
2041 //! an empty range that indicates the position where those elements would be
2042 //! if they there is no elements with key k.
2044 //! <b>Complexity</b>: Logarithmic.
2046 //! <b>Throws</b>: If the internal value_compare ordering function throws.
2047 std::pair
<iterator
,iterator
> equal_range(const_reference value
)
2048 { return tree_
.equal_range(value
); }
2050 //! <b>Requires</b>: comp must imply the same element order as
2051 //! value_compare. Usually key is the part of the value_type
2052 //! that is used in the ordering functor.
2054 //! <b>Effects</b>: Finds a range containing all elements whose key is k
2055 //! according to the comparison functor or an empty range
2056 //! that indicates the position where those elements would be
2057 //! if they there is no elements with key k.
2059 //! <b>Complexity</b>: Logarithmic.
2061 //! <b>Throws</b>: If comp ordering function throws.
2063 //! <b>Note</b>: This function is used when constructing a value_type
2064 //! is expensive and the value_type can be compared with a cheaper
2065 //! key type. Usually this key is part of the value_type.
2066 template<class KeyType
, class KeyValueCompare
>
2067 std::pair
<iterator
,iterator
> equal_range(const KeyType
& key
, KeyValueCompare comp
)
2068 { return tree_
.equal_range(key
, comp
); }
2070 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
2071 //! an empty range that indicates the position where those elements would be
2072 //! if they there is no elements with key k.
2074 //! <b>Complexity</b>: Logarithmic.
2076 //! <b>Throws</b>: If the internal value_compare ordering function throws.
2077 std::pair
<const_iterator
, const_iterator
>
2078 equal_range(const_reference value
) const
2079 { return tree_
.equal_range(value
); }
2081 //! <b>Requires</b>: comp must imply the same element order as
2082 //! value_compare. Usually key is the part of the value_type
2083 //! that is used in the ordering functor.
2085 //! <b>Effects</b>: Finds a range containing all elements whose key is k
2086 //! according to the comparison functor or an empty range
2087 //! that indicates the position where those elements would be
2088 //! if they there is no elements with key k.
2090 //! <b>Complexity</b>: Logarithmic.
2092 //! <b>Throws</b>: If comp ordering function throws.
2094 //! <b>Note</b>: This function is used when constructing a value_type
2095 //! is expensive and the value_type can be compared with a cheaper
2096 //! key type. Usually this key is part of the value_type.
2097 template<class KeyType
, class KeyValueCompare
>
2098 std::pair
<const_iterator
, const_iterator
>
2099 equal_range(const KeyType
& key
, KeyValueCompare comp
) const
2100 { return tree_
.equal_range(key
, comp
); }
2102 //! <b>Requires</b>: value must be an lvalue and shall be in a treap_multiset of
2103 //! appropriate type. Otherwise the behavior is undefined.
2105 //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_multiset
2106 //! that points to the value
2108 //! <b>Complexity</b>: Constant.
2110 //! <b>Throws</b>: Nothing.
2112 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2114 static iterator
s_iterator_to(reference value
)
2115 { return tree_type::s_iterator_to(value
); }
2117 //! <b>Requires</b>: value must be an lvalue and shall be in a treap_multiset of
2118 //! appropriate type. Otherwise the behavior is undefined.
2120 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2121 //! treap_multiset that points to the value
2123 //! <b>Complexity</b>: Constant.
2125 //! <b>Throws</b>: Nothing.
2127 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2129 static const_iterator
s_iterator_to(const_reference value
)
2130 { return tree_type::s_iterator_to(value
); }
2132 //! <b>Requires</b>: value must be an lvalue and shall be in a treap_multiset of
2133 //! appropriate type. Otherwise the behavior is undefined.
2135 //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_multiset
2136 //! that points to the value
2138 //! <b>Complexity</b>: Constant.
2140 //! <b>Throws</b>: Nothing.
2141 iterator
iterator_to(reference value
)
2142 { return tree_
.iterator_to(value
); }
2144 //! <b>Requires</b>: value must be an lvalue and shall be in a treap_multiset of
2145 //! appropriate type. Otherwise the behavior is undefined.
2147 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2148 //! treap_multiset that points to the value
2150 //! <b>Complexity</b>: Constant.
2152 //! <b>Throws</b>: Nothing.
2153 const_iterator
iterator_to(const_reference value
) const
2154 { return tree_
.iterator_to(value
); }
2156 //! <b>Requires</b>: value shall not be in a treap_multiset/treap_multiset.
2158 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
2161 //! <b>Throws</b>: Nothing.
2163 //! <b>Complexity</b>: Constant time.
2165 //! <b>Note</b>: This function puts the hook in the well-known default state
2166 //! used by auto_unlink and safe hooks.
2167 static void init_node(reference value
)
2168 { tree_type::init_node(value
); }
2170 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
2172 //! <b>Complexity</b>: Average complexity is constant time.
2174 //! <b>Throws</b>: Nothing.
2176 //! <b>Notes</b>: This function breaks the tree and the tree can
2177 //! only be used for more unlink_leftmost_without_rebalance calls.
2178 //! This function is normally used to achieve a step by step
2179 //! controlled destruction of the tree.
2180 pointer
unlink_leftmost_without_rebalance()
2181 { return tree_
.unlink_leftmost_without_rebalance(); }
2183 //! <b>Requires</b>: replace_this must be a valid iterator of *this
2184 //! and with_this must not be inserted in any tree.
2186 //! <b>Effects</b>: Replaces replace_this in its position in the
2187 //! tree with with_this. The tree does not need to be rebalanced.
2189 //! <b>Complexity</b>: Constant.
2191 //! <b>Throws</b>: Nothing.
2193 //! <b>Note</b>: This function will break container ordering invariants if
2194 //! with_this is not equivalent to *replace_this according to the
2195 //! ordering rules. This function is faster than erasing and inserting
2196 //! the node, since no rebalancing or comparison is needed.
2197 void replace_node(iterator replace_this
, reference with_this
)
2198 { tree_
.replace_node(replace_this
, with_this
); }
2200 //! <b>Effects</b>: Rebalances the tree.
2202 //! <b>Throws</b>: Nothing.
2204 //! <b>Complexity</b>: Linear.
2206 { tree_
.rebalance(); }
2208 //! <b>Requires</b>: old_root is a node of a tree.
2210 //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
2212 //! <b>Returns</b>: The new root of the subtree.
2214 //! <b>Throws</b>: Nothing.
2216 //! <b>Complexity</b>: Linear to the elements in the subtree.
2217 iterator
rebalance_subtree(iterator root
)
2218 { return tree_
.rebalance_subtree(root
); }
2220 //! <b>Returns</b>: The balance factor (alpha) used in this tree
2222 //! <b>Throws</b>: Nothing.
2224 //! <b>Complexity</b>: Constant.
2225 float balance_factor() const
2226 { return tree_
.balance_factor(); }
2228 //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
2230 //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
2231 //! the tree if the new balance factor is stricter (less) than the old factor.
2233 //! <b>Throws</b>: Nothing.
2235 //! <b>Complexity</b>: Linear to the elements in the subtree.
2236 void balance_factor(float new_alpha
)
2237 { tree_
.balance_factor(new_alpha
); }
2240 friend bool operator==(const treap_multiset_impl
&x
, const treap_multiset_impl
&y
)
2241 { return x
.tree_
== y
.tree_
; }
2243 friend bool operator<(const treap_multiset_impl
&x
, const treap_multiset_impl
&y
)
2244 { return x
.tree_
< y
.tree_
; }
2248 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2249 template<class T
, class ...Options
>
2251 template<class Config
>
2253 inline bool operator!=
2254 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2255 (const treap_multiset_impl
<T
, Options
...> &x
, const treap_multiset_impl
<T
, Options
...> &y
)
2257 (const treap_multiset_impl
<Config
> &x
, const treap_multiset_impl
<Config
> &y
)
2259 { return !(x
== y
); }
2261 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2262 template<class T
, class ...Options
>
2264 template<class Config
>
2266 inline bool operator>
2267 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2268 (const treap_multiset_impl
<T
, Options
...> &x
, const treap_multiset_impl
<T
, Options
...> &y
)
2270 (const treap_multiset_impl
<Config
> &x
, const treap_multiset_impl
<Config
> &y
)
2274 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2275 template<class T
, class ...Options
>
2277 template<class Config
>
2279 inline bool operator<=
2280 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2281 (const treap_multiset_impl
<T
, Options
...> &x
, const treap_multiset_impl
<T
, Options
...> &y
)
2283 (const treap_multiset_impl
<Config
> &x
, const treap_multiset_impl
<Config
> &y
)
2285 { return !(y
< x
); }
2287 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2288 template<class T
, class ...Options
>
2290 template<class Config
>
2292 inline bool operator>=
2293 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2294 (const treap_multiset_impl
<T
, Options
...> &x
, const treap_multiset_impl
<T
, Options
...> &y
)
2296 (const treap_multiset_impl
<Config
> &x
, const treap_multiset_impl
<Config
> &y
)
2298 { return !(x
< y
); }
2300 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2301 template<class T
, class ...Options
>
2303 template<class Config
>
2306 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2307 (treap_multiset_impl
<T
, Options
...> &x
, treap_multiset_impl
<T
, Options
...> &y
)
2309 (treap_multiset_impl
<Config
> &x
, treap_multiset_impl
<Config
> &y
)
2313 //! Helper metafunction to define a \c treap_multiset that yields to the same type when the
2314 //! same options (either explicitly or implicitly) are used.
2315 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2316 template<class T
, class ...Options
>
2318 template<class T
, class O1
= none
, class O2
= none
2319 , class O3
= none
, class O4
= none
>
2321 struct make_treap_multiset
2324 typedef treap_multiset_impl
2325 < typename make_treap_opt
<T
,
2326 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2332 > implementation_defined
;
2334 typedef implementation_defined type
;
2337 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
2339 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2340 template<class T
, class O1
, class O2
, class O3
, class O4
>
2342 template<class T
, class ...Options
>
2344 class treap_multiset
2345 : public make_treap_multiset
<T
,
2346 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2353 typedef typename make_treap_multiset
2355 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2363 typedef typename
Base::value_compare value_compare
;
2364 typedef typename
Base::priority_compare priority_compare
;
2365 typedef typename
Base::value_traits value_traits
;
2366 typedef typename
Base::iterator iterator
;
2367 typedef typename
Base::const_iterator const_iterator
;
2369 //Assert if passed value traits are compatible with the type
2370 BOOST_STATIC_ASSERT((detail::is_same
<typename
value_traits::value_type
, T
>::value
));
2372 treap_multiset( const value_compare
&cmp
= value_compare()
2373 , const priority_compare
&pcmp
= priority_compare()
2374 , const value_traits
&v_traits
= value_traits())
2375 : Base(cmp
, pcmp
, v_traits
)
2378 template<class Iterator
>
2379 treap_multiset( Iterator b
, Iterator e
2380 , const value_compare
&cmp
= value_compare()
2381 , const priority_compare
&pcmp
= priority_compare()
2382 , const value_traits
&v_traits
= value_traits())
2383 : Base(b
, e
, cmp
, pcmp
, v_traits
)
2386 static treap_multiset
&container_from_end_iterator(iterator end_iterator
)
2387 { return static_cast<treap_multiset
&>(Base::container_from_end_iterator(end_iterator
)); }
2389 static const treap_multiset
&container_from_end_iterator(const_iterator end_iterator
)
2390 { return static_cast<const treap_multiset
&>(Base::container_from_end_iterator(end_iterator
)); }
2392 static treap_multiset
&container_from_iterator(iterator it
)
2393 { return static_cast<treap_multiset
&>(Base::container_from_iterator(it
)); }
2395 static const treap_multiset
&container_from_iterator(const_iterator it
)
2396 { return static_cast<const treap_multiset
&>(Base::container_from_iterator(it
)); }
2401 } //namespace intrusive
2404 #include <boost/intrusive/detail/config_end.hpp>
2406 #endif //BOOST_INTRUSIVE_TRIE_SET_HPP