fix doc example typo
[boost.git] / boost / intrusive / avl_set.hpp
blob3998f0514a5257fa24e50066d8e1f8cf56fc62ff
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2007-2008
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/intrusive for documentation.
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>
19 #include <iterator>
21 namespace boost {
22 namespace intrusive {
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.
26 //!
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.
30 //!
31 //! The container supports the following options:
32 //! \c base_hook<>/member_hook<>/value_traits<>,
33 //! \c constant_time_size<>, \c size_type<> and
34 //! \c compare<>.
35 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
36 template<class T, class ...Options>
37 #else
38 template<class Config>
39 #endif
40 class avl_set_impl
42 /// @cond
43 typedef avltree_impl<Config> tree_type;
44 //! This class is
45 //! non-copyable
46 avl_set_impl (const avl_set_impl&);
48 //! This class is
49 //! non-assignable
50 avl_set_impl &operator =(const avl_set_impl&);
52 typedef tree_type implementation_defined;
53 /// @endcond
55 public:
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;
77 /// @cond
78 private:
79 tree_type tree_;
80 /// @endcond
82 public:
83 //! <b>Effects</b>: Constructs an empty avl_set.
84 //!
85 //! <b>Complexity</b>: Constant.
86 //!
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.
97 //!
98 //! <b>Effects</b>: Constructs an empty avl_set and inserts elements from
99 //! [b, e).
100 //!
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).
103 //!
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).
116 //!
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.
119 //!
120 //! <b>Throws</b>: Nothing.
121 ~avl_set_impl()
124 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the avl_set.
125 //!
126 //! <b>Complexity</b>: Constant.
127 //!
128 //! <b>Throws</b>: Nothing.
129 iterator begin()
130 { return tree_.begin(); }
132 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the avl_set.
133 //!
134 //! <b>Complexity</b>: Constant.
135 //!
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.
141 //!
142 //! <b>Complexity</b>: Constant.
143 //!
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.
149 //!
150 //! <b>Complexity</b>: Constant.
151 //!
152 //! <b>Throws</b>: Nothing.
153 iterator end()
154 { return tree_.end(); }
156 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the avl_set.
157 //!
158 //! <b>Complexity</b>: Constant.
159 //!
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.
165 //!
166 //! <b>Complexity</b>: Constant.
167 //!
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.
174 //!
175 //! <b>Complexity</b>: Constant.
176 //!
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.
183 //!
184 //! <b>Complexity</b>: Constant.
185 //!
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.
192 //!
193 //! <b>Complexity</b>: Constant.
194 //!
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.
201 //!
202 //! <b>Complexity</b>: Constant.
203 //!
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.
210 //!
211 //! <b>Complexity</b>: Constant.
212 //!
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.
219 //!
220 //! <b>Complexity</b>: Constant.
221 //!
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
227 //! of avl_set.
228 //!
229 //! <b>Effects</b>: Returns a const reference to the avl_set associated to the end iterator
230 //!
231 //! <b>Throws</b>: Nothing.
232 //!
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
242 //! of avl_set.
243 //!
244 //! <b>Effects</b>: Returns a const reference to the set associated to the end iterator
245 //!
246 //! <b>Throws</b>: Nothing.
247 //!
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.
257 //!
258 //! <b>Effects</b>: Returns a reference to the set associated to the iterator
259 //!
260 //! <b>Throws</b>: Nothing.
261 //!
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.
271 //!
272 //! <b>Effects</b>: Returns a const reference to the set associated to the iterator
273 //!
274 //! <b>Throws</b>: Nothing.
275 //!
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.
285 //!
286 //! <b>Complexity</b>: Constant.
287 //!
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.
293 //!
294 //! <b>Complexity</b>: Constant.
295 //!
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.
301 //!
302 //! <b>Complexity</b>: Constant.
303 //!
304 //! <b>Throws</b>: Nothing.
305 bool empty() const
306 { return tree_.empty(); }
308 //! <b>Effects</b>: Returns the number of elements stored in the avl_set.
309 //!
310 //! <b>Complexity</b>: Linear to elements contained in *this if,
311 //! constant-time size option is enabled. Constant-time otherwise.
312 //!
313 //! <b>Throws</b>: Nothing.
314 size_type size() const
315 { return tree_.size(); }
317 //! <b>Effects</b>: Swaps the contents of two sets.
318 //!
319 //! <b>Complexity</b>: Constant.
320 //!
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).
336 //!
337 //! <b>Complexity</b>: Linear to erased plus inserted elements.
338 //!
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
345 //!
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
352 //! and false.
353 //!
354 //! <b>Complexity</b>: Average complexity for insert element is at
355 //! most logarithmic.
356 //!
357 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
358 //!
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
365 //!
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.
371 //!
372 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
373 //! constant time if t is inserted immediately before hint.
374 //!
375 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
376 //!
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.
385 //!
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.
394 //!
395 //! <b>Complexity</b>: Average complexity is at most logarithmic.
397 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
398 //!
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.
420 //!
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.
430 //!
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.
435 //!
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)).
446 //!
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".
459 //!
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.
464 //!
465 //! <b>Complexity</b>: Constant time.
467 //! <b>Throws</b>: Nothing.
468 //!
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.
477 //!
478 //! <b>Effects</b>: Inserts a range into the avl_set.
479 //!
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
482 //! by value_comp().
483 //!
484 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
485 //!
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.
493 //!
494 //! <b>Complexity</b>: Average complexity is constant time.
495 //!
496 //! <b>Returns</b>: An iterator to the element after the erased element.
498 //! <b>Throws</b>: Nothing.
499 //!
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.
506 //!
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.
509 //!
510 //! <b>Returns</b>: An iterator to the element after the erased elements.
511 //!
512 //! <b>Throws</b>: Nothing.
513 //!
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.
520 //!
521 //! <b>Returns</b>: The number of erased elements.
522 //!
523 //! <b>Complexity</b>: O(log(size()) + this->count(value)).
524 //!
525 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
526 //!
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.
534 //!
535 //! <b>Returns</b>: The number of erased elements.
536 //!
537 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
538 //!
539 //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee.
540 //!
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
545 /// @cond
546 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
547 /// @endcond
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.
555 //!
556 //! <b>Complexity</b>: Average complexity for erase element is constant time.
557 //!
558 //! <b>Returns</b>: An iterator to the element after the erased element.
559 //!
560 //! <b>Throws</b>: Nothing.
561 //!
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); }
572 #endif
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.
578 //!
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.
581 //!
582 //! <b>Returns</b>: An iterator to the element after the erased elements.
583 //!
584 //! <b>Throws</b>: Nothing.
585 //!
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.
596 //!
597 //! <b>Throws</b>: If the internal value_compare ordering function throws.
598 //!
599 //! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee.
600 //!
601 //! <b>Throws</b>: Nothing.
602 //!
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.
616 //!
617 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
618 //!
619 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
620 //!
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
625 /// @cond
626 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
627 /// @endcond
629 { return tree_.erase_and_dispose(key, comp, disposer); }
631 //! <b>Effects</b>: Erases all the elements of the container.
632 //!
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.
635 //!
636 //! <b>Throws</b>: Nothing.
637 //!
638 //! <b>Note</b>: Invalidates the iterators (but not the references)
639 //! to the erased elements. No destructors are called.
640 void clear()
641 { return tree_.clear(); }
643 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
644 //!
645 //! <b>Effects</b>: Erases all the elements of the container.
646 //!
647 //! <b>Complexity</b>: Linear to the number of elements on the container.
648 //! Disposer::operator()(pointer) is called for the removed elements.
649 //!
650 //! <b>Throws</b>: Nothing.
651 //!
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
659 //!
660 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
661 //! to number of objects with the given key.
662 //!
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.
669 //!
670 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
671 //! to number of objects with the given key.
672 //!
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.
680 //!
681 //! <b>Complexity</b>: Logarithmic.
682 //!
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.
694 //!
695 //! <b>Complexity</b>: Logarithmic.
696 //!
697 //! <b>Throws</b>: If comp ordering function throws.
698 //!
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.
708 //!
709 //! <b>Complexity</b>: Logarithmic.
710 //!
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.
722 //!
723 //! <b>Complexity</b>: Logarithmic.
724 //!
725 //! <b>Throws</b>: If comp ordering function throws.
726 //!
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.
736 //!
737 //! <b>Complexity</b>: Logarithmic.
738 //!
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.
750 //!
751 //! <b>Complexity</b>: Logarithmic.
752 //!
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.
764 //!
765 //! <b>Complexity</b>: Logarithmic.
766 //!
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.
778 //!
779 //! <b>Complexity</b>: Logarithmic.
780 //!
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.
794 //!
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
805 //! does not exist.
807 //! <b>Complexity</b>: Logarithmic.
808 //!
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.
820 //!
821 //! <b>Complexity</b>: Logarithmic.
822 //!
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
833 //! does not exist.
834 //!
835 //! <b>Complexity</b>: Logarithmic.
836 //!
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.
849 //!
850 //! <b>Complexity</b>: Logarithmic.
851 //!
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.
864 //!
865 //! <b>Complexity</b>: Logarithmic.
866 //!
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.
879 //!
880 //! <b>Complexity</b>: Logarithmic.
881 //!
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.
895 //!
896 //! <b>Complexity</b>: Logarithmic.
897 //!
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.
910 //!
911 //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_set
912 //! that points to the value
913 //!
914 //! <b>Complexity</b>: Constant.
915 //!
916 //! <b>Throws</b>: Nothing.
917 //!
918 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
919 //! is stateless.
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.
925 //!
926 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
927 //! avl_set that points to the value
928 //!
929 //! <b>Complexity</b>: Constant.
930 //!
931 //! <b>Throws</b>: Nothing.
932 //!
933 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
934 //! is stateless.
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.
940 //!
941 //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_set
942 //! that points to the value
943 //!
944 //! <b>Complexity</b>: Constant.
945 //!
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.
952 //!
953 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
954 //! avl_set that points to the value
955 //!
956 //! <b>Complexity</b>: Constant.
957 //!
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.
963 //!
964 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
965 //! state.
966 //!
967 //! <b>Throws</b>: Nothing.
968 //!
969 //! <b>Complexity</b>: Constant time.
970 //!
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.
977 //!
978 //! <b>Complexity</b>: Average complexity is constant time.
979 //!
980 //! <b>Throws</b>: Nothing.
981 //!
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.
991 //!
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.
994 //!
995 //! <b>Complexity</b>: Constant.
996 //!
997 //! <b>Throws</b>: Nothing.
998 //!
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); }
1006 /// @cond
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_; }
1012 /// @endcond
1015 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1016 template<class T, class ...Options>
1017 #else
1018 template<class Config>
1019 #endif
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)
1023 #else
1024 (const avl_set_impl<Config> &x, const avl_set_impl<Config> &y)
1025 #endif
1026 { return !(x == y); }
1028 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1029 template<class T, class ...Options>
1030 #else
1031 template<class Config>
1032 #endif
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)
1036 #else
1037 (const avl_set_impl<Config> &x, const avl_set_impl<Config> &y)
1038 #endif
1039 { return y < x; }
1041 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1042 template<class T, class ...Options>
1043 #else
1044 template<class Config>
1045 #endif
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)
1049 #else
1050 (const avl_set_impl<Config> &x, const avl_set_impl<Config> &y)
1051 #endif
1052 { return !(y < x); }
1054 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1055 template<class T, class ...Options>
1056 #else
1057 template<class Config>
1058 #endif
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)
1062 #else
1063 (const avl_set_impl<Config> &x, const avl_set_impl<Config> &y)
1064 #endif
1065 { return !(x < y); }
1067 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1068 template<class T, class ...Options>
1069 #else
1070 template<class Config>
1071 #endif
1072 inline void swap
1073 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1074 (avl_set_impl<T, Options...> &x, avl_set_impl<T, Options...> &y)
1075 #else
1076 (avl_set_impl<Config> &x, avl_set_impl<Config> &y)
1077 #endif
1078 { x.swap(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>
1084 #else
1085 template<class T, class O1 = none, class O2 = none
1086 , class O3 = none, class O4 = none>
1087 #endif
1088 struct make_avl_set
1090 /// @cond
1091 typedef avl_set_impl
1092 < typename make_avltree_opt
1093 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1094 <T, O1, O2, O3, O4>
1095 #else
1096 <T, Options...>
1097 #endif
1098 ::type
1099 > implementation_defined;
1100 /// @endcond
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>
1108 #else
1109 template<class T, class ...Options>
1110 #endif
1111 class avl_set
1112 : public make_avl_set
1113 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1114 <T, O1, O2, O3, O4>
1115 #else
1116 <T, Options...>
1117 #endif
1118 ::type
1120 typedef typename make_avl_set
1121 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1122 <T, O1, O2, O3, O4>
1123 #else
1124 <T, Options...>
1125 #endif
1126 ::type Base;
1128 public:
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)); }
1162 #endif
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.
1166 //!
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
1174 //! \c compare<>.
1175 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1176 template<class T, class ...Options>
1177 #else
1178 template<class Config>
1179 #endif
1180 class avl_multiset_impl
1182 /// @cond
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;
1189 /// @endcond
1191 public:
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;
1213 /// @cond
1214 private:
1215 tree_type tree_;
1216 /// @endcond
1218 public:
1219 //! <b>Effects</b>: Constructs an empty avl_multiset.
1220 //!
1221 //! <b>Complexity</b>: Constant.
1222 //!
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.
1233 //!
1234 //! <b>Effects</b>: Constructs an empty avl_multiset and inserts elements from
1235 //! [b, e).
1236 //!
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
1239 //!
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).
1252 //!
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.
1255 //!
1256 //! <b>Throws</b>: Nothing.
1257 ~avl_multiset_impl()
1260 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the avl_multiset.
1261 //!
1262 //! <b>Complexity</b>: Constant.
1263 //!
1264 //! <b>Throws</b>: Nothing.
1265 iterator begin()
1266 { return tree_.begin(); }
1268 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the avl_multiset.
1269 //!
1270 //! <b>Complexity</b>: Constant.
1271 //!
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.
1277 //!
1278 //! <b>Complexity</b>: Constant.
1279 //!
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.
1285 //!
1286 //! <b>Complexity</b>: Constant.
1287 //!
1288 //! <b>Throws</b>: Nothing.
1289 iterator end()
1290 { return tree_.end(); }
1292 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the avl_multiset.
1293 //!
1294 //! <b>Complexity</b>: Constant.
1295 //!
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.
1301 //!
1302 //! <b>Complexity</b>: Constant.
1303 //!
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.
1310 //!
1311 //! <b>Complexity</b>: Constant.
1312 //!
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.
1319 //!
1320 //! <b>Complexity</b>: Constant.
1321 //!
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.
1328 //!
1329 //! <b>Complexity</b>: Constant.
1330 //!
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.
1337 //!
1338 //! <b>Complexity</b>: Constant.
1339 //!
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.
1346 //!
1347 //! <b>Complexity</b>: Constant.
1348 //!
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.
1355 //!
1356 //! <b>Complexity</b>: Constant.
1357 //!
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.
1364 //!
1365 //! <b>Effects</b>: Returns a const reference to the avl_multiset associated to the end iterator
1366 //!
1367 //! <b>Throws</b>: Nothing.
1368 //!
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.
1379 //!
1380 //! <b>Effects</b>: Returns a const reference to the avl_multiset associated to the end iterator
1381 //!
1382 //! <b>Throws</b>: Nothing.
1383 //!
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.
1393 //!
1394 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1395 //!
1396 //! <b>Throws</b>: Nothing.
1397 //!
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.
1407 //!
1408 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1409 //!
1410 //! <b>Throws</b>: Nothing.
1411 //!
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.
1421 //!
1422 //! <b>Complexity</b>: Constant.
1423 //!
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.
1429 //!
1430 //! <b>Complexity</b>: Constant.
1431 //!
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.
1437 //!
1438 //! <b>Complexity</b>: Constant.
1439 //!
1440 //! <b>Throws</b>: Nothing.
1441 bool empty() const
1442 { return tree_.empty(); }
1444 //! <b>Effects</b>: Returns the number of elements stored in the avl_multiset.
1445 //!
1446 //! <b>Complexity</b>: Linear to elements contained in *this if,
1447 //! constant-time size option is enabled. Constant-time otherwise.
1448 //!
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.
1454 //!
1455 //! <b>Complexity</b>: Constant.
1456 //!
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).
1472 //!
1473 //! <b>Complexity</b>: Linear to erased plus inserted elements.
1474 //!
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
1481 //!
1482 //! <b>Effects</b>: Inserts value into the avl_multiset.
1483 //!
1484 //! <b>Returns</b>: An iterator that points to the position where the new
1485 //! element was inserted.
1486 //!
1487 //! <b>Complexity</b>: Average complexity for insert element is at
1488 //! most logarithmic.
1489 //!
1490 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1491 //!
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
1498 //!
1499 //! <b>Effects</b>: Inserts x into the avl_multiset, using pos as a hint to
1500 //! where it will be inserted.
1501 //!
1502 //! <b>Returns</b>: An iterator that points to the position where the new
1503 //! element was inserted.
1504 //!
1505 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
1506 //! constant time if t is inserted immediately before hint.
1507 //!
1508 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1509 //!
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.
1517 //!
1518 //! <b>Effects</b>: Inserts a range into the avl_multiset.
1519 //!
1520 //! <b>Returns</b>: An iterator that points to the position where the new
1521 //! element was inserted.
1522 //!
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().
1526 //!
1527 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1528 //!
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.
1536 //!
1537 //! <b>Complexity</b>: Average complexity is constant time.
1538 //!
1539 //! <b>Returns</b>: An iterator to the element after the erased element.
1541 //! <b>Throws</b>: Nothing.
1542 //!
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.
1551 //!
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.
1554 //!
1555 //! <b>Throws</b>: Nothing.
1556 //!
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.
1563 //!
1564 //! <b>Returns</b>: The number of erased elements.
1565 //!
1566 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1567 //!
1568 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1569 //!
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.
1577 //!
1578 //! <b>Returns</b>: The number of erased elements.
1579 //!
1580 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1581 //!
1582 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1583 //!
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
1588 /// @cond
1589 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
1590 /// @endcond
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.
1600 //!
1601 //! <b>Complexity</b>: Average complexity for erase element is constant time.
1602 //!
1603 //! <b>Throws</b>: Nothing.
1604 //!
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); }
1615 #endif
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.
1623 //!
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.
1626 //!
1627 //! <b>Throws</b>: Nothing.
1628 //!
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.
1639 //!
1640 //! <b>Returns</b>: The number of erased elements.
1641 //!
1642 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1643 //!
1644 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1645 //!
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.
1659 //!
1660 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1661 //!
1662 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1663 //!
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
1668 /// @cond
1669 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
1670 /// @endcond
1672 { return tree_.erase_and_dispose(key, comp, disposer); }
1674 //! <b>Effects</b>: Erases all the elements of the container.
1675 //!
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.
1678 //!
1679 //! <b>Throws</b>: Nothing.
1680 //!
1681 //! <b>Note</b>: Invalidates the iterators (but not the references)
1682 //! to the erased elements. No destructors are called.
1683 void clear()
1684 { return tree_.clear(); }
1686 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1687 //!
1688 //! <b>Effects</b>: Erases all the elements of the container.
1689 //!
1690 //! <b>Complexity</b>: Linear to the number of elements on the container.
1691 //! Disposer::operator()(pointer) is called for the removed elements.
1692 //!
1693 //! <b>Throws</b>: Nothing.
1694 //!
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
1702 //!
1703 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1704 //! to number of objects with the given key.
1705 //!
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.
1712 //!
1713 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1714 //! to number of objects with the given key.
1715 //!
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.
1723 //!
1724 //! <b>Complexity</b>: Logarithmic.
1725 //!
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.
1737 //!
1738 //! <b>Complexity</b>: Logarithmic.
1739 //!
1740 //! <b>Throws</b>: If comp ordering function throws.
1741 //!
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.
1751 //!
1752 //! <b>Complexity</b>: Logarithmic.
1753 //!
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.
1765 //!
1766 //! <b>Complexity</b>: Logarithmic.
1767 //!
1768 //! <b>Throws</b>: If comp ordering function throws.
1769 //!
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.
1779 //!
1780 //! <b>Complexity</b>: Logarithmic.
1781 //!
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.
1793 //!
1794 //! <b>Complexity</b>: Logarithmic.
1795 //!
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.
1807 //!
1808 //! <b>Complexity</b>: Logarithmic.
1809 //!
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.
1821 //!
1822 //! <b>Complexity</b>: Logarithmic.
1823 //!
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.
1837 //!
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
1848 //! does not exist.
1850 //! <b>Complexity</b>: Logarithmic.
1851 //!
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.
1863 //!
1864 //! <b>Complexity</b>: Logarithmic.
1865 //!
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
1876 //! does not exist.
1877 //!
1878 //! <b>Complexity</b>: Logarithmic.
1879 //!
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.
1892 //!
1893 //! <b>Complexity</b>: Logarithmic.
1894 //!
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.
1907 //!
1908 //! <b>Complexity</b>: Logarithmic.
1909 //!
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.
1922 //!
1923 //! <b>Complexity</b>: Logarithmic.
1924 //!
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.
1938 //!
1939 //! <b>Complexity</b>: Logarithmic.
1940 //!
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.
1953 //!
1954 //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_multiset
1955 //! that points to the value
1956 //!
1957 //! <b>Complexity</b>: Constant.
1958 //!
1959 //! <b>Throws</b>: Nothing.
1960 //!
1961 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
1962 //! is stateless.
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.
1968 //!
1969 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1970 //! avl_multiset that points to the value
1971 //!
1972 //! <b>Complexity</b>: Constant.
1973 //!
1974 //! <b>Throws</b>: Nothing.
1975 //!
1976 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
1977 //! is stateless.
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.
1983 //!
1984 //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_multiset
1985 //! that points to the value
1986 //!
1987 //! <b>Complexity</b>: Constant.
1988 //!
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.
1995 //!
1996 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1997 //! avl_multiset that points to the value
1998 //!
1999 //! <b>Complexity</b>: Constant.
2000 //!
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.
2006 //!
2007 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
2008 //! state.
2009 //!
2010 //! <b>Throws</b>: Nothing.
2011 //!
2012 //! <b>Complexity</b>: Constant time.
2013 //!
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.
2020 //!
2021 //! <b>Complexity</b>: Average complexity is constant time.
2022 //!
2023 //! <b>Throws</b>: Nothing.
2024 //!
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.
2034 //!
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.
2037 //!
2038 //! <b>Complexity</b>: Constant.
2039 //!
2040 //! <b>Throws</b>: Nothing.
2041 //!
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); }
2049 /// @cond
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_; }
2055 /// @endcond
2058 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2059 template<class T, class ...Options>
2060 #else
2061 template<class Config>
2062 #endif
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)
2066 #else
2067 (const avl_multiset_impl<Config> &x, const avl_multiset_impl<Config> &y)
2068 #endif
2069 { return !(x == y); }
2071 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2072 template<class T, class ...Options>
2073 #else
2074 template<class Config>
2075 #endif
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)
2079 #else
2080 (const avl_multiset_impl<Config> &x, const avl_multiset_impl<Config> &y)
2081 #endif
2082 { return y < x; }
2084 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2085 template<class T, class ...Options>
2086 #else
2087 template<class Config>
2088 #endif
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)
2092 #else
2093 (const avl_multiset_impl<Config> &x, const avl_multiset_impl<Config> &y)
2094 #endif
2095 { return !(y < x); }
2097 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2098 template<class T, class ...Options>
2099 #else
2100 template<class Config>
2101 #endif
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)
2105 #else
2106 (const avl_multiset_impl<Config> &x, const avl_multiset_impl<Config> &y)
2107 #endif
2108 { return !(x < y); }
2110 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2111 template<class T, class ...Options>
2112 #else
2113 template<class Config>
2114 #endif
2115 inline void swap
2116 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2117 (avl_multiset_impl<T, Options...> &x, avl_multiset_impl<T, Options...> &y)
2118 #else
2119 (avl_multiset_impl<Config> &x, avl_multiset_impl<Config> &y)
2120 #endif
2121 { x.swap(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>
2127 #else
2128 template<class T, class O1 = none, class O2 = none
2129 , class O3 = none, class O4 = none>
2130 #endif
2131 struct make_avl_multiset
2133 /// @cond
2134 typedef avl_multiset_impl
2135 < typename make_avltree_opt
2136 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2137 <T, O1, O2, O3, O4>
2138 #else
2139 <T, Options...>
2140 #endif
2141 ::type
2142 > implementation_defined;
2143 /// @endcond
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>
2151 #else
2152 template<class T, class ...Options>
2153 #endif
2154 class avl_multiset
2155 : public make_avl_multiset<T,
2156 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2157 O1, O2, O3, O4
2158 #else
2159 Options...
2160 #endif
2161 >::type
2163 typedef typename make_avl_multiset
2164 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2165 <T, O1, O2, O3, O4>
2166 #else
2167 <T, Options...>
2168 #endif
2169 ::type Base;
2171 public:
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)); }
2205 #endif
2207 } //namespace intrusive
2208 } //namespace boost
2210 #include <boost/intrusive/detail/config_end.hpp>
2212 #endif //BOOST_INTRUSIVE_AVL_SET_HPP