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_AVL_SET_HPP
13 #define BOOST_INTRUSIVE_AVL_SET_HPP
15 #include <boost/intrusive/detail/config_begin.hpp>
16 #include <boost/intrusive/intrusive_fwd.hpp>
17 #include <boost/intrusive/avltree.hpp>
18 #include <boost/intrusive/detail/mpl.hpp>
24 //! The class template avl_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<> and
35 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
36 template<class T
, class ...Options
>
38 template<class Config
>
43 typedef avltree_impl
<Config
> tree_type
;
46 avl_set_impl (const avl_set_impl
&);
50 avl_set_impl
&operator =(const avl_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::key_compare key_compare
;
66 typedef typename
implementation_defined::iterator iterator
;
67 typedef typename
implementation_defined::const_iterator const_iterator
;
68 typedef typename
implementation_defined::reverse_iterator reverse_iterator
;
69 typedef typename
implementation_defined::const_reverse_iterator const_reverse_iterator
;
70 typedef typename
implementation_defined::insert_commit_data insert_commit_data
;
71 typedef typename
implementation_defined::node_traits node_traits
;
72 typedef typename
implementation_defined::node node
;
73 typedef typename
implementation_defined::node_ptr node_ptr
;
74 typedef typename
implementation_defined::const_node_ptr const_node_ptr
;
75 typedef typename
implementation_defined::node_algorithms node_algorithms
;
83 //! <b>Effects</b>: Constructs an empty avl_set.
85 //! <b>Complexity</b>: Constant.
87 //! <b>Throws</b>: If value_traits::node_traits::node
88 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
89 //! or the copy constructor of the value_compare object throws.
90 avl_set_impl( const value_compare
&cmp
= value_compare()
91 , const value_traits
&v_traits
= value_traits())
92 : tree_(cmp
, v_traits
)
95 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
96 //! cmp must be a comparison function that induces a strict weak ordering.
98 //! <b>Effects</b>: Constructs an empty avl_set and inserts elements from
101 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
102 //! comp and otherwise N * log N, where N is std::distance(last, first).
104 //! <b>Throws</b>: If value_traits::node_traits::node
105 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
106 //! or the copy constructor/operator() of the value_compare object throws.
107 template<class Iterator
>
108 avl_set_impl( Iterator b
, Iterator e
109 , const value_compare
&cmp
= value_compare()
110 , const value_traits
&v_traits
= value_traits())
111 : tree_(true, b
, e
, cmp
, v_traits
)
114 //! <b>Effects</b>: Detaches all elements from this. The objects in the avl_set
115 //! are not deleted (i.e. no destructors are called).
117 //! <b>Complexity</b>: Linear to the number of elements on the container.
118 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
120 //! <b>Throws</b>: Nothing.
124 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the avl_set.
126 //! <b>Complexity</b>: Constant.
128 //! <b>Throws</b>: Nothing.
130 { return tree_
.begin(); }
132 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the avl_set.
134 //! <b>Complexity</b>: Constant.
136 //! <b>Throws</b>: Nothing.
137 const_iterator
begin() const
138 { return tree_
.begin(); }
140 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the avl_set.
142 //! <b>Complexity</b>: Constant.
144 //! <b>Throws</b>: Nothing.
145 const_iterator
cbegin() const
146 { return tree_
.cbegin(); }
148 //! <b>Effects</b>: Returns an iterator pointing to the end of the avl_set.
150 //! <b>Complexity</b>: Constant.
152 //! <b>Throws</b>: Nothing.
154 { return tree_
.end(); }
156 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the avl_set.
158 //! <b>Complexity</b>: Constant.
160 //! <b>Throws</b>: Nothing.
161 const_iterator
end() const
162 { return tree_
.end(); }
164 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the avl_set.
166 //! <b>Complexity</b>: Constant.
168 //! <b>Throws</b>: Nothing.
169 const_iterator
cend() const
170 { return tree_
.cend(); }
172 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
173 //! reversed avl_set.
175 //! <b>Complexity</b>: Constant.
177 //! <b>Throws</b>: Nothing.
178 reverse_iterator
rbegin()
179 { return tree_
.rbegin(); }
181 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
182 //! of the reversed avl_set.
184 //! <b>Complexity</b>: Constant.
186 //! <b>Throws</b>: Nothing.
187 const_reverse_iterator
rbegin() const
188 { return tree_
.rbegin(); }
190 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
191 //! of the reversed avl_set.
193 //! <b>Complexity</b>: Constant.
195 //! <b>Throws</b>: Nothing.
196 const_reverse_iterator
crbegin() const
197 { return tree_
.crbegin(); }
199 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
200 //! of the reversed avl_set.
202 //! <b>Complexity</b>: Constant.
204 //! <b>Throws</b>: Nothing.
205 reverse_iterator
rend()
206 { return tree_
.rend(); }
208 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
209 //! of the reversed avl_set.
211 //! <b>Complexity</b>: Constant.
213 //! <b>Throws</b>: Nothing.
214 const_reverse_iterator
rend() const
215 { return tree_
.rend(); }
217 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
218 //! of the reversed avl_set.
220 //! <b>Complexity</b>: Constant.
222 //! <b>Throws</b>: Nothing.
223 const_reverse_iterator
crend() const
224 { return tree_
.crend(); }
226 //! <b>Precondition</b>: end_iterator must be a valid end iterator
229 //! <b>Effects</b>: Returns a const reference to the avl_set associated to the end iterator
231 //! <b>Throws</b>: Nothing.
233 //! <b>Complexity</b>: Constant.
234 static avl_set_impl
&container_from_end_iterator(iterator end_iterator
)
236 return *detail::parent_from_member
<avl_set_impl
, tree_type
>
237 ( &tree_type::container_from_end_iterator(end_iterator
)
238 , &avl_set_impl::tree_
);
241 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
244 //! <b>Effects</b>: Returns a const reference to the set associated to the end iterator
246 //! <b>Throws</b>: Nothing.
248 //! <b>Complexity</b>: Constant.
249 static const avl_set_impl
&container_from_end_iterator(const_iterator end_iterator
)
251 return *detail::parent_from_member
<avl_set_impl
, tree_type
>
252 ( &tree_type::container_from_end_iterator(end_iterator
)
253 , &avl_set_impl::tree_
);
256 //! <b>Precondition</b>: it must be a valid iterator of set.
258 //! <b>Effects</b>: Returns a reference to the set associated to the iterator
260 //! <b>Throws</b>: Nothing.
262 //! <b>Complexity</b>: Logarithmic.
263 static avl_set_impl
&container_from_iterator(iterator it
)
265 return *detail::parent_from_member
<avl_set_impl
, tree_type
>
266 ( &tree_type::container_from_iterator(it
)
267 , &avl_set_impl::tree_
);
270 //! <b>Precondition</b>: it must be a valid const_iterator of set.
272 //! <b>Effects</b>: Returns a const reference to the set associated to the iterator
274 //! <b>Throws</b>: Nothing.
276 //! <b>Complexity</b>: Logarithmic.
277 static const avl_set_impl
&container_from_iterator(const_iterator it
)
279 return *detail::parent_from_member
<avl_set_impl
, tree_type
>
280 ( &tree_type::container_from_iterator(it
)
281 , &avl_set_impl::tree_
);
284 //! <b>Effects</b>: Returns the key_compare object used by the avl_set.
286 //! <b>Complexity</b>: Constant.
288 //! <b>Throws</b>: If key_compare copy-constructor throws.
289 key_compare
key_comp() const
290 { return tree_
.value_comp(); }
292 //! <b>Effects</b>: Returns the value_compare object used by the avl_set.
294 //! <b>Complexity</b>: Constant.
296 //! <b>Throws</b>: If value_compare copy-constructor throws.
297 value_compare
value_comp() const
298 { return tree_
.value_comp(); }
300 //! <b>Effects</b>: Returns true is the container is empty.
302 //! <b>Complexity</b>: Constant.
304 //! <b>Throws</b>: Nothing.
306 { return tree_
.empty(); }
308 //! <b>Effects</b>: Returns the number of elements stored in the avl_set.
310 //! <b>Complexity</b>: Linear to elements contained in *this if,
311 //! constant-time size option is enabled. Constant-time otherwise.
313 //! <b>Throws</b>: Nothing.
314 size_type
size() const
315 { return tree_
.size(); }
317 //! <b>Effects</b>: Swaps the contents of two sets.
319 //! <b>Complexity</b>: Constant.
321 //! <b>Throws</b>: If the swap() call for the comparison functor
322 //! found using ADL throws. Strong guarantee.
323 void swap(avl_set_impl
& other
)
324 { tree_
.swap(other
.tree_
); }
326 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
327 //! Cloner should yield to nodes equivalent to the original nodes.
329 //! <b>Effects</b>: Erases all the elements from *this
330 //! calling Disposer::operator()(pointer), clones all the
331 //! elements from src calling Cloner::operator()(const_reference )
332 //! and inserts them on *this. Copies the predicate from the source container.
334 //! If cloner throws, all cloned elements are unlinked and disposed
335 //! calling Disposer::operator()(pointer).
337 //! <b>Complexity</b>: Linear to erased plus inserted elements.
339 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
340 template <class Cloner
, class Disposer
>
341 void clone_from(const avl_set_impl
&src
, Cloner cloner
, Disposer disposer
)
342 { tree_
.clone_from(src
.tree_
, cloner
, disposer
); }
344 //! <b>Requires</b>: value must be an lvalue
346 //! <b>Effects</b>: Treaps to inserts value into the avl_set.
348 //! <b>Returns</b>: If the value
349 //! is not already present inserts it and returns a pair containing the
350 //! iterator to the new value and true. If there is an equivalent value
351 //! returns a pair containing an iterator to the already present value
354 //! <b>Complexity</b>: Average complexity for insert element is at
355 //! most logarithmic.
357 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
359 //! <b>Note</b>: Does not affect the validity of iterators and references.
360 //! No copy-constructors are called.
361 std::pair
<iterator
, bool> insert(reference value
)
362 { return tree_
.insert_unique(value
); }
364 //! <b>Requires</b>: value must be an lvalue
366 //! <b>Effects</b>: Treaps to to insert x into the avl_set, using "hint"
367 //! as a hint to where it will be inserted.
369 //! <b>Returns</b>: An iterator that points to the position where the
370 //! new element was inserted into the avl_set.
372 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
373 //! constant time if t is inserted immediately before hint.
375 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
377 //! <b>Note</b>: Does not affect the validity of iterators and references.
378 //! No copy-constructors are called.
379 iterator
insert(const_iterator hint
, reference value
)
380 { return tree_
.insert_unique(hint
, value
); }
382 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
383 //! the same strict weak ordering as value_compare. The difference is that
384 //! key_value_comp compares an arbitrary key with the contained values.
386 //! <b>Effects</b>: Checks if a value can be inserted in the avl_set, using
387 //! a user provided key instead of the value itself.
389 //! <b>Returns</b>: If there is an equivalent value
390 //! returns a pair containing an iterator to the already present value
391 //! and false. If the value can be inserted returns true in the returned
392 //! pair boolean and fills "commit_data" that is meant to be used with
393 //! the "insert_commit" function.
395 //! <b>Complexity</b>: Average complexity is at most logarithmic.
397 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
399 //! <b>Notes</b>: This function is used to improve performance when constructing
400 //! a value_type is expensive: if there is an equivalent value
401 //! the constructed object must be discarded. Many times, the part of the
402 //! node that is used to impose the order is much cheaper to construct
403 //! than the value_type and this function offers the possibility to use that
404 //! part to check if the insertion will be successful.
406 //! If the check is successful, the user can construct the value_type and use
407 //! "insert_commit" to insert the object in constant-time. This gives a total
408 //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
410 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
411 //! objects are inserted or erased from the avl_set.
412 template<class KeyType
, class KeyValueCompare
>
413 std::pair
<iterator
, bool> insert_check
414 (const KeyType
&key
, KeyValueCompare key_value_comp
, insert_commit_data
&commit_data
)
415 { return tree_
.insert_unique_check(key
, key_value_comp
, commit_data
); }
417 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
418 //! the same strict weak ordering as value_compare. The difference is that
419 //! key_value_comp compares an arbitrary key with the contained values.
421 //! <b>Effects</b>: Checks if a value can be inserted in the avl_set, using
422 //! a user provided key instead of the value itself, using "hint"
423 //! as a hint to where it will be inserted.
425 //! <b>Returns</b>: If there is an equivalent value
426 //! returns a pair containing an iterator to the already present value
427 //! and false. If the value can be inserted returns true in the returned
428 //! pair boolean and fills "commit_data" that is meant to be used with
429 //! the "insert_commit" function.
431 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
432 //! constant time if t is inserted immediately before hint.
434 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
436 //! <b>Notes</b>: This function is used to improve performance when constructing
437 //! a value_type is expensive: if there is an equivalent value
438 //! the constructed object must be discarded. Many times, the part of the
439 //! constructing that is used to impose the order is much cheaper to construct
440 //! than the value_type and this function offers the possibility to use that key
441 //! to check if the insertion will be successful.
443 //! If the check is successful, the user can construct the value_type and use
444 //! "insert_commit" to insert the object in constant-time. This can give a total
445 //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
447 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
448 //! objects are inserted or erased from the avl_set.
449 template<class KeyType
, class KeyValueCompare
>
450 std::pair
<iterator
, bool> insert_check
451 (const_iterator hint
, const KeyType
&key
452 ,KeyValueCompare key_value_comp
, insert_commit_data
&commit_data
)
453 { return tree_
.insert_unique_check(hint
, key
, key_value_comp
, commit_data
); }
455 //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
456 //! must have been obtained from a previous call to "insert_check".
457 //! No objects should have been inserted or erased from the avl_set between
458 //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
460 //! <b>Effects</b>: Inserts the value in the avl_set using the information obtained
461 //! from the "commit_data" that a previous "insert_check" filled.
463 //! <b>Returns</b>: An iterator to the newly inserted object.
465 //! <b>Complexity</b>: Constant time.
467 //! <b>Throws</b>: Nothing.
469 //! <b>Notes</b>: This function has only sense if a "insert_check" has been
470 //! previously executed to fill "commit_data". No value should be inserted or
471 //! erased between the "insert_check" and "insert_commit" calls.
472 iterator
insert_commit(reference value
, const insert_commit_data
&commit_data
)
473 { return tree_
.insert_unique_commit(value
, commit_data
); }
475 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
476 //! of type value_type.
478 //! <b>Effects</b>: Inserts a range into the avl_set.
480 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
481 //! size of the range. However, it is linear in N if the range is already sorted
484 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
486 //! <b>Note</b>: Does not affect the validity of iterators and references.
487 //! No copy-constructors are called.
488 template<class Iterator
>
489 void insert(Iterator b
, Iterator e
)
490 { tree_
.insert_unique(b
, e
); }
492 //! <b>Effects</b>: Erases the element pointed to by pos.
494 //! <b>Complexity</b>: Average complexity is constant time.
496 //! <b>Returns</b>: An iterator to the element after the erased element.
498 //! <b>Throws</b>: Nothing.
500 //! <b>Note</b>: Invalidates the iterators (but not the references)
501 //! to the erased elements. No destructors are called.
502 iterator
erase(const_iterator i
)
503 { return tree_
.erase(i
); }
505 //! <b>Effects</b>: Erases the range pointed to by b end e.
507 //! <b>Complexity</b>: Average complexity for erase range is at most
508 //! O(log(size() + N)), where N is the number of elements in the range.
510 //! <b>Returns</b>: An iterator to the element after the erased elements.
512 //! <b>Throws</b>: Nothing.
514 //! <b>Note</b>: Invalidates the iterators (but not the references)
515 //! to the erased elements. No destructors are called.
516 iterator
erase(const_iterator b
, const_iterator e
)
517 { return tree_
.erase(b
, e
); }
519 //! <b>Effects</b>: Erases all the elements with the given value.
521 //! <b>Returns</b>: The number of erased elements.
523 //! <b>Complexity</b>: O(log(size()) + this->count(value)).
525 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
527 //! <b>Note</b>: Invalidates the iterators (but not the references)
528 //! to the erased elements. No destructors are called.
529 size_type
erase(const_reference value
)
530 { return tree_
.erase(value
); }
532 //! <b>Effects</b>: Erases all the elements that compare equal with
533 //! the given key and the given comparison functor.
535 //! <b>Returns</b>: The number of erased elements.
537 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
539 //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee.
541 //! <b>Note</b>: Invalidates the iterators (but not the references)
542 //! to the erased elements. No destructors are called.
543 template<class KeyType
, class KeyValueCompare
>
544 size_type
erase(const KeyType
& key
, KeyValueCompare comp
546 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
549 { return tree_
.erase(key
, comp
); }
551 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
553 //! <b>Effects</b>: Erases the element pointed to by pos.
554 //! Disposer::operator()(pointer) is called for the removed element.
556 //! <b>Complexity</b>: Average complexity for erase element is constant time.
558 //! <b>Returns</b>: An iterator to the element after the erased element.
560 //! <b>Throws</b>: Nothing.
562 //! <b>Note</b>: Invalidates the iterators
563 //! to the erased elements.
564 template<class Disposer
>
565 iterator
erase_and_dispose(const_iterator i
, Disposer disposer
)
566 { return tree_
.erase_and_dispose(i
, disposer
); }
568 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
569 template<class Disposer
>
570 iterator
erase_and_dispose(iterator i
, Disposer disposer
)
571 { return this->erase_and_dispose(const_iterator(i
), disposer
); }
574 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
576 //! <b>Effects</b>: Erases the range pointed to by b end e.
577 //! Disposer::operator()(pointer) is called for the removed elements.
579 //! <b>Complexity</b>: Average complexity for erase range is at most
580 //! O(log(size() + N)), where N is the number of elements in the range.
582 //! <b>Returns</b>: An iterator to the element after the erased elements.
584 //! <b>Throws</b>: Nothing.
586 //! <b>Note</b>: Invalidates the iterators
587 //! to the erased elements.
588 template<class Disposer
>
589 iterator
erase_and_dispose(const_iterator b
, const_iterator e
, Disposer disposer
)
590 { return tree_
.erase_and_dispose(b
, e
, disposer
); }
592 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
594 //! <b>Effects</b>: Erases all the elements with the given value.
595 //! Disposer::operator()(pointer) is called for the removed elements.
597 //! <b>Throws</b>: If the internal value_compare ordering function throws.
599 //! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee.
601 //! <b>Throws</b>: Nothing.
603 //! <b>Note</b>: Invalidates the iterators (but not the references)
604 //! to the erased elements. No destructors are called.
605 template<class Disposer
>
606 size_type
erase_and_dispose(const_reference value
, Disposer disposer
)
607 { return tree_
.erase_and_dispose(value
, disposer
); }
609 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
611 //! <b>Effects</b>: Erases all the elements with the given key.
612 //! according to the comparison functor "comp".
613 //! Disposer::operator()(pointer) is called for the removed elements.
615 //! <b>Returns</b>: The number of erased elements.
617 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
619 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
621 //! <b>Note</b>: Invalidates the iterators
622 //! to the erased elements.
623 template<class KeyType
, class KeyValueCompare
, class Disposer
>
624 size_type
erase_and_dispose(const KeyType
& key
, KeyValueCompare comp
, Disposer disposer
626 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
629 { return tree_
.erase_and_dispose(key
, comp
, disposer
); }
631 //! <b>Effects</b>: Erases all the elements of the container.
633 //! <b>Complexity</b>: Linear to the number of elements on the container.
634 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
636 //! <b>Throws</b>: Nothing.
638 //! <b>Note</b>: Invalidates the iterators (but not the references)
639 //! to the erased elements. No destructors are called.
641 { return tree_
.clear(); }
643 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
645 //! <b>Effects</b>: Erases all the elements of the container.
647 //! <b>Complexity</b>: Linear to the number of elements on the container.
648 //! Disposer::operator()(pointer) is called for the removed elements.
650 //! <b>Throws</b>: Nothing.
652 //! <b>Note</b>: Invalidates the iterators (but not the references)
653 //! to the erased elements. No destructors are called.
654 template<class Disposer
>
655 void clear_and_dispose(Disposer disposer
)
656 { return tree_
.clear_and_dispose(disposer
); }
658 //! <b>Effects</b>: Returns the number of contained elements with the given key
660 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
661 //! to number of objects with the given key.
663 //! <b>Throws</b>: If the internal value_compare ordering function throws.
664 size_type
count(const_reference value
) const
665 { return tree_
.find(value
) != end(); }
667 //! <b>Effects</b>: Returns the number of contained elements with the same key
668 //! compared with the given comparison functor.
670 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
671 //! to number of objects with the given key.
673 //! <b>Throws</b>: If comp ordering function throws.
674 template<class KeyType
, class KeyValueCompare
>
675 size_type
count(const KeyType
& key
, KeyValueCompare comp
) const
676 { return tree_
.find(key
, comp
) != end(); }
678 //! <b>Effects</b>: Returns an iterator to the first element whose
679 //! key is not less than k or end() if that element does not exist.
681 //! <b>Complexity</b>: Logarithmic.
683 //! <b>Throws</b>: If the internal value_compare ordering function throws.
684 iterator
lower_bound(const_reference value
)
685 { return tree_
.lower_bound(value
); }
687 //! <b>Requires</b>: comp must imply the same element order as
688 //! value_compare. Usually key is the part of the value_type
689 //! that is used in the ordering functor.
691 //! <b>Effects</b>: Returns an iterator to the first element whose
692 //! key according to the comparison functor is not less than k or
693 //! end() if that element does not exist.
695 //! <b>Complexity</b>: Logarithmic.
697 //! <b>Throws</b>: If comp ordering function throws.
699 //! <b>Note</b>: This function is used when constructing a value_type
700 //! is expensive and the value_type can be compared with a cheaper
701 //! key type. Usually this key is part of the value_type.
702 template<class KeyType
, class KeyValueCompare
>
703 iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
)
704 { return tree_
.lower_bound(key
, comp
); }
706 //! <b>Effects</b>: Returns a const iterator to the first element whose
707 //! key is not less than k or end() if that element does not exist.
709 //! <b>Complexity</b>: Logarithmic.
711 //! <b>Throws</b>: If the internal value_compare ordering function throws.
712 const_iterator
lower_bound(const_reference value
) const
713 { return tree_
.lower_bound(value
); }
715 //! <b>Requires</b>: comp must imply the same element order as
716 //! value_compare. Usually key is the part of the value_type
717 //! that is used in the ordering functor.
719 //! <b>Effects</b>: Returns a const_iterator to the first element whose
720 //! key according to the comparison functor is not less than k or
721 //! end() if that element does not exist.
723 //! <b>Complexity</b>: Logarithmic.
725 //! <b>Throws</b>: If comp ordering function throws.
727 //! <b>Note</b>: This function is used when constructing a value_type
728 //! is expensive and the value_type can be compared with a cheaper
729 //! key type. Usually this key is part of the value_type.
730 template<class KeyType
, class KeyValueCompare
>
731 const_iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
) const
732 { return tree_
.lower_bound(key
, comp
); }
734 //! <b>Effects</b>: Returns an iterator to the first element whose
735 //! key is greater than k or end() if that element does not exist.
737 //! <b>Complexity</b>: Logarithmic.
739 //! <b>Throws</b>: If the internal value_compare ordering function throws.
740 iterator
upper_bound(const_reference value
)
741 { return tree_
.upper_bound(value
); }
743 //! <b>Requires</b>: comp must imply the same element order as
744 //! value_compare. Usually key is the part of the value_type
745 //! that is used in the ordering functor.
747 //! <b>Effects</b>: Returns an iterator to the first element whose
748 //! key according to the comparison functor is greater than key or
749 //! end() if that element does not exist.
751 //! <b>Complexity</b>: Logarithmic.
753 //! <b>Throws</b>: If comp ordering function throws.
755 //! <b>Note</b>: This function is used when constructing a value_type
756 //! is expensive and the value_type can be compared with a cheaper
757 //! key type. Usually this key is part of the value_type.
758 template<class KeyType
, class KeyValueCompare
>
759 iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
)
760 { return tree_
.upper_bound(key
, comp
); }
762 //! <b>Effects</b>: Returns an iterator to the first element whose
763 //! key is greater than k or end() if that element does not exist.
765 //! <b>Complexity</b>: Logarithmic.
767 //! <b>Throws</b>: If the internal value_compare ordering function throws.
768 const_iterator
upper_bound(const_reference value
) const
769 { return tree_
.upper_bound(value
); }
771 //! <b>Requires</b>: comp must imply the same element order as
772 //! value_compare. Usually key is the part of the value_type
773 //! that is used in the ordering functor.
775 //! <b>Effects</b>: Returns a const_iterator to the first element whose
776 //! key according to the comparison functor is greater than key or
777 //! end() if that element does not exist.
779 //! <b>Complexity</b>: Logarithmic.
781 //! <b>Throws</b>: If comp ordering function throws.
783 //! <b>Note</b>: This function is used when constructing a value_type
784 //! is expensive and the value_type can be compared with a cheaper
785 //! key type. Usually this key is part of the value_type.
786 template<class KeyType
, class KeyValueCompare
>
787 const_iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
) const
788 { return tree_
.upper_bound(key
, comp
); }
790 //! <b>Effects</b>: Finds an iterator to the first element whose value is
791 //! "value" or end() if that element does not exist.
793 //! <b>Complexity</b>: Logarithmic.
795 //! <b>Throws</b>: If the internal value_compare ordering function throws.
796 iterator
find(const_reference value
)
797 { return tree_
.find(value
); }
799 //! <b>Requires</b>: comp must imply the same element order as
800 //! value_compare. Usually key is the part of the value_type
801 //! that is used in the ordering functor.
803 //! <b>Effects</b>: Finds an iterator to the first element whose key is
804 //! "key" according to the comparison functor or end() if that element
807 //! <b>Complexity</b>: Logarithmic.
809 //! <b>Throws</b>: If comp ordering function throws.
811 //! <b>Note</b>: This function is used when constructing a value_type
812 //! is expensive and the value_type can be compared with a cheaper
813 //! key type. Usually this key is part of the value_type.
814 template<class KeyType
, class KeyValueCompare
>
815 iterator
find(const KeyType
& key
, KeyValueCompare comp
)
816 { return tree_
.find(key
, comp
); }
818 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
819 //! "value" or end() if that element does not exist.
821 //! <b>Complexity</b>: Logarithmic.
823 //! <b>Throws</b>: If the internal value_compare ordering function throws.
824 const_iterator
find(const_reference value
) const
825 { return tree_
.find(value
); }
827 //! <b>Requires</b>: comp must imply the same element order as
828 //! value_compare. Usually key is the part of the value_type
829 //! that is used in the ordering functor.
831 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
832 //! "key" according to the comparison functor or end() if that element
835 //! <b>Complexity</b>: Logarithmic.
837 //! <b>Throws</b>: If comp ordering function throws.
839 //! <b>Note</b>: This function is used when constructing a value_type
840 //! is expensive and the value_type can be compared with a cheaper
841 //! key type. Usually this key is part of the value_type.
842 template<class KeyType
, class KeyValueCompare
>
843 const_iterator
find(const KeyType
& key
, KeyValueCompare comp
) const
844 { return tree_
.find(key
, comp
); }
846 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
847 //! an empty range that indicates the position where those elements would be
848 //! if they there is no elements with key k.
850 //! <b>Complexity</b>: Logarithmic.
852 //! <b>Throws</b>: If the internal value_compare ordering function throws.
853 std::pair
<iterator
,iterator
> equal_range(const_reference value
)
854 { return tree_
.equal_range(value
); }
856 //! <b>Requires</b>: comp must imply the same element order as
857 //! value_compare. Usually key is the part of the value_type
858 //! that is used in the ordering functor.
860 //! <b>Effects</b>: Finds a range containing all elements whose key is k
861 //! according to the comparison functor or an empty range
862 //! that indicates the position where those elements would be
863 //! if they there is no elements with key k.
865 //! <b>Complexity</b>: Logarithmic.
867 //! <b>Throws</b>: If comp ordering function throws.
869 //! <b>Note</b>: This function is used when constructing a value_type
870 //! is expensive and the value_type can be compared with a cheaper
871 //! key type. Usually this key is part of the value_type.
872 template<class KeyType
, class KeyValueCompare
>
873 std::pair
<iterator
,iterator
> equal_range(const KeyType
& key
, KeyValueCompare comp
)
874 { return tree_
.equal_range(key
, comp
); }
876 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
877 //! an empty range that indicates the position where those elements would be
878 //! if they there is no elements with key k.
880 //! <b>Complexity</b>: Logarithmic.
882 //! <b>Throws</b>: If the internal value_compare ordering function throws.
883 std::pair
<const_iterator
, const_iterator
>
884 equal_range(const_reference value
) const
885 { return tree_
.equal_range(value
); }
887 //! <b>Requires</b>: comp must imply the same element order as
888 //! value_compare. Usually key is the part of the value_type
889 //! that is used in the ordering functor.
891 //! <b>Effects</b>: Finds a range containing all elements whose key is k
892 //! according to the comparison functor or an empty range
893 //! that indicates the position where those elements would be
894 //! if they there is no elements with key k.
896 //! <b>Complexity</b>: Logarithmic.
898 //! <b>Throws</b>: If comp ordering function throws.
900 //! <b>Note</b>: This function is used when constructing a value_type
901 //! is expensive and the value_type can be compared with a cheaper
902 //! key type. Usually this key is part of the value_type.
903 template<class KeyType
, class KeyValueCompare
>
904 std::pair
<const_iterator
, const_iterator
>
905 equal_range(const KeyType
& key
, KeyValueCompare comp
) const
906 { return tree_
.equal_range(key
, comp
); }
908 //! <b>Requires</b>: value must be an lvalue and shall be in a avl_set of
909 //! appropriate type. Otherwise the behavior is undefined.
911 //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_set
912 //! that points to the value
914 //! <b>Complexity</b>: Constant.
916 //! <b>Throws</b>: Nothing.
918 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
920 static iterator
s_iterator_to(reference value
)
921 { return tree_type::s_iterator_to(value
); }
923 //! <b>Requires</b>: value must be an lvalue and shall be in a avl_set of
924 //! appropriate type. Otherwise the behavior is undefined.
926 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
927 //! avl_set that points to the value
929 //! <b>Complexity</b>: Constant.
931 //! <b>Throws</b>: Nothing.
933 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
935 static const_iterator
s_iterator_to(const_reference value
)
936 { return tree_type::s_iterator_to(value
); }
938 //! <b>Requires</b>: value must be an lvalue and shall be in a avl_set of
939 //! appropriate type. Otherwise the behavior is undefined.
941 //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_set
942 //! that points to the value
944 //! <b>Complexity</b>: Constant.
946 //! <b>Throws</b>: Nothing.
947 iterator
iterator_to(reference value
)
948 { return tree_
.iterator_to(value
); }
950 //! <b>Requires</b>: value must be an lvalue and shall be in a avl_set of
951 //! appropriate type. Otherwise the behavior is undefined.
953 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
954 //! avl_set that points to the value
956 //! <b>Complexity</b>: Constant.
958 //! <b>Throws</b>: Nothing.
959 const_iterator
iterator_to(const_reference value
) const
960 { return tree_
.iterator_to(value
); }
962 //! <b>Requires</b>: value shall not be in a avl_set/avl_multiset.
964 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
967 //! <b>Throws</b>: Nothing.
969 //! <b>Complexity</b>: Constant time.
971 //! <b>Note</b>: This function puts the hook in the well-known default state
972 //! used by auto_unlink and safe hooks.
973 static void init_node(reference value
)
974 { tree_type::init_node(value
); }
976 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
978 //! <b>Complexity</b>: Average complexity is constant time.
980 //! <b>Throws</b>: Nothing.
982 //! <b>Notes</b>: This function breaks the tree and the tree can
983 //! only be used for more unlink_leftmost_without_rebalance calls.
984 //! This function is normally used to achieve a step by step
985 //! controlled destruction of the tree.
986 pointer
unlink_leftmost_without_rebalance()
987 { return tree_
.unlink_leftmost_without_rebalance(); }
989 //! <b>Requires</b>: replace_this must be a valid iterator of *this
990 //! and with_this must not be inserted in any tree.
992 //! <b>Effects</b>: Replaces replace_this in its position in the
993 //! tree with with_this. The tree does not need to be rebalanced.
995 //! <b>Complexity</b>: Constant.
997 //! <b>Throws</b>: Nothing.
999 //! <b>Note</b>: This function will break container ordering invariants if
1000 //! with_this is not equivalent to *replace_this according to the
1001 //! ordering rules. This function is faster than erasing and inserting
1002 //! the node, since no rebalancing or comparison is needed.
1003 void replace_node(iterator replace_this
, reference with_this
)
1004 { tree_
.replace_node(replace_this
, with_this
); }
1007 friend bool operator==(const avl_set_impl
&x
, const avl_set_impl
&y
)
1008 { return x
.tree_
== y
.tree_
; }
1010 friend bool operator<(const avl_set_impl
&x
, const avl_set_impl
&y
)
1011 { return x
.tree_
< y
.tree_
; }
1015 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1016 template<class T
, class ...Options
>
1018 template<class Config
>
1020 inline bool operator!=
1021 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1022 (const avl_set_impl
<T
, Options
...> &x
, const avl_set_impl
<T
, Options
...> &y
)
1024 (const avl_set_impl
<Config
> &x
, const avl_set_impl
<Config
> &y
)
1026 { return !(x
== y
); }
1028 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1029 template<class T
, class ...Options
>
1031 template<class Config
>
1033 inline bool operator>
1034 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1035 (const avl_set_impl
<T
, Options
...> &x
, const avl_set_impl
<T
, Options
...> &y
)
1037 (const avl_set_impl
<Config
> &x
, const avl_set_impl
<Config
> &y
)
1041 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1042 template<class T
, class ...Options
>
1044 template<class Config
>
1046 inline bool operator<=
1047 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1048 (const avl_set_impl
<T
, Options
...> &x
, const avl_set_impl
<T
, Options
...> &y
)
1050 (const avl_set_impl
<Config
> &x
, const avl_set_impl
<Config
> &y
)
1052 { return !(y
< x
); }
1054 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1055 template<class T
, class ...Options
>
1057 template<class Config
>
1059 inline bool operator>=
1060 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1061 (const avl_set_impl
<T
, Options
...> &x
, const avl_set_impl
<T
, Options
...> &y
)
1063 (const avl_set_impl
<Config
> &x
, const avl_set_impl
<Config
> &y
)
1065 { return !(x
< y
); }
1067 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1068 template<class T
, class ...Options
>
1070 template<class Config
>
1073 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1074 (avl_set_impl
<T
, Options
...> &x
, avl_set_impl
<T
, Options
...> &y
)
1076 (avl_set_impl
<Config
> &x
, avl_set_impl
<Config
> &y
)
1080 //! Helper metafunction to define a \c avl_set that yields to the same type when the
1081 //! same options (either explicitly or implicitly) are used.
1082 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1083 template<class T
, class ...Options
>
1085 template<class T
, class O1
= none
, class O2
= none
1086 , class O3
= none
, class O4
= none
>
1091 typedef avl_set_impl
1092 < typename make_avltree_opt
1093 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1099 > implementation_defined
;
1101 typedef implementation_defined type
;
1104 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1106 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1107 template<class T
, class O1
, class O2
, class O3
, class O4
>
1109 template<class T
, class ...Options
>
1112 : public make_avl_set
1113 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1120 typedef typename make_avl_set
1121 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1129 typedef typename
Base::value_compare value_compare
;
1130 typedef typename
Base::value_traits value_traits
;
1131 typedef typename
Base::iterator iterator
;
1132 typedef typename
Base::const_iterator const_iterator
;
1134 //Assert if passed value traits are compatible with the type
1135 BOOST_STATIC_ASSERT((detail::is_same
<typename
value_traits::value_type
, T
>::value
));
1137 avl_set( const value_compare
&cmp
= value_compare()
1138 , const value_traits
&v_traits
= value_traits())
1139 : Base(cmp
, v_traits
)
1142 template<class Iterator
>
1143 avl_set( Iterator b
, Iterator e
1144 , const value_compare
&cmp
= value_compare()
1145 , const value_traits
&v_traits
= value_traits())
1146 : Base(b
, e
, cmp
, v_traits
)
1149 static avl_set
&container_from_end_iterator(iterator end_iterator
)
1150 { return static_cast<avl_set
&>(Base::container_from_end_iterator(end_iterator
)); }
1152 static const avl_set
&container_from_end_iterator(const_iterator end_iterator
)
1153 { return static_cast<const avl_set
&>(Base::container_from_end_iterator(end_iterator
)); }
1155 static avl_set
&container_from_iterator(iterator end_iterator
)
1156 { return static_cast<avl_set
&>(Base::container_from_iterator(end_iterator
)); }
1158 static const avl_set
&container_from_iterator(const_iterator end_iterator
)
1159 { return static_cast<const avl_set
&>(Base::container_from_iterator(end_iterator
)); }
1164 //! The class template avl_multiset is an intrusive container, that mimics most of
1165 //! the interface of std::avl_multiset as described in the C++ standard.
1167 //! The template parameter \c T is the type to be managed by the container.
1168 //! The user can specify additional options and if no options are provided
1169 //! default options are used.
1171 //! The container supports the following options:
1172 //! \c base_hook<>/member_hook<>/value_traits<>,
1173 //! \c constant_time_size<>, \c size_type<> and
1175 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1176 template<class T
, class ...Options
>
1178 template<class Config
>
1180 class avl_multiset_impl
1183 typedef avltree_impl
<Config
> tree_type
;
1185 //Non-copyable and non-assignable
1186 avl_multiset_impl (const avl_multiset_impl
&);
1187 avl_multiset_impl
&operator =(const avl_multiset_impl
&);
1188 typedef tree_type implementation_defined
;
1192 typedef typename
implementation_defined::value_type value_type
;
1193 typedef typename
implementation_defined::value_traits value_traits
;
1194 typedef typename
implementation_defined::pointer pointer
;
1195 typedef typename
implementation_defined::const_pointer const_pointer
;
1196 typedef typename
implementation_defined::reference reference
;
1197 typedef typename
implementation_defined::const_reference const_reference
;
1198 typedef typename
implementation_defined::difference_type difference_type
;
1199 typedef typename
implementation_defined::size_type size_type
;
1200 typedef typename
implementation_defined::value_compare value_compare
;
1201 typedef typename
implementation_defined::key_compare key_compare
;
1202 typedef typename
implementation_defined::iterator iterator
;
1203 typedef typename
implementation_defined::const_iterator const_iterator
;
1204 typedef typename
implementation_defined::reverse_iterator reverse_iterator
;
1205 typedef typename
implementation_defined::const_reverse_iterator const_reverse_iterator
;
1206 typedef typename
implementation_defined::insert_commit_data insert_commit_data
;
1207 typedef typename
implementation_defined::node_traits node_traits
;
1208 typedef typename
implementation_defined::node node
;
1209 typedef typename
implementation_defined::node_ptr node_ptr
;
1210 typedef typename
implementation_defined::const_node_ptr const_node_ptr
;
1211 typedef typename
implementation_defined::node_algorithms node_algorithms
;
1219 //! <b>Effects</b>: Constructs an empty avl_multiset.
1221 //! <b>Complexity</b>: Constant.
1223 //! <b>Throws</b>: If value_traits::node_traits::node
1224 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1225 //! or the copy constructor/operator() of the value_compare object throws.
1226 avl_multiset_impl( const value_compare
&cmp
= value_compare()
1227 , const value_traits
&v_traits
= value_traits())
1228 : tree_(cmp
, v_traits
)
1231 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
1232 //! cmp must be a comparison function that induces a strict weak ordering.
1234 //! <b>Effects</b>: Constructs an empty avl_multiset and inserts elements from
1237 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
1238 //! comp and otherwise N * log N, where N is the distance between first and last
1240 //! <b>Throws</b>: If value_traits::node_traits::node
1241 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1242 //! or the copy constructor/operator() of the value_compare object throws.
1243 template<class Iterator
>
1244 avl_multiset_impl( Iterator b
, Iterator e
1245 , const value_compare
&cmp
= value_compare()
1246 , const value_traits
&v_traits
= value_traits())
1247 : tree_(false, b
, e
, cmp
, v_traits
)
1250 //! <b>Effects</b>: Detaches all elements from this. The objects in the avl_multiset
1251 //! are not deleted (i.e. no destructors are called).
1253 //! <b>Complexity</b>: Linear to the number of elements on the container.
1254 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1256 //! <b>Throws</b>: Nothing.
1257 ~avl_multiset_impl()
1260 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the avl_multiset.
1262 //! <b>Complexity</b>: Constant.
1264 //! <b>Throws</b>: Nothing.
1266 { return tree_
.begin(); }
1268 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the avl_multiset.
1270 //! <b>Complexity</b>: Constant.
1272 //! <b>Throws</b>: Nothing.
1273 const_iterator
begin() const
1274 { return tree_
.begin(); }
1276 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the avl_multiset.
1278 //! <b>Complexity</b>: Constant.
1280 //! <b>Throws</b>: Nothing.
1281 const_iterator
cbegin() const
1282 { return tree_
.cbegin(); }
1284 //! <b>Effects</b>: Returns an iterator pointing to the end of the avl_multiset.
1286 //! <b>Complexity</b>: Constant.
1288 //! <b>Throws</b>: Nothing.
1290 { return tree_
.end(); }
1292 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the avl_multiset.
1294 //! <b>Complexity</b>: Constant.
1296 //! <b>Throws</b>: Nothing.
1297 const_iterator
end() const
1298 { return tree_
.end(); }
1300 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the avl_multiset.
1302 //! <b>Complexity</b>: Constant.
1304 //! <b>Throws</b>: Nothing.
1305 const_iterator
cend() const
1306 { return tree_
.cend(); }
1308 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
1309 //! reversed avl_multiset.
1311 //! <b>Complexity</b>: Constant.
1313 //! <b>Throws</b>: Nothing.
1314 reverse_iterator
rbegin()
1315 { return tree_
.rbegin(); }
1317 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1318 //! of the reversed avl_multiset.
1320 //! <b>Complexity</b>: Constant.
1322 //! <b>Throws</b>: Nothing.
1323 const_reverse_iterator
rbegin() const
1324 { return tree_
.rbegin(); }
1326 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1327 //! of the reversed avl_multiset.
1329 //! <b>Complexity</b>: Constant.
1331 //! <b>Throws</b>: Nothing.
1332 const_reverse_iterator
crbegin() const
1333 { return tree_
.crbegin(); }
1335 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
1336 //! of the reversed avl_multiset.
1338 //! <b>Complexity</b>: Constant.
1340 //! <b>Throws</b>: Nothing.
1341 reverse_iterator
rend()
1342 { return tree_
.rend(); }
1344 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1345 //! of the reversed avl_multiset.
1347 //! <b>Complexity</b>: Constant.
1349 //! <b>Throws</b>: Nothing.
1350 const_reverse_iterator
rend() const
1351 { return tree_
.rend(); }
1353 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1354 //! of the reversed avl_multiset.
1356 //! <b>Complexity</b>: Constant.
1358 //! <b>Throws</b>: Nothing.
1359 const_reverse_iterator
crend() const
1360 { return tree_
.crend(); }
1362 //! <b>Precondition</b>: end_iterator must be a valid end iterator
1363 //! of avl_multiset.
1365 //! <b>Effects</b>: Returns a const reference to the avl_multiset associated to the end iterator
1367 //! <b>Throws</b>: Nothing.
1369 //! <b>Complexity</b>: Constant.
1370 static avl_multiset_impl
&container_from_end_iterator(iterator end_iterator
)
1372 return *detail::parent_from_member
<avl_multiset_impl
, tree_type
>
1373 ( &tree_type::container_from_end_iterator(end_iterator
)
1374 , &avl_multiset_impl::tree_
);
1377 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
1378 //! of avl_multiset.
1380 //! <b>Effects</b>: Returns a const reference to the avl_multiset associated to the end iterator
1382 //! <b>Throws</b>: Nothing.
1384 //! <b>Complexity</b>: Constant.
1385 static const avl_multiset_impl
&container_from_end_iterator(const_iterator end_iterator
)
1387 return *detail::parent_from_member
<avl_multiset_impl
, tree_type
>
1388 ( &tree_type::container_from_end_iterator(end_iterator
)
1389 , &avl_multiset_impl::tree_
);
1392 //! <b>Precondition</b>: it must be a valid iterator of multiset.
1394 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1396 //! <b>Throws</b>: Nothing.
1398 //! <b>Complexity</b>: Logarithmic.
1399 static avl_multiset_impl
&container_from_iterator(iterator it
)
1401 return *detail::parent_from_member
<avl_multiset_impl
, tree_type
>
1402 ( &tree_type::container_from_iterator(it
)
1403 , &avl_multiset_impl::tree_
);
1406 //! <b>Precondition</b>: it must be a valid const_iterator of multiset.
1408 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1410 //! <b>Throws</b>: Nothing.
1412 //! <b>Complexity</b>: Logarithmic.
1413 static const avl_multiset_impl
&container_from_iterator(const_iterator it
)
1415 return *detail::parent_from_member
<avl_multiset_impl
, tree_type
>
1416 ( &tree_type::container_from_iterator(it
)
1417 , &avl_multiset_impl::tree_
);
1420 //! <b>Effects</b>: Returns the key_compare object used by the avl_multiset.
1422 //! <b>Complexity</b>: Constant.
1424 //! <b>Throws</b>: If key_compare copy-constructor throws.
1425 key_compare
key_comp() const
1426 { return tree_
.value_comp(); }
1428 //! <b>Effects</b>: Returns the value_compare object used by the avl_multiset.
1430 //! <b>Complexity</b>: Constant.
1432 //! <b>Throws</b>: If value_compare copy-constructor throws.
1433 value_compare
value_comp() const
1434 { return tree_
.value_comp(); }
1436 //! <b>Effects</b>: Returns true is the container is empty.
1438 //! <b>Complexity</b>: Constant.
1440 //! <b>Throws</b>: Nothing.
1442 { return tree_
.empty(); }
1444 //! <b>Effects</b>: Returns the number of elements stored in the avl_multiset.
1446 //! <b>Complexity</b>: Linear to elements contained in *this if,
1447 //! constant-time size option is enabled. Constant-time otherwise.
1449 //! <b>Throws</b>: Nothing.
1450 size_type
size() const
1451 { return tree_
.size(); }
1453 //! <b>Effects</b>: Swaps the contents of two avl_multisets.
1455 //! <b>Complexity</b>: Constant.
1457 //! <b>Throws</b>: If the swap() call for the comparison functor
1458 //! found using ADL throws. Strong guarantee.
1459 void swap(avl_multiset_impl
& other
)
1460 { tree_
.swap(other
.tree_
); }
1462 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1463 //! Cloner should yield to nodes equivalent to the original nodes.
1465 //! <b>Effects</b>: Erases all the elements from *this
1466 //! calling Disposer::operator()(pointer), clones all the
1467 //! elements from src calling Cloner::operator()(const_reference )
1468 //! and inserts them on *this. Copies the predicate from the source container.
1470 //! If cloner throws, all cloned elements are unlinked and disposed
1471 //! calling Disposer::operator()(pointer).
1473 //! <b>Complexity</b>: Linear to erased plus inserted elements.
1475 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
1476 template <class Cloner
, class Disposer
>
1477 void clone_from(const avl_multiset_impl
&src
, Cloner cloner
, Disposer disposer
)
1478 { tree_
.clone_from(src
.tree_
, cloner
, disposer
); }
1480 //! <b>Requires</b>: value must be an lvalue
1482 //! <b>Effects</b>: Inserts value into the avl_multiset.
1484 //! <b>Returns</b>: An iterator that points to the position where the new
1485 //! element was inserted.
1487 //! <b>Complexity</b>: Average complexity for insert element is at
1488 //! most logarithmic.
1490 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1492 //! <b>Note</b>: Does not affect the validity of iterators and references.
1493 //! No copy-constructors are called.
1494 iterator
insert(reference value
)
1495 { return tree_
.insert_equal(value
); }
1497 //! <b>Requires</b>: value must be an lvalue
1499 //! <b>Effects</b>: Inserts x into the avl_multiset, using pos as a hint to
1500 //! where it will be inserted.
1502 //! <b>Returns</b>: An iterator that points to the position where the new
1503 //! element was inserted.
1505 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
1506 //! constant time if t is inserted immediately before hint.
1508 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1510 //! <b>Note</b>: Does not affect the validity of iterators and references.
1511 //! No copy-constructors are called.
1512 iterator
insert(const_iterator hint
, reference value
)
1513 { return tree_
.insert_equal(hint
, value
); }
1515 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
1516 //! of type value_type.
1518 //! <b>Effects</b>: Inserts a range into the avl_multiset.
1520 //! <b>Returns</b>: An iterator that points to the position where the new
1521 //! element was inserted.
1523 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
1524 //! size of the range. However, it is linear in N if the range is already sorted
1525 //! by value_comp().
1527 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1529 //! <b>Note</b>: Does not affect the validity of iterators and references.
1530 //! No copy-constructors are called.
1531 template<class Iterator
>
1532 void insert(Iterator b
, Iterator e
)
1533 { tree_
.insert_equal(b
, e
); }
1535 //! <b>Effects</b>: Erases the element pointed to by pos.
1537 //! <b>Complexity</b>: Average complexity is constant time.
1539 //! <b>Returns</b>: An iterator to the element after the erased element.
1541 //! <b>Throws</b>: Nothing.
1543 //! <b>Note</b>: Invalidates the iterators (but not the references)
1544 //! to the erased elements. No destructors are called.
1545 iterator
erase(const_iterator i
)
1546 { return tree_
.erase(i
); }
1548 //! <b>Effects</b>: Erases the range pointed to by b end e.
1550 //! <b>Returns</b>: An iterator to the element after the erased elements.
1552 //! <b>Complexity</b>: Average complexity for erase range is at most
1553 //! O(log(size() + N)), where N is the number of elements in the range.
1555 //! <b>Throws</b>: Nothing.
1557 //! <b>Note</b>: Invalidates the iterators (but not the references)
1558 //! to the erased elements. No destructors are called.
1559 iterator
erase(const_iterator b
, const_iterator e
)
1560 { return tree_
.erase(b
, e
); }
1562 //! <b>Effects</b>: Erases all the elements with the given value.
1564 //! <b>Returns</b>: The number of erased elements.
1566 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1568 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1570 //! <b>Note</b>: Invalidates the iterators (but not the references)
1571 //! to the erased elements. No destructors are called.
1572 size_type
erase(const_reference value
)
1573 { return tree_
.erase(value
); }
1575 //! <b>Effects</b>: Erases all the elements that compare equal with
1576 //! the given key and the given comparison functor.
1578 //! <b>Returns</b>: The number of erased elements.
1580 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1582 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1584 //! <b>Note</b>: Invalidates the iterators (but not the references)
1585 //! to the erased elements. No destructors are called.
1586 template<class KeyType
, class KeyValueCompare
>
1587 size_type
erase(const KeyType
& key
, KeyValueCompare comp
1589 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
1592 { return tree_
.erase(key
, comp
); }
1594 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1596 //! <b>Returns</b>: An iterator to the element after the erased element.
1598 //! <b>Effects</b>: Erases the element pointed to by pos.
1599 //! Disposer::operator()(pointer) is called for the removed element.
1601 //! <b>Complexity</b>: Average complexity for erase element is constant time.
1603 //! <b>Throws</b>: Nothing.
1605 //! <b>Note</b>: Invalidates the iterators
1606 //! to the erased elements.
1607 template<class Disposer
>
1608 iterator
erase_and_dispose(const_iterator i
, Disposer disposer
)
1609 { return tree_
.erase_and_dispose(i
, disposer
); }
1611 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1612 template<class Disposer
>
1613 iterator
erase_and_dispose(iterator i
, Disposer disposer
)
1614 { return this->erase_and_dispose(const_iterator(i
), disposer
); }
1617 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1619 //! <b>Returns</b>: An iterator to the element after the erased elements.
1621 //! <b>Effects</b>: Erases the range pointed to by b end e.
1622 //! Disposer::operator()(pointer) is called for the removed elements.
1624 //! <b>Complexity</b>: Average complexity for erase range is at most
1625 //! O(log(size() + N)), where N is the number of elements in the range.
1627 //! <b>Throws</b>: Nothing.
1629 //! <b>Note</b>: Invalidates the iterators
1630 //! to the erased elements.
1631 template<class Disposer
>
1632 iterator
erase_and_dispose(const_iterator b
, const_iterator e
, Disposer disposer
)
1633 { return tree_
.erase_and_dispose(b
, e
, disposer
); }
1635 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1637 //! <b>Effects</b>: Erases all the elements with the given value.
1638 //! Disposer::operator()(pointer) is called for the removed elements.
1640 //! <b>Returns</b>: The number of erased elements.
1642 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1644 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1646 //! <b>Note</b>: Invalidates the iterators (but not the references)
1647 //! to the erased elements. No destructors are called.
1648 template<class Disposer
>
1649 size_type
erase_and_dispose(const_reference value
, Disposer disposer
)
1650 { return tree_
.erase_and_dispose(value
, disposer
); }
1652 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1654 //! <b>Effects</b>: Erases all the elements with the given key.
1655 //! according to the comparison functor "comp".
1656 //! Disposer::operator()(pointer) is called for the removed elements.
1658 //! <b>Returns</b>: The number of erased elements.
1660 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1662 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1664 //! <b>Note</b>: Invalidates the iterators
1665 //! to the erased elements.
1666 template<class KeyType
, class KeyValueCompare
, class Disposer
>
1667 size_type
erase_and_dispose(const KeyType
& key
, KeyValueCompare comp
, Disposer disposer
1669 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
1672 { return tree_
.erase_and_dispose(key
, comp
, disposer
); }
1674 //! <b>Effects</b>: Erases all the elements of the container.
1676 //! <b>Complexity</b>: Linear to the number of elements on the container.
1677 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1679 //! <b>Throws</b>: Nothing.
1681 //! <b>Note</b>: Invalidates the iterators (but not the references)
1682 //! to the erased elements. No destructors are called.
1684 { return tree_
.clear(); }
1686 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1688 //! <b>Effects</b>: Erases all the elements of the container.
1690 //! <b>Complexity</b>: Linear to the number of elements on the container.
1691 //! Disposer::operator()(pointer) is called for the removed elements.
1693 //! <b>Throws</b>: Nothing.
1695 //! <b>Note</b>: Invalidates the iterators (but not the references)
1696 //! to the erased elements. No destructors are called.
1697 template<class Disposer
>
1698 void clear_and_dispose(Disposer disposer
)
1699 { return tree_
.clear_and_dispose(disposer
); }
1701 //! <b>Effects</b>: Returns the number of contained elements with the given key
1703 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1704 //! to number of objects with the given key.
1706 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1707 size_type
count(const_reference value
) const
1708 { return tree_
.count(value
); }
1710 //! <b>Effects</b>: Returns the number of contained elements with the same key
1711 //! compared with the given comparison functor.
1713 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1714 //! to number of objects with the given key.
1716 //! <b>Throws</b>: If comp ordering function throws.
1717 template<class KeyType
, class KeyValueCompare
>
1718 size_type
count(const KeyType
& key
, KeyValueCompare comp
) const
1719 { return tree_
.count(key
, comp
); }
1721 //! <b>Effects</b>: Returns an iterator to the first element whose
1722 //! key is not less than k or end() if that element does not exist.
1724 //! <b>Complexity</b>: Logarithmic.
1726 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1727 iterator
lower_bound(const_reference value
)
1728 { return tree_
.lower_bound(value
); }
1730 //! <b>Requires</b>: comp must imply the same element order as
1731 //! value_compare. Usually key is the part of the value_type
1732 //! that is used in the ordering functor.
1734 //! <b>Effects</b>: Returns an iterator to the first element whose
1735 //! key according to the comparison functor is not less than k or
1736 //! end() if that element does not exist.
1738 //! <b>Complexity</b>: Logarithmic.
1740 //! <b>Throws</b>: If comp ordering function throws.
1742 //! <b>Note</b>: This function is used when constructing a value_type
1743 //! is expensive and the value_type can be compared with a cheaper
1744 //! key type. Usually this key is part of the value_type.
1745 template<class KeyType
, class KeyValueCompare
>
1746 iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
)
1747 { return tree_
.lower_bound(key
, comp
); }
1749 //! <b>Effects</b>: Returns a const iterator to the first element whose
1750 //! key is not less than k or end() if that element does not exist.
1752 //! <b>Complexity</b>: Logarithmic.
1754 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1755 const_iterator
lower_bound(const_reference value
) const
1756 { return tree_
.lower_bound(value
); }
1758 //! <b>Requires</b>: comp must imply the same element order as
1759 //! value_compare. Usually key is the part of the value_type
1760 //! that is used in the ordering functor.
1762 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1763 //! key according to the comparison functor is not less than k or
1764 //! end() if that element does not exist.
1766 //! <b>Complexity</b>: Logarithmic.
1768 //! <b>Throws</b>: If comp ordering function throws.
1770 //! <b>Note</b>: This function is used when constructing a value_type
1771 //! is expensive and the value_type can be compared with a cheaper
1772 //! key type. Usually this key is part of the value_type.
1773 template<class KeyType
, class KeyValueCompare
>
1774 const_iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
) const
1775 { return tree_
.lower_bound(key
, comp
); }
1777 //! <b>Effects</b>: Returns an iterator to the first element whose
1778 //! key is greater than k or end() if that element does not exist.
1780 //! <b>Complexity</b>: Logarithmic.
1782 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1783 iterator
upper_bound(const_reference value
)
1784 { return tree_
.upper_bound(value
); }
1786 //! <b>Requires</b>: comp must imply the same element order as
1787 //! value_compare. Usually key is the part of the value_type
1788 //! that is used in the ordering functor.
1790 //! <b>Effects</b>: Returns an iterator to the first element whose
1791 //! key according to the comparison functor is greater than key or
1792 //! end() if that element does not exist.
1794 //! <b>Complexity</b>: Logarithmic.
1796 //! <b>Throws</b>: If comp ordering function throws.
1798 //! <b>Note</b>: This function is used when constructing a value_type
1799 //! is expensive and the value_type can be compared with a cheaper
1800 //! key type. Usually this key is part of the value_type.
1801 template<class KeyType
, class KeyValueCompare
>
1802 iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
)
1803 { return tree_
.upper_bound(key
, comp
); }
1805 //! <b>Effects</b>: Returns an iterator to the first element whose
1806 //! key is greater than k or end() if that element does not exist.
1808 //! <b>Complexity</b>: Logarithmic.
1810 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1811 const_iterator
upper_bound(const_reference value
) const
1812 { return tree_
.upper_bound(value
); }
1814 //! <b>Requires</b>: comp must imply the same element order as
1815 //! value_compare. Usually key is the part of the value_type
1816 //! that is used in the ordering functor.
1818 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1819 //! key according to the comparison functor is greater than key or
1820 //! end() if that element does not exist.
1822 //! <b>Complexity</b>: Logarithmic.
1824 //! <b>Throws</b>: If comp ordering function throws.
1826 //! <b>Note</b>: This function is used when constructing a value_type
1827 //! is expensive and the value_type can be compared with a cheaper
1828 //! key type. Usually this key is part of the value_type.
1829 template<class KeyType
, class KeyValueCompare
>
1830 const_iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
) const
1831 { return tree_
.upper_bound(key
, comp
); }
1833 //! <b>Effects</b>: Finds an iterator to the first element whose value is
1834 //! "value" or end() if that element does not exist.
1836 //! <b>Complexity</b>: Logarithmic.
1838 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1839 iterator
find(const_reference value
)
1840 { return tree_
.find(value
); }
1842 //! <b>Requires</b>: comp must imply the same element order as
1843 //! value_compare. Usually key is the part of the value_type
1844 //! that is used in the ordering functor.
1846 //! <b>Effects</b>: Finds an iterator to the first element whose key is
1847 //! "key" according to the comparison functor or end() if that element
1850 //! <b>Complexity</b>: Logarithmic.
1852 //! <b>Throws</b>: If comp ordering function throws.
1854 //! <b>Note</b>: This function is used when constructing a value_type
1855 //! is expensive and the value_type can be compared with a cheaper
1856 //! key type. Usually this key is part of the value_type.
1857 template<class KeyType
, class KeyValueCompare
>
1858 iterator
find(const KeyType
& key
, KeyValueCompare comp
)
1859 { return tree_
.find(key
, comp
); }
1861 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
1862 //! "value" or end() if that element does not exist.
1864 //! <b>Complexity</b>: Logarithmic.
1866 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1867 const_iterator
find(const_reference value
) const
1868 { return tree_
.find(value
); }
1870 //! <b>Requires</b>: comp must imply the same element order as
1871 //! value_compare. Usually key is the part of the value_type
1872 //! that is used in the ordering functor.
1874 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
1875 //! "key" according to the comparison functor or end() if that element
1878 //! <b>Complexity</b>: Logarithmic.
1880 //! <b>Throws</b>: If comp ordering function throws.
1882 //! <b>Note</b>: This function is used when constructing a value_type
1883 //! is expensive and the value_type can be compared with a cheaper
1884 //! key type. Usually this key is part of the value_type.
1885 template<class KeyType
, class KeyValueCompare
>
1886 const_iterator
find(const KeyType
& key
, KeyValueCompare comp
) const
1887 { return tree_
.find(key
, comp
); }
1889 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1890 //! an empty range that indicates the position where those elements would be
1891 //! if they there is no elements with key k.
1893 //! <b>Complexity</b>: Logarithmic.
1895 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1896 std::pair
<iterator
,iterator
> equal_range(const_reference value
)
1897 { return tree_
.equal_range(value
); }
1899 //! <b>Requires</b>: comp must imply the same element order as
1900 //! value_compare. Usually key is the part of the value_type
1901 //! that is used in the ordering functor.
1903 //! <b>Effects</b>: Finds a range containing all elements whose key is k
1904 //! according to the comparison functor or an empty range
1905 //! that indicates the position where those elements would be
1906 //! if they there is no elements with key k.
1908 //! <b>Complexity</b>: Logarithmic.
1910 //! <b>Throws</b>: If comp ordering function throws.
1912 //! <b>Note</b>: This function is used when constructing a value_type
1913 //! is expensive and the value_type can be compared with a cheaper
1914 //! key type. Usually this key is part of the value_type.
1915 template<class KeyType
, class KeyValueCompare
>
1916 std::pair
<iterator
,iterator
> equal_range(const KeyType
& key
, KeyValueCompare comp
)
1917 { return tree_
.equal_range(key
, comp
); }
1919 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1920 //! an empty range that indicates the position where those elements would be
1921 //! if they there is no elements with key k.
1923 //! <b>Complexity</b>: Logarithmic.
1925 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1926 std::pair
<const_iterator
, const_iterator
>
1927 equal_range(const_reference value
) const
1928 { return tree_
.equal_range(value
); }
1930 //! <b>Requires</b>: comp must imply the same element order as
1931 //! value_compare. Usually key is the part of the value_type
1932 //! that is used in the ordering functor.
1934 //! <b>Effects</b>: Finds a range containing all elements whose key is k
1935 //! according to the comparison functor or an empty range
1936 //! that indicates the position where those elements would be
1937 //! if they there is no elements with key k.
1939 //! <b>Complexity</b>: Logarithmic.
1941 //! <b>Throws</b>: If comp ordering function throws.
1943 //! <b>Note</b>: This function is used when constructing a value_type
1944 //! is expensive and the value_type can be compared with a cheaper
1945 //! key type. Usually this key is part of the value_type.
1946 template<class KeyType
, class KeyValueCompare
>
1947 std::pair
<const_iterator
, const_iterator
>
1948 equal_range(const KeyType
& key
, KeyValueCompare comp
) const
1949 { return tree_
.equal_range(key
, comp
); }
1951 //! <b>Requires</b>: value must be an lvalue and shall be in a avl_multiset of
1952 //! appropriate type. Otherwise the behavior is undefined.
1954 //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_multiset
1955 //! that points to the value
1957 //! <b>Complexity</b>: Constant.
1959 //! <b>Throws</b>: Nothing.
1961 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
1963 static iterator
s_iterator_to(reference value
)
1964 { return tree_type::s_iterator_to(value
); }
1966 //! <b>Requires</b>: value must be an lvalue and shall be in a avl_multiset of
1967 //! appropriate type. Otherwise the behavior is undefined.
1969 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1970 //! avl_multiset that points to the value
1972 //! <b>Complexity</b>: Constant.
1974 //! <b>Throws</b>: Nothing.
1976 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
1978 static const_iterator
s_iterator_to(const_reference value
)
1979 { return tree_type::s_iterator_to(value
); }
1981 //! <b>Requires</b>: value must be an lvalue and shall be in a avl_multiset of
1982 //! appropriate type. Otherwise the behavior is undefined.
1984 //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_multiset
1985 //! that points to the value
1987 //! <b>Complexity</b>: Constant.
1989 //! <b>Throws</b>: Nothing.
1990 iterator
iterator_to(reference value
)
1991 { return tree_
.iterator_to(value
); }
1993 //! <b>Requires</b>: value must be an lvalue and shall be in a avl_multiset of
1994 //! appropriate type. Otherwise the behavior is undefined.
1996 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1997 //! avl_multiset that points to the value
1999 //! <b>Complexity</b>: Constant.
2001 //! <b>Throws</b>: Nothing.
2002 const_iterator
iterator_to(const_reference value
) const
2003 { return tree_
.iterator_to(value
); }
2005 //! <b>Requires</b>: value shall not be in a avl_multiset/avl_multiset.
2007 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
2010 //! <b>Throws</b>: Nothing.
2012 //! <b>Complexity</b>: Constant time.
2014 //! <b>Note</b>: This function puts the hook in the well-known default state
2015 //! used by auto_unlink and safe hooks.
2016 static void init_node(reference value
)
2017 { tree_type::init_node(value
); }
2019 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
2021 //! <b>Complexity</b>: Average complexity is constant time.
2023 //! <b>Throws</b>: Nothing.
2025 //! <b>Notes</b>: This function breaks the tree and the tree can
2026 //! only be used for more unlink_leftmost_without_rebalance calls.
2027 //! This function is normally used to achieve a step by step
2028 //! controlled destruction of the tree.
2029 pointer
unlink_leftmost_without_rebalance()
2030 { return tree_
.unlink_leftmost_without_rebalance(); }
2032 //! <b>Requires</b>: replace_this must be a valid iterator of *this
2033 //! and with_this must not be inserted in any tree.
2035 //! <b>Effects</b>: Replaces replace_this in its position in the
2036 //! tree with with_this. The tree does not need to be rebalanced.
2038 //! <b>Complexity</b>: Constant.
2040 //! <b>Throws</b>: Nothing.
2042 //! <b>Note</b>: This function will break container ordering invariants if
2043 //! with_this is not equivalent to *replace_this according to the
2044 //! ordering rules. This function is faster than erasing and inserting
2045 //! the node, since no rebalancing or comparison is needed.
2046 void replace_node(iterator replace_this
, reference with_this
)
2047 { tree_
.replace_node(replace_this
, with_this
); }
2050 friend bool operator==(const avl_multiset_impl
&x
, const avl_multiset_impl
&y
)
2051 { return x
.tree_
== y
.tree_
; }
2053 friend bool operator<(const avl_multiset_impl
&x
, const avl_multiset_impl
&y
)
2054 { return x
.tree_
< y
.tree_
; }
2058 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2059 template<class T
, class ...Options
>
2061 template<class Config
>
2063 inline bool operator!=
2064 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2065 (const avl_multiset_impl
<T
, Options
...> &x
, const avl_multiset_impl
<T
, Options
...> &y
)
2067 (const avl_multiset_impl
<Config
> &x
, const avl_multiset_impl
<Config
> &y
)
2069 { return !(x
== y
); }
2071 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2072 template<class T
, class ...Options
>
2074 template<class Config
>
2076 inline bool operator>
2077 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2078 (const avl_multiset_impl
<T
, Options
...> &x
, const avl_multiset_impl
<T
, Options
...> &y
)
2080 (const avl_multiset_impl
<Config
> &x
, const avl_multiset_impl
<Config
> &y
)
2084 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2085 template<class T
, class ...Options
>
2087 template<class Config
>
2089 inline bool operator<=
2090 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2091 (const avl_multiset_impl
<T
, Options
...> &x
, const avl_multiset_impl
<T
, Options
...> &y
)
2093 (const avl_multiset_impl
<Config
> &x
, const avl_multiset_impl
<Config
> &y
)
2095 { return !(y
< x
); }
2097 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2098 template<class T
, class ...Options
>
2100 template<class Config
>
2102 inline bool operator>=
2103 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2104 (const avl_multiset_impl
<T
, Options
...> &x
, const avl_multiset_impl
<T
, Options
...> &y
)
2106 (const avl_multiset_impl
<Config
> &x
, const avl_multiset_impl
<Config
> &y
)
2108 { return !(x
< y
); }
2110 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2111 template<class T
, class ...Options
>
2113 template<class Config
>
2116 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2117 (avl_multiset_impl
<T
, Options
...> &x
, avl_multiset_impl
<T
, Options
...> &y
)
2119 (avl_multiset_impl
<Config
> &x
, avl_multiset_impl
<Config
> &y
)
2123 //! Helper metafunction to define a \c avl_multiset that yields to the same type when the
2124 //! same options (either explicitly or implicitly) are used.
2125 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2126 template<class T
, class ...Options
>
2128 template<class T
, class O1
= none
, class O2
= none
2129 , class O3
= none
, class O4
= none
>
2131 struct make_avl_multiset
2134 typedef avl_multiset_impl
2135 < typename make_avltree_opt
2136 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2142 > implementation_defined
;
2144 typedef implementation_defined type
;
2147 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
2149 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2150 template<class T
, class O1
, class O2
, class O3
, class O4
>
2152 template<class T
, class ...Options
>
2155 : public make_avl_multiset
<T
,
2156 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2163 typedef typename make_avl_multiset
2164 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2172 typedef typename
Base::value_compare value_compare
;
2173 typedef typename
Base::value_traits value_traits
;
2174 typedef typename
Base::iterator iterator
;
2175 typedef typename
Base::const_iterator const_iterator
;
2177 //Assert if passed value traits are compatible with the type
2178 BOOST_STATIC_ASSERT((detail::is_same
<typename
value_traits::value_type
, T
>::value
));
2180 avl_multiset( const value_compare
&cmp
= value_compare()
2181 , const value_traits
&v_traits
= value_traits())
2182 : Base(cmp
, v_traits
)
2185 template<class Iterator
>
2186 avl_multiset( Iterator b
, Iterator e
2187 , const value_compare
&cmp
= value_compare()
2188 , const value_traits
&v_traits
= value_traits())
2189 : Base(b
, e
, cmp
, v_traits
)
2192 static avl_multiset
&container_from_end_iterator(iterator end_iterator
)
2193 { return static_cast<avl_multiset
&>(Base::container_from_end_iterator(end_iterator
)); }
2195 static const avl_multiset
&container_from_end_iterator(const_iterator end_iterator
)
2196 { return static_cast<const avl_multiset
&>(Base::container_from_end_iterator(end_iterator
)); }
2198 static avl_multiset
&container_from_iterator(iterator end_iterator
)
2199 { return static_cast<avl_multiset
&>(Base::container_from_iterator(end_iterator
)); }
2201 static const avl_multiset
&container_from_iterator(const_iterator end_iterator
)
2202 { return static_cast<const avl_multiset
&>(Base::container_from_iterator(end_iterator
)); }
2207 } //namespace intrusive
2210 #include <boost/intrusive/detail/config_end.hpp>
2212 #endif //BOOST_INTRUSIVE_AVL_SET_HPP