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_SG_SET_HPP
13 #define BOOST_INTRUSIVE_SG_SET_HPP
15 #include <boost/intrusive/detail/config_begin.hpp>
16 #include <boost/intrusive/intrusive_fwd.hpp>
17 #include <boost/intrusive/sgtree.hpp>
18 #include <boost/intrusive/detail/mpl.hpp>
24 //! The class template sg_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 sgtree_impl
<Config
> tree_type
;
46 sg_set_impl (const sg_set_impl
&);
50 sg_set_impl
&operator =(const sg_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 sg_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 sg_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 sg_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 sg_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 sg_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 sg_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 sg_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 sg_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 sg_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 sg_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 sg_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
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 sg_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 sg_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 sg_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 sg_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 sg_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 sg_set associated to the end iterator
231 //! <b>Throws</b>: Nothing.
233 //! <b>Complexity</b>: Constant.
234 static sg_set_impl
&container_from_end_iterator(iterator end_iterator
)
236 return *detail::parent_from_member
<sg_set_impl
, tree_type
>
237 ( &tree_type::container_from_end_iterator(end_iterator
)
238 , &sg_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 sg_set associated to the end iterator
246 //! <b>Throws</b>: Nothing.
248 //! <b>Complexity</b>: Constant.
249 static const sg_set_impl
&container_from_end_iterator(const_iterator end_iterator
)
251 return *detail::parent_from_member
<sg_set_impl
, tree_type
>
252 ( &tree_type::container_from_end_iterator(end_iterator
)
253 , &sg_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 sg_set_impl
&container_from_iterator(iterator it
)
265 return *detail::parent_from_member
<sg_set_impl
, tree_type
>
266 ( &tree_type::container_from_iterator(it
)
267 , &sg_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 sg_set_impl
&container_from_iterator(const_iterator it
)
279 return *detail::parent_from_member
<sg_set_impl
, tree_type
>
280 ( &tree_type::container_from_iterator(it
)
281 , &sg_set_impl::tree_
);
284 //! <b>Effects</b>: Returns the key_compare object used by the sg_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 sg_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 if 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 sg_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(sg_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 sg_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>: Tries to inserts value into the sg_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>: Tries to to insert x into the sg_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 sg_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 ascapegoatitrary key with the contained values.
386 //! <b>Effects</b>: Checks if a value can be inserted in the sg_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 sg_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 ascapegoatitrary key with the contained values.
421 //! <b>Effects</b>: Checks if a value can be inserted in the sg_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 sg_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 sg_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 sg_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 sg_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 sg_set of
909 //! appropriate type. Otherwise the behavior is undefined.
911 //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_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 sg_set of
924 //! appropriate type. Otherwise the behavior is undefined.
926 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
927 //! sg_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 sg_set of
939 //! appropriate type. Otherwise the behavior is undefined.
941 //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_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 sg_set of
951 //! appropriate type. Otherwise the behavior is undefined.
953 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
954 //! sg_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 sg_set/sg_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
); }
1006 //! <b>Effects</b>: Rebalances the tree.
1008 //! <b>Throws</b>: Nothing.
1010 //! <b>Complexity</b>: Linear.
1012 { tree_
.rebalance(); }
1014 //! <b>Requires</b>: old_root is a node of a tree.
1016 //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
1018 //! <b>Returns</b>: The new root of the subtree.
1020 //! <b>Throws</b>: Nothing.
1022 //! <b>Complexity</b>: Linear to the elements in the subtree.
1023 iterator
rebalance_subtree(iterator root
)
1024 { return tree_
.rebalance_subtree(root
); }
1026 //! <b>Returns</b>: The balance factor (alpha) used in this tree
1028 //! <b>Throws</b>: Nothing.
1030 //! <b>Complexity</b>: Constant.
1031 float balance_factor() const
1032 { return tree_
.balance_factor(); }
1034 //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
1036 //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
1037 //! the tree if the new balance factor is stricter (less) than the old factor.
1039 //! <b>Throws</b>: Nothing.
1041 //! <b>Complexity</b>: Linear to the elements in the subtree.
1042 void balance_factor(float new_alpha
)
1043 { tree_
.balance_factor(new_alpha
); }
1046 friend bool operator==(const sg_set_impl
&x
, const sg_set_impl
&y
)
1047 { return x
.tree_
== y
.tree_
; }
1049 friend bool operator<(const sg_set_impl
&x
, const sg_set_impl
&y
)
1050 { return x
.tree_
< y
.tree_
; }
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 sg_set_impl
<T
, Options
...> &x
, const sg_set_impl
<T
, Options
...> &y
)
1063 (const sg_set_impl
<Config
> &x
, const sg_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
>
1072 inline bool operator>
1073 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1074 (const sg_set_impl
<T
, Options
...> &x
, const sg_set_impl
<T
, Options
...> &y
)
1076 (const sg_set_impl
<Config
> &x
, const sg_set_impl
<Config
> &y
)
1080 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1081 template<class T
, class ...Options
>
1083 template<class Config
>
1085 inline bool operator<=
1086 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1087 (const sg_set_impl
<T
, Options
...> &x
, const sg_set_impl
<T
, Options
...> &y
)
1089 (const sg_set_impl
<Config
> &x
, const sg_set_impl
<Config
> &y
)
1091 { return !(y
< x
); }
1093 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1094 template<class T
, class ...Options
>
1096 template<class Config
>
1098 inline bool operator>=
1099 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1100 (const sg_set_impl
<T
, Options
...> &x
, const sg_set_impl
<T
, Options
...> &y
)
1102 (const sg_set_impl
<Config
> &x
, const sg_set_impl
<Config
> &y
)
1104 { return !(x
< y
); }
1106 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1107 template<class T
, class ...Options
>
1109 template<class Config
>
1112 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1113 (sg_set_impl
<T
, Options
...> &x
, sg_set_impl
<T
, Options
...> &y
)
1115 (sg_set_impl
<Config
> &x
, sg_set_impl
<Config
> &y
)
1119 //! Helper metafunction to define a \c sg_set that yields to the same type when the
1120 //! same options (either explicitly or implicitly) are used.
1121 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1122 template<class T
, class ...Options
>
1124 template<class T
, class O1
= none
, class O2
= none
1125 , class O3
= none
, class O4
= none
>
1131 < typename make_sgtree_opt
<T
,
1132 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1138 > implementation_defined
;
1140 typedef implementation_defined type
;
1143 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1145 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1146 template<class T
, class O1
, class O2
, class O3
, class O4
>
1148 template<class T
, class ...Options
>
1151 : public make_sg_set
<T
,
1152 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1159 typedef typename make_sg_set
1161 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1169 typedef typename
Base::value_compare value_compare
;
1170 typedef typename
Base::value_traits value_traits
;
1171 typedef typename
Base::iterator iterator
;
1172 typedef typename
Base::const_iterator const_iterator
;
1174 //Assert if passed value traits are compatible with the type
1175 BOOST_STATIC_ASSERT((detail::is_same
<typename
value_traits::value_type
, T
>::value
));
1177 sg_set( const value_compare
&cmp
= value_compare()
1178 , const value_traits
&v_traits
= value_traits())
1179 : Base(cmp
, v_traits
)
1182 template<class Iterator
>
1183 sg_set( Iterator b
, Iterator e
1184 , const value_compare
&cmp
= value_compare()
1185 , const value_traits
&v_traits
= value_traits())
1186 : Base(b
, e
, cmp
, v_traits
)
1189 static sg_set
&container_from_end_iterator(iterator end_iterator
)
1190 { return static_cast<sg_set
&>(Base::container_from_end_iterator(end_iterator
)); }
1192 static const sg_set
&container_from_end_iterator(const_iterator end_iterator
)
1193 { return static_cast<const sg_set
&>(Base::container_from_end_iterator(end_iterator
)); }
1195 static sg_set
&container_from_iterator(iterator it
)
1196 { return static_cast<sg_set
&>(Base::container_from_iterator(it
)); }
1198 static const sg_set
&container_from_iterator(const_iterator it
)
1199 { return static_cast<const sg_set
&>(Base::container_from_iterator(it
)); }
1204 //! The class template sg_multiset is an intrusive container, that mimics most of
1205 //! the interface of std::sg_multiset as described in the C++ standard.
1207 //! The template parameter \c T is the type to be managed by the container.
1208 //! The user can specify additional options and if no options are provided
1209 //! default options are used.
1211 //! The container supports the following options:
1212 //! \c base_hook<>/member_hook<>/value_traits<>,
1213 //! \c constant_time_size<>, \c size_type<> and
1215 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1216 template<class T
, class ...Options
>
1218 template<class Config
>
1220 class sg_multiset_impl
1223 typedef sgtree_impl
<Config
> tree_type
;
1225 //Non-copyable and non-assignable
1226 sg_multiset_impl (const sg_multiset_impl
&);
1227 sg_multiset_impl
&operator =(const sg_multiset_impl
&);
1228 typedef tree_type implementation_defined
;
1232 typedef typename
implementation_defined::value_type value_type
;
1233 typedef typename
implementation_defined::value_traits value_traits
;
1234 typedef typename
implementation_defined::pointer pointer
;
1235 typedef typename
implementation_defined::const_pointer const_pointer
;
1236 typedef typename
implementation_defined::reference reference
;
1237 typedef typename
implementation_defined::const_reference const_reference
;
1238 typedef typename
implementation_defined::difference_type difference_type
;
1239 typedef typename
implementation_defined::size_type size_type
;
1240 typedef typename
implementation_defined::value_compare value_compare
;
1241 typedef typename
implementation_defined::key_compare key_compare
;
1242 typedef typename
implementation_defined::iterator iterator
;
1243 typedef typename
implementation_defined::const_iterator const_iterator
;
1244 typedef typename
implementation_defined::reverse_iterator reverse_iterator
;
1245 typedef typename
implementation_defined::const_reverse_iterator const_reverse_iterator
;
1246 typedef typename
implementation_defined::insert_commit_data insert_commit_data
;
1247 typedef typename
implementation_defined::node_traits node_traits
;
1248 typedef typename
implementation_defined::node node
;
1249 typedef typename
implementation_defined::node_ptr node_ptr
;
1250 typedef typename
implementation_defined::const_node_ptr const_node_ptr
;
1251 typedef typename
implementation_defined::node_algorithms node_algorithms
;
1259 //! <b>Effects</b>: Constructs an empty sg_multiset.
1261 //! <b>Complexity</b>: Constant.
1263 //! <b>Throws</b>: If value_traits::node_traits::node
1264 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1265 //! or the copy constructor/operator() of the value_compare object throws.
1266 sg_multiset_impl( const value_compare
&cmp
= value_compare()
1267 , const value_traits
&v_traits
= value_traits())
1268 : tree_(cmp
, v_traits
)
1271 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
1272 //! cmp must be a comparison function that induces a strict weak ordering.
1274 //! <b>Effects</b>: Constructs an empty sg_multiset and inserts elements from
1277 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
1278 //! comp and otherwise N * log N, where N is the distance between first and last
1280 //! <b>Throws</b>: If value_traits::node_traits::node
1281 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1282 //! or the copy constructor/operator() of the value_compare object throws.
1283 template<class Iterator
>
1284 sg_multiset_impl( Iterator b
, Iterator e
1285 , const value_compare
&cmp
= value_compare()
1286 , const value_traits
&v_traits
= value_traits())
1287 : tree_(false, b
, e
, cmp
, v_traits
)
1290 //! <b>Effects</b>: Detaches all elements from this. The objects in the sg_multiset
1291 //! are not deleted (i.e. no destructors are called).
1293 //! <b>Complexity</b>: Linear to the number of elements on the container.
1294 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1296 //! <b>Throws</b>: Nothing.
1300 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the sg_multiset.
1302 //! <b>Complexity</b>: Constant.
1304 //! <b>Throws</b>: Nothing.
1306 { return tree_
.begin(); }
1308 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_multiset.
1310 //! <b>Complexity</b>: Constant.
1312 //! <b>Throws</b>: Nothing.
1313 const_iterator
begin() const
1314 { return tree_
.begin(); }
1316 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_multiset.
1318 //! <b>Complexity</b>: Constant.
1320 //! <b>Throws</b>: Nothing.
1321 const_iterator
cbegin() const
1322 { return tree_
.cbegin(); }
1324 //! <b>Effects</b>: Returns an iterator pointing to the end of the sg_multiset.
1326 //! <b>Complexity</b>: Constant.
1328 //! <b>Throws</b>: Nothing.
1330 { return tree_
.end(); }
1332 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_multiset.
1334 //! <b>Complexity</b>: Constant.
1336 //! <b>Throws</b>: Nothing.
1337 const_iterator
end() const
1338 { return tree_
.end(); }
1340 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_multiset.
1342 //! <b>Complexity</b>: Constant.
1344 //! <b>Throws</b>: Nothing.
1345 const_iterator
cend() const
1346 { return tree_
.cend(); }
1348 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
1349 //! reversed sg_multiset.
1351 //! <b>Complexity</b>: Constant.
1353 //! <b>Throws</b>: Nothing.
1354 reverse_iterator
rbegin()
1355 { return tree_
.rbegin(); }
1357 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1358 //! of the reversed sg_multiset.
1360 //! <b>Complexity</b>: Constant.
1362 //! <b>Throws</b>: Nothing.
1363 const_reverse_iterator
rbegin() const
1364 { return tree_
.rbegin(); }
1366 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1367 //! of the reversed sg_multiset.
1369 //! <b>Complexity</b>: Constant.
1371 //! <b>Throws</b>: Nothing.
1372 const_reverse_iterator
crbegin() const
1373 { return tree_
.crbegin(); }
1375 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
1376 //! of the reversed sg_multiset.
1378 //! <b>Complexity</b>: Constant.
1380 //! <b>Throws</b>: Nothing.
1381 reverse_iterator
rend()
1382 { return tree_
.rend(); }
1384 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1385 //! of the reversed sg_multiset.
1387 //! <b>Complexity</b>: Constant.
1389 //! <b>Throws</b>: Nothing.
1390 const_reverse_iterator
rend() const
1391 { return tree_
.rend(); }
1393 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1394 //! of the reversed sg_multiset.
1396 //! <b>Complexity</b>: Constant.
1398 //! <b>Throws</b>: Nothing.
1399 const_reverse_iterator
crend() const
1400 { return tree_
.crend(); }
1402 //! <b>Precondition</b>: end_iterator must be a valid end iterator
1405 //! <b>Effects</b>: Returns a const reference to the sg_multiset associated to the end iterator
1407 //! <b>Throws</b>: Nothing.
1409 //! <b>Complexity</b>: Constant.
1410 static sg_multiset_impl
&container_from_end_iterator(iterator end_iterator
)
1412 return *detail::parent_from_member
<sg_multiset_impl
, tree_type
>
1413 ( &tree_type::container_from_end_iterator(end_iterator
)
1414 , &sg_multiset_impl::tree_
);
1417 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
1420 //! <b>Effects</b>: Returns a const reference to the sg_multiset associated to the end iterator
1422 //! <b>Throws</b>: Nothing.
1424 //! <b>Complexity</b>: Constant.
1425 static const sg_multiset_impl
&container_from_end_iterator(const_iterator end_iterator
)
1427 return *detail::parent_from_member
<sg_multiset_impl
, tree_type
>
1428 ( &tree_type::container_from_end_iterator(end_iterator
)
1429 , &sg_multiset_impl::tree_
);
1432 //! <b>Precondition</b>: it must be a valid iterator of multiset.
1434 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1436 //! <b>Throws</b>: Nothing.
1438 //! <b>Complexity</b>: Constant.
1439 static sg_multiset_impl
&container_from_iterator(iterator it
)
1441 return *detail::parent_from_member
<sg_multiset_impl
, tree_type
>
1442 ( &tree_type::container_from_iterator(it
)
1443 , &sg_multiset_impl::tree_
);
1446 //! <b>Precondition</b>: it must be a valid const_iterator of multiset.
1448 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1450 //! <b>Throws</b>: Nothing.
1452 //! <b>Complexity</b>: Constant.
1453 static const sg_multiset_impl
&container_from_iterator(const_iterator it
)
1455 return *detail::parent_from_member
<sg_multiset_impl
, tree_type
>
1456 ( &tree_type::container_from_iterator(it
)
1457 , &sg_multiset_impl::tree_
);
1460 //! <b>Effects</b>: Returns the key_compare object used by the sg_multiset.
1462 //! <b>Complexity</b>: Constant.
1464 //! <b>Throws</b>: If key_compare copy-constructor throws.
1465 key_compare
key_comp() const
1466 { return tree_
.value_comp(); }
1468 //! <b>Effects</b>: Returns the value_compare object used by the sg_multiset.
1470 //! <b>Complexity</b>: Constant.
1472 //! <b>Throws</b>: If value_compare copy-constructor throws.
1473 value_compare
value_comp() const
1474 { return tree_
.value_comp(); }
1476 //! <b>Effects</b>: Returns true if the container is empty.
1478 //! <b>Complexity</b>: Constant.
1480 //! <b>Throws</b>: Nothing.
1482 { return tree_
.empty(); }
1484 //! <b>Effects</b>: Returns the number of elements stored in the sg_multiset.
1486 //! <b>Complexity</b>: Linear to elements contained in *this if,
1487 //! constant-time size option is enabled. Constant-time otherwise.
1489 //! <b>Throws</b>: Nothing.
1490 size_type
size() const
1491 { return tree_
.size(); }
1493 //! <b>Effects</b>: Swaps the contents of two sg_multisets.
1495 //! <b>Complexity</b>: Constant.
1497 //! <b>Throws</b>: If the swap() call for the comparison functor
1498 //! found using ADL throws. Strong guarantee.
1499 void swap(sg_multiset_impl
& other
)
1500 { tree_
.swap(other
.tree_
); }
1502 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1503 //! Cloner should yield to nodes equivalent to the original nodes.
1505 //! <b>Effects</b>: Erases all the elements from *this
1506 //! calling Disposer::operator()(pointer), clones all the
1507 //! elements from src calling Cloner::operator()(const_reference )
1508 //! and inserts them on *this. Copies the predicate from the source container.
1510 //! If cloner throws, all cloned elements are unlinked and disposed
1511 //! calling Disposer::operator()(pointer).
1513 //! <b>Complexity</b>: Linear to erased plus inserted elements.
1515 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
1516 template <class Cloner
, class Disposer
>
1517 void clone_from(const sg_multiset_impl
&src
, Cloner cloner
, Disposer disposer
)
1518 { tree_
.clone_from(src
.tree_
, cloner
, disposer
); }
1520 //! <b>Requires</b>: value must be an lvalue
1522 //! <b>Effects</b>: Inserts value into the sg_multiset.
1524 //! <b>Returns</b>: An iterator that points to the position where the new
1525 //! element was inserted.
1527 //! <b>Complexity</b>: Average complexity for insert element is at
1528 //! most logarithmic.
1530 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1532 //! <b>Note</b>: Does not affect the validity of iterators and references.
1533 //! No copy-constructors are called.
1534 iterator
insert(reference value
)
1535 { return tree_
.insert_equal(value
); }
1537 //! <b>Requires</b>: value must be an lvalue
1539 //! <b>Effects</b>: Inserts x into the sg_multiset, using pos as a hint to
1540 //! where it will be inserted.
1542 //! <b>Returns</b>: An iterator that points to the position where the new
1543 //! element was inserted.
1545 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
1546 //! constant time if t is inserted immediately before hint.
1548 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1550 //! <b>Note</b>: Does not affect the validity of iterators and references.
1551 //! No copy-constructors are called.
1552 iterator
insert(const_iterator hint
, reference value
)
1553 { return tree_
.insert_equal(hint
, value
); }
1555 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
1556 //! of type value_type.
1558 //! <b>Effects</b>: Inserts a range into the sg_multiset.
1560 //! <b>Returns</b>: An iterator that points to the position where the new
1561 //! element was inserted.
1563 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
1564 //! size of the range. However, it is linear in N if the range is already sorted
1565 //! by value_comp().
1567 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1569 //! <b>Note</b>: Does not affect the validity of iterators and references.
1570 //! No copy-constructors are called.
1571 template<class Iterator
>
1572 void insert(Iterator b
, Iterator e
)
1573 { tree_
.insert_equal(b
, e
); }
1575 //! <b>Effects</b>: Erases the element pointed to by pos.
1577 //! <b>Complexity</b>: Average complexity is constant time.
1579 //! <b>Returns</b>: An iterator to the element after the erased element.
1581 //! <b>Throws</b>: Nothing.
1583 //! <b>Note</b>: Invalidates the iterators (but not the references)
1584 //! to the erased elements. No destructors are called.
1585 iterator
erase(const_iterator i
)
1586 { return tree_
.erase(i
); }
1588 //! <b>Effects</b>: Erases the range pointed to by b end e.
1590 //! <b>Returns</b>: An iterator to the element after the erased elements.
1592 //! <b>Complexity</b>: Average complexity for erase range is at most
1593 //! O(log(size() + N)), where N is the number of elements in the range.
1595 //! <b>Throws</b>: Nothing.
1597 //! <b>Note</b>: Invalidates the iterators (but not the references)
1598 //! to the erased elements. No destructors are called.
1599 iterator
erase(const_iterator b
, const_iterator e
)
1600 { return tree_
.erase(b
, e
); }
1602 //! <b>Effects</b>: Erases all the elements with the given value.
1604 //! <b>Returns</b>: The number of erased elements.
1606 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1608 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1610 //! <b>Note</b>: Invalidates the iterators (but not the references)
1611 //! to the erased elements. No destructors are called.
1612 size_type
erase(const_reference value
)
1613 { return tree_
.erase(value
); }
1615 //! <b>Effects</b>: Erases all the elements that compare equal with
1616 //! the given key and the given comparison functor.
1618 //! <b>Returns</b>: The number of erased elements.
1620 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1622 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1624 //! <b>Note</b>: Invalidates the iterators (but not the references)
1625 //! to the erased elements. No destructors are called.
1626 template<class KeyType
, class KeyValueCompare
>
1627 size_type
erase(const KeyType
& key
, KeyValueCompare comp
1629 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
1632 { return tree_
.erase(key
, comp
); }
1634 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1636 //! <b>Returns</b>: An iterator to the element after the erased element.
1638 //! <b>Effects</b>: Erases the element pointed to by pos.
1639 //! Disposer::operator()(pointer) is called for the removed element.
1641 //! <b>Complexity</b>: Average complexity for erase element is constant time.
1643 //! <b>Throws</b>: Nothing.
1645 //! <b>Note</b>: Invalidates the iterators
1646 //! to the erased elements.
1647 template<class Disposer
>
1648 iterator
erase_and_dispose(const_iterator i
, Disposer disposer
)
1649 { return tree_
.erase_and_dispose(i
, disposer
); }
1651 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1652 template<class Disposer
>
1653 iterator
erase_and_dispose(iterator i
, Disposer disposer
)
1654 { return this->erase_and_dispose(const_iterator(i
), disposer
); }
1657 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1659 //! <b>Returns</b>: An iterator to the element after the erased elements.
1661 //! <b>Effects</b>: Erases the range pointed to by b end e.
1662 //! Disposer::operator()(pointer) is called for the removed elements.
1664 //! <b>Complexity</b>: Average complexity for erase range is at most
1665 //! O(log(size() + N)), where N is the number of elements in the range.
1667 //! <b>Throws</b>: Nothing.
1669 //! <b>Note</b>: Invalidates the iterators
1670 //! to the erased elements.
1671 template<class Disposer
>
1672 iterator
erase_and_dispose(const_iterator b
, const_iterator e
, Disposer disposer
)
1673 { return tree_
.erase_and_dispose(b
, e
, disposer
); }
1675 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1677 //! <b>Effects</b>: Erases all the elements with the given value.
1678 //! Disposer::operator()(pointer) is called for the removed elements.
1680 //! <b>Returns</b>: The number of erased elements.
1682 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1684 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1686 //! <b>Note</b>: Invalidates the iterators (but not the references)
1687 //! to the erased elements. No destructors are called.
1688 template<class Disposer
>
1689 size_type
erase_and_dispose(const_reference value
, Disposer disposer
)
1690 { return tree_
.erase_and_dispose(value
, disposer
); }
1692 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1694 //! <b>Effects</b>: Erases all the elements with the given key.
1695 //! according to the comparison functor "comp".
1696 //! Disposer::operator()(pointer) is called for the removed elements.
1698 //! <b>Returns</b>: The number of erased elements.
1700 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1702 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1704 //! <b>Note</b>: Invalidates the iterators
1705 //! to the erased elements.
1706 template<class KeyType
, class KeyValueCompare
, class Disposer
>
1707 size_type
erase_and_dispose(const KeyType
& key
, KeyValueCompare comp
, Disposer disposer
1709 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
1712 { return tree_
.erase_and_dispose(key
, comp
, disposer
); }
1714 //! <b>Effects</b>: Erases all the elements of the container.
1716 //! <b>Complexity</b>: Linear to the number of elements on the container.
1717 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1719 //! <b>Throws</b>: Nothing.
1721 //! <b>Note</b>: Invalidates the iterators (but not the references)
1722 //! to the erased elements. No destructors are called.
1724 { return tree_
.clear(); }
1726 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1728 //! <b>Effects</b>: Erases all the elements of the container.
1730 //! <b>Complexity</b>: Linear to the number of elements on the container.
1731 //! Disposer::operator()(pointer) is called for the removed elements.
1733 //! <b>Throws</b>: Nothing.
1735 //! <b>Note</b>: Invalidates the iterators (but not the references)
1736 //! to the erased elements. No destructors are called.
1737 template<class Disposer
>
1738 void clear_and_dispose(Disposer disposer
)
1739 { return tree_
.clear_and_dispose(disposer
); }
1741 //! <b>Effects</b>: Returns the number of contained elements with the given key
1743 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1744 //! to number of objects with the given key.
1746 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1747 size_type
count(const_reference value
) const
1748 { return tree_
.count(value
); }
1750 //! <b>Effects</b>: Returns the number of contained elements with the same key
1751 //! compared with the given comparison functor.
1753 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1754 //! to number of objects with the given key.
1756 //! <b>Throws</b>: If comp ordering function throws.
1757 template<class KeyType
, class KeyValueCompare
>
1758 size_type
count(const KeyType
& key
, KeyValueCompare comp
) const
1759 { return tree_
.count(key
, comp
); }
1761 //! <b>Effects</b>: Returns an iterator to the first element whose
1762 //! key is not less than k or end() if that element does not exist.
1764 //! <b>Complexity</b>: Logarithmic.
1766 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1767 iterator
lower_bound(const_reference value
)
1768 { return tree_
.lower_bound(value
); }
1770 //! <b>Requires</b>: comp must imply the same element order as
1771 //! value_compare. Usually key is the part of the value_type
1772 //! that is used in the ordering functor.
1774 //! <b>Effects</b>: Returns an iterator to the first element whose
1775 //! key according to the comparison functor is not less than k or
1776 //! end() if that element does not exist.
1778 //! <b>Complexity</b>: Logarithmic.
1780 //! <b>Throws</b>: If comp ordering function throws.
1782 //! <b>Note</b>: This function is used when constructing a value_type
1783 //! is expensive and the value_type can be compared with a cheaper
1784 //! key type. Usually this key is part of the value_type.
1785 template<class KeyType
, class KeyValueCompare
>
1786 iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
)
1787 { return tree_
.lower_bound(key
, comp
); }
1789 //! <b>Effects</b>: Returns a const iterator to the first element whose
1790 //! key is not less than k or end() if that element does not exist.
1792 //! <b>Complexity</b>: Logarithmic.
1794 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1795 const_iterator
lower_bound(const_reference value
) const
1796 { return tree_
.lower_bound(value
); }
1798 //! <b>Requires</b>: comp must imply the same element order as
1799 //! value_compare. Usually key is the part of the value_type
1800 //! that is used in the ordering functor.
1802 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1803 //! key according to the comparison functor is not less than k or
1804 //! end() if that element does not exist.
1806 //! <b>Complexity</b>: Logarithmic.
1808 //! <b>Throws</b>: If comp ordering function throws.
1810 //! <b>Note</b>: This function is used when constructing a value_type
1811 //! is expensive and the value_type can be compared with a cheaper
1812 //! key type. Usually this key is part of the value_type.
1813 template<class KeyType
, class KeyValueCompare
>
1814 const_iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
) const
1815 { return tree_
.lower_bound(key
, comp
); }
1817 //! <b>Effects</b>: Returns an iterator to the first element whose
1818 //! key is greater than k or end() if that element does not exist.
1820 //! <b>Complexity</b>: Logarithmic.
1822 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1823 iterator
upper_bound(const_reference value
)
1824 { return tree_
.upper_bound(value
); }
1826 //! <b>Requires</b>: comp must imply the same element order as
1827 //! value_compare. Usually key is the part of the value_type
1828 //! that is used in the ordering functor.
1830 //! <b>Effects</b>: Returns an iterator to the first element whose
1831 //! key according to the comparison functor is greater than key or
1832 //! end() if that element does not exist.
1834 //! <b>Complexity</b>: Logarithmic.
1836 //! <b>Throws</b>: If comp ordering function throws.
1838 //! <b>Note</b>: This function is used when constructing a value_type
1839 //! is expensive and the value_type can be compared with a cheaper
1840 //! key type. Usually this key is part of the value_type.
1841 template<class KeyType
, class KeyValueCompare
>
1842 iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
)
1843 { return tree_
.upper_bound(key
, comp
); }
1845 //! <b>Effects</b>: Returns an iterator to the first element whose
1846 //! key is greater than k or end() if that element does not exist.
1848 //! <b>Complexity</b>: Logarithmic.
1850 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1851 const_iterator
upper_bound(const_reference value
) const
1852 { return tree_
.upper_bound(value
); }
1854 //! <b>Requires</b>: comp must imply the same element order as
1855 //! value_compare. Usually key is the part of the value_type
1856 //! that is used in the ordering functor.
1858 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1859 //! key according to the comparison functor is greater than key or
1860 //! end() if that element does not exist.
1862 //! <b>Complexity</b>: Logarithmic.
1864 //! <b>Throws</b>: If comp ordering function throws.
1866 //! <b>Note</b>: This function is used when constructing a value_type
1867 //! is expensive and the value_type can be compared with a cheaper
1868 //! key type. Usually this key is part of the value_type.
1869 template<class KeyType
, class KeyValueCompare
>
1870 const_iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
) const
1871 { return tree_
.upper_bound(key
, comp
); }
1873 //! <b>Effects</b>: Finds an iterator to the first element whose value is
1874 //! "value" or end() if that element does not exist.
1876 //! <b>Complexity</b>: Logarithmic.
1878 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1879 iterator
find(const_reference value
)
1880 { return tree_
.find(value
); }
1882 //! <b>Requires</b>: comp must imply the same element order as
1883 //! value_compare. Usually key is the part of the value_type
1884 //! that is used in the ordering functor.
1886 //! <b>Effects</b>: Finds an iterator to the first element whose key is
1887 //! "key" according to the comparison functor or end() if that element
1890 //! <b>Complexity</b>: Logarithmic.
1892 //! <b>Throws</b>: If comp ordering function throws.
1894 //! <b>Note</b>: This function is used when constructing a value_type
1895 //! is expensive and the value_type can be compared with a cheaper
1896 //! key type. Usually this key is part of the value_type.
1897 template<class KeyType
, class KeyValueCompare
>
1898 iterator
find(const KeyType
& key
, KeyValueCompare comp
)
1899 { return tree_
.find(key
, comp
); }
1901 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
1902 //! "value" or end() if that element does not exist.
1904 //! <b>Complexity</b>: Logarithmic.
1906 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1907 const_iterator
find(const_reference value
) const
1908 { return tree_
.find(value
); }
1910 //! <b>Requires</b>: comp must imply the same element order as
1911 //! value_compare. Usually key is the part of the value_type
1912 //! that is used in the ordering functor.
1914 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
1915 //! "key" according to the comparison functor or end() if that element
1918 //! <b>Complexity</b>: Logarithmic.
1920 //! <b>Throws</b>: If comp ordering function throws.
1922 //! <b>Note</b>: This function is used when constructing a value_type
1923 //! is expensive and the value_type can be compared with a cheaper
1924 //! key type. Usually this key is part of the value_type.
1925 template<class KeyType
, class KeyValueCompare
>
1926 const_iterator
find(const KeyType
& key
, KeyValueCompare comp
) const
1927 { return tree_
.find(key
, comp
); }
1929 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1930 //! an empty range that indicates the position where those elements would be
1931 //! if they there is no elements with key k.
1933 //! <b>Complexity</b>: Logarithmic.
1935 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1936 std::pair
<iterator
,iterator
> equal_range(const_reference value
)
1937 { return tree_
.equal_range(value
); }
1939 //! <b>Requires</b>: comp must imply the same element order as
1940 //! value_compare. Usually key is the part of the value_type
1941 //! that is used in the ordering functor.
1943 //! <b>Effects</b>: Finds a range containing all elements whose key is k
1944 //! according to the comparison functor or an empty range
1945 //! that indicates the position where those elements would be
1946 //! if they there is no elements with key k.
1948 //! <b>Complexity</b>: Logarithmic.
1950 //! <b>Throws</b>: If comp ordering function throws.
1952 //! <b>Note</b>: This function is used when constructing a value_type
1953 //! is expensive and the value_type can be compared with a cheaper
1954 //! key type. Usually this key is part of the value_type.
1955 template<class KeyType
, class KeyValueCompare
>
1956 std::pair
<iterator
,iterator
> equal_range(const KeyType
& key
, KeyValueCompare comp
)
1957 { return tree_
.equal_range(key
, comp
); }
1959 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1960 //! an empty range that indicates the position where those elements would be
1961 //! if they there is no elements with key k.
1963 //! <b>Complexity</b>: Logarithmic.
1965 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1966 std::pair
<const_iterator
, const_iterator
>
1967 equal_range(const_reference value
) const
1968 { return tree_
.equal_range(value
); }
1970 //! <b>Requires</b>: comp must imply the same element order as
1971 //! value_compare. Usually key is the part of the value_type
1972 //! that is used in the ordering functor.
1974 //! <b>Effects</b>: Finds a range containing all elements whose key is k
1975 //! according to the comparison functor or an empty range
1976 //! that indicates the position where those elements would be
1977 //! if they there is no elements with key k.
1979 //! <b>Complexity</b>: Logarithmic.
1981 //! <b>Throws</b>: If comp ordering function throws.
1983 //! <b>Note</b>: This function is used when constructing a value_type
1984 //! is expensive and the value_type can be compared with a cheaper
1985 //! key type. Usually this key is part of the value_type.
1986 template<class KeyType
, class KeyValueCompare
>
1987 std::pair
<const_iterator
, const_iterator
>
1988 equal_range(const KeyType
& key
, KeyValueCompare comp
) const
1989 { return tree_
.equal_range(key
, comp
); }
1991 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
1992 //! appropriate type. Otherwise the behavior is undefined.
1994 //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_multiset
1995 //! that points to the value
1997 //! <b>Complexity</b>: Constant.
1999 //! <b>Throws</b>: Nothing.
2001 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2003 static iterator
s_iterator_to(reference value
)
2004 { return tree_type::s_iterator_to(value
); }
2006 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
2007 //! appropriate type. Otherwise the behavior is undefined.
2009 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2010 //! sg_multiset that points to the value
2012 //! <b>Complexity</b>: Constant.
2014 //! <b>Throws</b>: Nothing.
2016 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2018 static const_iterator
s_iterator_to(const_reference value
)
2019 { return tree_type::s_iterator_to(value
); }
2021 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
2022 //! appropriate type. Otherwise the behavior is undefined.
2024 //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_multiset
2025 //! that points to the value
2027 //! <b>Complexity</b>: Constant.
2029 //! <b>Throws</b>: Nothing.
2030 iterator
iterator_to(reference value
)
2031 { return tree_
.iterator_to(value
); }
2033 //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
2034 //! appropriate type. Otherwise the behavior is undefined.
2036 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2037 //! sg_multiset that points to the value
2039 //! <b>Complexity</b>: Constant.
2041 //! <b>Throws</b>: Nothing.
2042 const_iterator
iterator_to(const_reference value
) const
2043 { return tree_
.iterator_to(value
); }
2045 //! <b>Requires</b>: value shall not be in a sg_multiset/sg_multiset.
2047 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
2050 //! <b>Throws</b>: Nothing.
2052 //! <b>Complexity</b>: Constant time.
2054 //! <b>Note</b>: This function puts the hook in the well-known default state
2055 //! used by auto_unlink and safe hooks.
2056 static void init_node(reference value
)
2057 { tree_type::init_node(value
); }
2059 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
2061 //! <b>Complexity</b>: Average complexity is constant time.
2063 //! <b>Throws</b>: Nothing.
2065 //! <b>Notes</b>: This function breaks the tree and the tree can
2066 //! only be used for more unlink_leftmost_without_rebalance calls.
2067 //! This function is normally used to achieve a step by step
2068 //! controlled destruction of the tree.
2069 pointer
unlink_leftmost_without_rebalance()
2070 { return tree_
.unlink_leftmost_without_rebalance(); }
2072 //! <b>Requires</b>: replace_this must be a valid iterator of *this
2073 //! and with_this must not be inserted in any tree.
2075 //! <b>Effects</b>: Replaces replace_this in its position in the
2076 //! tree with with_this. The tree does not need to be rebalanced.
2078 //! <b>Complexity</b>: Constant.
2080 //! <b>Throws</b>: Nothing.
2082 //! <b>Note</b>: This function will break container ordering invariants if
2083 //! with_this is not equivalent to *replace_this according to the
2084 //! ordering rules. This function is faster than erasing and inserting
2085 //! the node, since no rebalancing or comparison is needed.
2086 void replace_node(iterator replace_this
, reference with_this
)
2087 { tree_
.replace_node(replace_this
, with_this
); }
2089 //! <b>Effects</b>: Rebalances the tree.
2091 //! <b>Throws</b>: Nothing.
2093 //! <b>Complexity</b>: Linear.
2095 { tree_
.rebalance(); }
2097 //! <b>Requires</b>: old_root is a node of a tree.
2099 //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
2101 //! <b>Returns</b>: The new root of the subtree.
2103 //! <b>Throws</b>: Nothing.
2105 //! <b>Complexity</b>: Linear to the elements in the subtree.
2106 iterator
rebalance_subtree(iterator root
)
2107 { return tree_
.rebalance_subtree(root
); }
2109 //! <b>Returns</b>: The balance factor (alpha) used in this tree
2111 //! <b>Throws</b>: Nothing.
2113 //! <b>Complexity</b>: Constant.
2114 float balance_factor() const
2115 { return tree_
.balance_factor(); }
2117 //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
2119 //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
2120 //! the tree if the new balance factor is stricter (less) than the old factor.
2122 //! <b>Throws</b>: Nothing.
2124 //! <b>Complexity</b>: Linear to the elements in the subtree.
2125 void balance_factor(float new_alpha
)
2126 { tree_
.balance_factor(new_alpha
); }
2129 friend bool operator==(const sg_multiset_impl
&x
, const sg_multiset_impl
&y
)
2130 { return x
.tree_
== y
.tree_
; }
2132 friend bool operator<(const sg_multiset_impl
&x
, const sg_multiset_impl
&y
)
2133 { return x
.tree_
< y
.tree_
; }
2137 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2138 template<class T
, class ...Options
>
2140 template<class Config
>
2142 inline bool operator!=
2143 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2144 (const sg_multiset_impl
<T
, Options
...> &x
, const sg_multiset_impl
<T
, Options
...> &y
)
2146 (const sg_multiset_impl
<Config
> &x
, const sg_multiset_impl
<Config
> &y
)
2148 { return !(x
== y
); }
2150 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2151 template<class T
, class ...Options
>
2153 template<class Config
>
2155 inline bool operator>
2156 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2157 (const sg_multiset_impl
<T
, Options
...> &x
, const sg_multiset_impl
<T
, Options
...> &y
)
2159 (const sg_multiset_impl
<Config
> &x
, const sg_multiset_impl
<Config
> &y
)
2163 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2164 template<class T
, class ...Options
>
2166 template<class Config
>
2168 inline bool operator<=
2169 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2170 (const sg_multiset_impl
<T
, Options
...> &x
, const sg_multiset_impl
<T
, Options
...> &y
)
2172 (const sg_multiset_impl
<Config
> &x
, const sg_multiset_impl
<Config
> &y
)
2174 { return !(y
< x
); }
2176 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2177 template<class T
, class ...Options
>
2179 template<class Config
>
2181 inline bool operator>=
2182 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2183 (const sg_multiset_impl
<T
, Options
...> &x
, const sg_multiset_impl
<T
, Options
...> &y
)
2185 (const sg_multiset_impl
<Config
> &x
, const sg_multiset_impl
<Config
> &y
)
2187 { return !(x
< y
); }
2189 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2190 template<class T
, class ...Options
>
2192 template<class Config
>
2195 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2196 (sg_multiset_impl
<T
, Options
...> &x
, sg_multiset_impl
<T
, Options
...> &y
)
2198 (sg_multiset_impl
<Config
> &x
, sg_multiset_impl
<Config
> &y
)
2202 //! Helper metafunction to define a \c sg_multiset that yields to the same type when the
2203 //! same options (either explicitly or implicitly) are used.
2204 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2205 template<class T
, class ...Options
>
2207 template<class T
, class O1
= none
, class O2
= none
2208 , class O3
= none
, class O4
= none
>
2210 struct make_sg_multiset
2213 typedef sg_multiset_impl
2214 < typename make_sgtree_opt
<T
,
2215 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2221 > implementation_defined
;
2223 typedef implementation_defined type
;
2226 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
2228 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2229 template<class T
, class O1
, class O2
, class O3
, class O4
>
2231 template<class T
, class ...Options
>
2234 : public make_sg_multiset
<T
,
2235 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2242 typedef typename make_sg_multiset
2244 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2252 typedef typename
Base::value_compare value_compare
;
2253 typedef typename
Base::value_traits value_traits
;
2254 typedef typename
Base::iterator iterator
;
2255 typedef typename
Base::const_iterator const_iterator
;
2257 //Assert if passed value traits are compatible with the type
2258 BOOST_STATIC_ASSERT((detail::is_same
<typename
value_traits::value_type
, T
>::value
));
2260 sg_multiset( const value_compare
&cmp
= value_compare()
2261 , const value_traits
&v_traits
= value_traits())
2262 : Base(cmp
, v_traits
)
2265 template<class Iterator
>
2266 sg_multiset( Iterator b
, Iterator e
2267 , const value_compare
&cmp
= value_compare()
2268 , const value_traits
&v_traits
= value_traits())
2269 : Base(b
, e
, cmp
, v_traits
)
2272 static sg_multiset
&container_from_end_iterator(iterator end_iterator
)
2273 { return static_cast<sg_multiset
&>(Base::container_from_end_iterator(end_iterator
)); }
2275 static const sg_multiset
&container_from_end_iterator(const_iterator end_iterator
)
2276 { return static_cast<const sg_multiset
&>(Base::container_from_end_iterator(end_iterator
)); }
2278 static sg_multiset
&container_from_iterator(iterator it
)
2279 { return static_cast<sg_multiset
&>(Base::container_from_iterator(it
)); }
2281 static const sg_multiset
&container_from_iterator(const_iterator it
)
2282 { return static_cast<const sg_multiset
&>(Base::container_from_iterator(it
)); }
2287 } //namespace intrusive
2290 #include <boost/intrusive/detail/config_end.hpp>
2292 #endif //BOOST_INTRUSIVE_SG_SET_HPP