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_SPLAY_SET_HPP
13 #define BOOST_INTRUSIVE_SPLAY_SET_HPP
15 #include <boost/intrusive/detail/config_begin.hpp>
16 #include <boost/intrusive/intrusive_fwd.hpp>
17 #include <boost/intrusive/splaytree.hpp>
18 #include <boost/intrusive/detail/mpl.hpp>
24 //! The class template splay_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 splaytree_impl
<Config
> tree_type
;
46 splay_set_impl (const splay_set_impl
&);
50 splay_set_impl
&operator =(const splay_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 splay_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 splay_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 splay_set and inserts elements from
101 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
102 //! comp and otherwise amortized 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 splay_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 splay_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 splay_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 splay_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 splay_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 splay_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 splay_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 splay_set.
166 //! <b>Complexity</b>: Constant.
168 //! <b>Throws</b>: Nothing.
169 const_iterator
cend() const
170 { return tree_
.cend(); }
172 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
173 //! reversed splay_set.
175 //! <b>Complexity</b>: Constant.
177 //! <b>Throws</b>: Nothing.
178 reverse_iterator
rbegin()
179 { return tree_
.rbegin(); }
181 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
182 //! of the reversed splay_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 splay_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 splay_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 splay_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 splay_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 splay_set associated to the end iterator
231 //! <b>Throws</b>: Nothing.
233 //! <b>Complexity</b>: Constant.
234 static splay_set_impl
&container_from_end_iterator(iterator end_iterator
)
236 return *detail::parent_from_member
<splay_set_impl
, tree_type
>
237 ( &tree_type::container_from_end_iterator(end_iterator
)
238 , &splay_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 splay_set associated to the end iterator
246 //! <b>Throws</b>: Nothing.
248 //! <b>Complexity</b>: Constant.
249 static const splay_set_impl
&container_from_end_iterator(const_iterator end_iterator
)
251 return *detail::parent_from_member
<splay_set_impl
, tree_type
>
252 ( &tree_type::container_from_end_iterator(end_iterator
)
253 , &splay_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>: Constant.
263 static splay_set_impl
&container_from_iterator(iterator it
)
265 return *detail::parent_from_member
<splay_set_impl
, tree_type
>
266 ( &tree_type::container_from_iterator(it
)
267 , &splay_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 splay_set_impl
&container_from_iterator(const_iterator it
)
279 return *detail::parent_from_member
<splay_set_impl
, tree_type
>
280 ( &tree_type::container_from_iterator(it
)
281 , &splay_set_impl::tree_
);
284 //! <b>Effects</b>: Returns the key_compare object used by the splay_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 splay_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 splay_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 splay_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(splay_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 splay_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 splay_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>: Amortized logarithmic.
356 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
358 //! <b>Note</b>: Does not affect the validity of iterators and references.
359 //! No copy-constructors are called.
360 std::pair
<iterator
, bool> insert(reference value
)
361 { return tree_
.insert_unique(value
); }
363 //! <b>Requires</b>: value must be an lvalue
365 //! <b>Effects</b>: Tries to to insert x into the splay_set, using "hint"
366 //! as a hint to where it will be inserted.
368 //! <b>Returns</b>: An iterator that points to the position where the
369 //! new element was inserted into the splay_set.
371 //! <b>Complexity</b>: Amortized logarithmic in general, but it's amortized
372 //! constant time if t is inserted immediately before hint.
374 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
376 //! <b>Note</b>: Does not affect the validity of iterators and references.
377 //! No copy-constructors are called.
378 iterator
insert(const_iterator hint
, reference value
)
379 { return tree_
.insert_unique(hint
, value
); }
381 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
382 //! the same strict weak ordering as value_compare. The difference is that
383 //! key_value_comp compares an arbitrary key with the contained values.
385 //! <b>Effects</b>: Checks if a value can be inserted in the splay_set, using
386 //! a user provided key instead of the value itself.
388 //! <b>Returns</b>: If there is an equivalent value
389 //! returns a pair containing an iterator to the already present value
390 //! and false. If the value can be inserted returns true in the returned
391 //! pair boolean and fills "commit_data" that is meant to be used with
392 //! the "insert_commit" function.
394 //! <b>Complexity</b>: Amortized logarithmic.
396 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
398 //! <b>Notes</b>: This function is used to improve performance when constructing
399 //! a value_type is expensive: if there is an equivalent value
400 //! the constructed object must be discarded. Many times, the part of the
401 //! node that is used to impose the order is much cheaper to construct
402 //! than the value_type and this function offers the possibility to use that
403 //! part to check if the insertion will be successful.
405 //! If the check is successful, the user can construct the value_type and use
406 //! "insert_commit" to insert the object in constant-time. This gives a total
407 //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
409 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
410 //! objects are inserted or erased from the splay_set.
411 template<class KeyType
, class KeyValueCompare
>
412 std::pair
<iterator
, bool> insert_check
413 (const KeyType
&key
, KeyValueCompare key_value_comp
, insert_commit_data
&commit_data
)
414 { return tree_
.insert_unique_check(key
, key_value_comp
, commit_data
); }
416 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
417 //! the same strict weak ordering as value_compare. The difference is that
418 //! key_value_comp compares an arbitrary key with the contained values.
420 //! <b>Effects</b>: Checks if a value can be inserted in the splay_set, using
421 //! a user provided key instead of the value itself, using "hint"
422 //! as a hint to where it will be inserted.
424 //! <b>Returns</b>: If there is an equivalent value
425 //! returns a pair containing an iterator to the already present value
426 //! and false. If the value can be inserted returns true in the returned
427 //! pair boolean and fills "commit_data" that is meant to be used with
428 //! the "insert_commit" function.
430 //! <b>Complexity</b>: Amortized logarithmic in general, but it's amortized
431 //! constant time if t is inserted immediately before hint.
433 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
435 //! <b>Notes</b>: This function is used to improve performance when constructing
436 //! a value_type is expensive: if there is an equivalent value
437 //! the constructed object must be discarded. Many times, the part of the
438 //! constructing that is used to impose the order is much cheaper to construct
439 //! than the value_type and this function offers the possibility to use that key
440 //! to check if the insertion will be successful.
442 //! If the check is successful, the user can construct the value_type and use
443 //! "insert_commit" to insert the object in constant-time. This can give a total
444 //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
446 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
447 //! objects are inserted or erased from the splay_set.
448 template<class KeyType
, class KeyValueCompare
>
449 std::pair
<iterator
, bool> insert_check
450 (const_iterator hint
, const KeyType
&key
451 ,KeyValueCompare key_value_comp
, insert_commit_data
&commit_data
)
452 { return tree_
.insert_unique_check(hint
, key
, key_value_comp
, commit_data
); }
454 //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
455 //! must have been obtained from a previous call to "insert_check".
456 //! No objects should have been inserted or erased from the splay_set between
457 //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
459 //! <b>Effects</b>: Inserts the value in the splay_set using the information obtained
460 //! from the "commit_data" that a previous "insert_check" filled.
462 //! <b>Returns</b>: An iterator to the newly inserted object.
464 //! <b>Complexity</b>: Constant time.
466 //! <b>Throws</b>: Nothing.
468 //! <b>Notes</b>: This function has only sense if a "insert_check" has been
469 //! previously executed to fill "commit_data". No value should be inserted or
470 //! erased between the "insert_check" and "insert_commit" calls.
471 iterator
insert_commit(reference value
, const insert_commit_data
&commit_data
)
472 { return tree_
.insert_unique_commit(value
, commit_data
); }
474 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
475 //! of type value_type.
477 //! <b>Effects</b>: Inserts a range into the splay_set.
479 //! <b>Complexity</b>: Insert range is amortized O(N * log(N)), where N is the
480 //! size of the range. However, it is linear in N if the range is already sorted
483 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
485 //! <b>Note</b>: Does not affect the validity of iterators and references.
486 //! No copy-constructors are called.
487 template<class Iterator
>
488 void insert(Iterator b
, Iterator e
)
489 { tree_
.insert_unique(b
, e
); }
491 //! <b>Effects</b>: Erases the element pointed to by pos.
493 //! <b>Complexity</b>: Average complexity is constant time.
495 //! <b>Returns</b>: An iterator to the element after the erased element.
497 //! <b>Throws</b>: Nothing.
499 //! <b>Note</b>: Invalidates the iterators (but not the references)
500 //! to the erased elements. No destructors are called.
501 iterator
erase(const_iterator i
)
502 { return tree_
.erase(i
); }
504 //! <b>Effects</b>: Erases the range pointed to by b end e.
506 //! <b>Complexity</b>: Average complexity for erase range is amortized
507 //! O(log(size() + N)), where N is the number of elements in the range.
509 //! <b>Returns</b>: An iterator to the element after the erased elements.
511 //! <b>Throws</b>: Nothing.
513 //! <b>Note</b>: Invalidates the iterators (but not the references)
514 //! to the erased elements. No destructors are called.
515 iterator
erase(const_iterator b
, const_iterator e
)
516 { return tree_
.erase(b
, e
); }
518 //! <b>Effects</b>: Erases all the elements with the given value.
520 //! <b>Returns</b>: The number of erased elements.
522 //! <b>Complexity</b>: Amortized O(log(size()) + this->count(value)).
524 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
526 //! <b>Note</b>: Invalidates the iterators (but not the references)
527 //! to the erased elements. No destructors are called.
528 size_type
erase(const_reference value
)
529 { return tree_
.erase(value
); }
531 //! <b>Effects</b>: Erases all the elements that compare equal with
532 //! the given key and the given comparison functor.
534 //! <b>Returns</b>: The number of erased elements.
536 //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
538 //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee.
540 //! <b>Note</b>: Invalidates the iterators (but not the references)
541 //! to the erased elements. No destructors are called.
542 template<class KeyType
, class KeyValueCompare
>
543 size_type
erase(const KeyType
& key
, KeyValueCompare comp
545 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
548 { return tree_
.erase(key
, comp
); }
550 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
552 //! <b>Effects</b>: Erases the element pointed to by pos.
553 //! Disposer::operator()(pointer) is called for the removed element.
555 //! <b>Complexity</b>: Average complexity for erase element is constant time.
557 //! <b>Returns</b>: An iterator to the element after the erased element.
559 //! <b>Throws</b>: Nothing.
561 //! <b>Note</b>: Invalidates the iterators
562 //! to the erased elements.
563 template<class Disposer
>
564 iterator
erase_and_dispose(const_iterator i
, Disposer disposer
)
565 { return tree_
.erase_and_dispose(i
, disposer
); }
567 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
568 template<class Disposer
>
569 iterator
erase_and_dispose(iterator i
, Disposer disposer
)
570 { return this->erase_and_dispose(const_iterator(i
), disposer
); }
573 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
575 //! <b>Effects</b>: Erases the range pointed to by b end e.
576 //! Disposer::operator()(pointer) is called for the removed elements.
578 //! <b>Complexity</b>: Average complexity for erase range is at most
579 //! O(log(size() + N)), where N is the number of elements in the range.
581 //! <b>Returns</b>: An iterator to the element after the erased elements.
583 //! <b>Throws</b>: Nothing.
585 //! <b>Note</b>: Invalidates the iterators
586 //! to the erased elements.
587 template<class Disposer
>
588 iterator
erase_and_dispose(const_iterator b
, const_iterator e
, Disposer disposer
)
589 { return tree_
.erase_and_dispose(b
, e
, disposer
); }
591 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
593 //! <b>Effects</b>: Erases all the elements with the given value.
594 //! Disposer::operator()(pointer) is called for the removed elements.
596 //! <b>Throws</b>: If the internal value_compare ordering function throws.
598 //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)). Basic guarantee.
600 //! <b>Throws</b>: Nothing.
602 //! <b>Note</b>: Invalidates the iterators (but not the references)
603 //! to the erased elements. No destructors are called.
604 template<class Disposer
>
605 size_type
erase_and_dispose(const_reference value
, Disposer disposer
)
606 { return tree_
.erase_and_dispose(value
, disposer
); }
608 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
610 //! <b>Effects</b>: Erases all the elements with the given key.
611 //! according to the comparison functor "comp".
612 //! Disposer::operator()(pointer) is called for the removed elements.
614 //! <b>Returns</b>: The number of erased elements.
616 //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
618 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
620 //! <b>Note</b>: Invalidates the iterators
621 //! to the erased elements.
622 template<class KeyType
, class KeyValueCompare
, class Disposer
>
623 size_type
erase_and_dispose(const KeyType
& key
, KeyValueCompare comp
, Disposer disposer
625 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
628 { return tree_
.erase_and_dispose(key
, comp
, disposer
); }
630 //! <b>Effects</b>: Erases all the elements of the container.
632 //! <b>Complexity</b>: Linear to the number of elements on the container.
633 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
635 //! <b>Throws</b>: Nothing.
637 //! <b>Note</b>: Invalidates the iterators (but not the references)
638 //! to the erased elements. No destructors are called.
640 { return tree_
.clear(); }
642 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
644 //! <b>Effects</b>: Erases all the elements of the container.
646 //! <b>Complexity</b>: Linear to the number of elements on the container.
647 //! Disposer::operator()(pointer) is called for the removed elements.
649 //! <b>Throws</b>: Nothing.
651 //! <b>Note</b>: Invalidates the iterators (but not the references)
652 //! to the erased elements. No destructors are called.
653 template<class Disposer
>
654 void clear_and_dispose(Disposer disposer
)
655 { return tree_
.clear_and_dispose(disposer
); }
657 //! <b>Effects</b>: Returns the number of contained elements with the given key
659 //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
660 //! to number of objects with the given key.
662 //! <b>Throws</b>: If the internal value_compare ordering function throws.
663 size_type
count(const_reference value
)
664 { return tree_
.find(value
) != end(); }
666 //! <b>Effects</b>: Returns the number of contained elements with the same key
667 //! compared with the given comparison functor.
669 //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
670 //! to number of objects with the given key.
672 //! <b>Throws</b>: If comp ordering function throws.
673 template<class KeyType
, class KeyValueCompare
>
674 size_type
count(const KeyType
& key
, KeyValueCompare comp
)
675 { return tree_
.find(key
, comp
) != end(); }
677 //! <b>Effects</b>: Returns the number of contained elements with the given key
679 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
680 //! to number of objects with the given key.
682 //! <b>Throws</b>: If the internal value_compare ordering function throws.
683 size_type
count_dont_splay(const_reference value
)const
684 { return tree_
.find_dont_splay(value
) != end(); }
686 //! <b>Effects</b>: Returns the number of contained elements with the same key
687 //! compared with the given comparison functor.
689 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
690 //! to number of objects with the given key.
692 //! <b>Throws</b>: If comp ordering function throws.
693 template<class KeyType
, class KeyValueCompare
>
694 size_type
count_dont_splay(const KeyType
& key
, KeyValueCompare comp
)const
695 { return tree_
.find_dont_splay(key
, comp
) != end(); }
697 //! <b>Effects</b>: Returns an iterator to the first element whose
698 //! key is not less than k or end() if that element does not exist.
700 //! <b>Complexity</b>: Amortized logarithmic.
702 //! <b>Throws</b>: If the internal value_compare ordering function throws.
703 iterator
lower_bound(const_reference value
)
704 { return tree_
.lower_bound(value
); }
706 //! <b>Requires</b>: comp must imply the same element order as
707 //! value_compare. Usually key is the part of the value_type
708 //! that is used in the ordering functor.
710 //! <b>Effects</b>: Returns an iterator to the first element whose
711 //! key according to the comparison functor is not less than k or
712 //! end() if that element does not exist.
714 //! <b>Complexity</b>: Amortized logarithmic.
716 //! <b>Throws</b>: If comp ordering function throws.
718 //! <b>Note</b>: This function is used when constructing a value_type
719 //! is expensive and the value_type can be compared with a cheaper
720 //! key type. Usually this key is part of the value_type.
721 template<class KeyType
, class KeyValueCompare
>
722 iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
)
723 { return tree_
.lower_bound(key
, comp
); }
725 //! <b>Effects</b>: Returns a const iterator to the first element whose
726 //! key is not less than k or end() if that element does not exist.
728 //! <b>Complexity</b>: Logarithmic.
730 //! <b>Throws</b>: If the internal value_compare ordering function throws.
731 const_iterator
lower_bound_dont_splay(const_reference value
) const
732 { return tree_
.lower_bound_dont_splay(value
); }
734 //! <b>Requires</b>: comp must imply the same element order as
735 //! value_compare. Usually key is the part of the value_type
736 //! that is used in the ordering functor.
738 //! <b>Effects</b>: Returns a const_iterator to the first element whose
739 //! key according to the comparison functor is not less than k or
740 //! end() if that element does not exist.
742 //! <b>Complexity</b>: Logarithmic.
744 //! <b>Throws</b>: If comp ordering function throws.
746 //! <b>Note</b>: This function is used when constructing a value_type
747 //! is expensive and the value_type can be compared with a cheaper
748 //! key type. Usually this key is part of the value_type.
749 template<class KeyType
, class KeyValueCompare
>
750 const_iterator
lower_bound_dont_splay(const KeyType
& key
, KeyValueCompare comp
) const
751 { return tree_
.lower_bound_dont_splay(key
, comp
); }
753 //! <b>Effects</b>: Returns an iterator to the first element whose
754 //! key is greater than k or end() if that element does not exist.
756 //! <b>Complexity</b>: Amortized logarithmic.
758 //! <b>Throws</b>: If the internal value_compare ordering function throws.
759 iterator
upper_bound(const_reference value
)
760 { return tree_
.upper_bound(value
); }
762 //! <b>Requires</b>: comp must imply the same element order as
763 //! value_compare. Usually key is the part of the value_type
764 //! that is used in the ordering functor.
766 //! <b>Effects</b>: Returns an iterator to the first element whose
767 //! key according to the comparison functor is greater than key or
768 //! end() if that element does not exist.
770 //! <b>Complexity</b>: Amortized logarithmic.
772 //! <b>Throws</b>: If comp ordering function throws.
774 //! <b>Note</b>: This function is used when constructing a value_type
775 //! is expensive and the value_type can be compared with a cheaper
776 //! key type. Usually this key is part of the value_type.
777 template<class KeyType
, class KeyValueCompare
>
778 iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
)
779 { return tree_
.upper_bound(key
, comp
); }
781 //! <b>Effects</b>: Returns an iterator to the first element whose
782 //! key is greater than k or end() if that element does not exist.
784 //! <b>Complexity</b>: Logarithmic.
786 //! <b>Throws</b>: If the internal value_compare ordering function throws.
787 const_iterator
upper_bound_dont_splay(const_reference value
) const
788 { return tree_
.upper_bound_dont_splay(value
); }
790 //! <b>Requires</b>: comp must imply the same element order as
791 //! value_compare. Usually key is the part of the value_type
792 //! that is used in the ordering functor.
794 //! <b>Effects</b>: Returns a const_iterator to the first element whose
795 //! key according to the comparison functor is greater than key or
796 //! end() if that element does not exist.
798 //! <b>Complexity</b>: Logarithmic.
800 //! <b>Throws</b>: If comp ordering function throws.
802 //! <b>Note</b>: This function is used when constructing a value_type
803 //! is expensive and the value_type can be compared with a cheaper
804 //! key type. Usually this key is part of the value_type.
805 template<class KeyType
, class KeyValueCompare
>
806 const_iterator
upper_bound_dont_splay(const KeyType
& key
, KeyValueCompare comp
) const
807 { return tree_
.upper_bound_dont_splay(key
, comp
); }
809 //! <b>Effects</b>: Finds an iterator to the first element whose value is
810 //! "value" or end() if that element does not exist.
812 //! <b>Complexity</b>: Amortized logarithmic.
814 //! <b>Throws</b>: If the internal value_compare ordering function throws.
815 iterator
find(const_reference value
)
816 { return tree_
.find(value
); }
818 //! <b>Requires</b>: comp must imply the same element order as
819 //! value_compare. Usually key is the part of the value_type
820 //! that is used in the ordering functor.
822 //! <b>Effects</b>: Finds an iterator to the first element whose key is
823 //! "key" according to the comparison functor or end() if that element
826 //! <b>Complexity</b>: Amortized logarithmic.
828 //! <b>Throws</b>: If comp ordering function throws.
830 //! <b>Note</b>: This function is used when constructing a value_type
831 //! is expensive and the value_type can be compared with a cheaper
832 //! key type. Usually this key is part of the value_type.
833 template<class KeyType
, class KeyValueCompare
>
834 iterator
find(const KeyType
& key
, KeyValueCompare comp
)
835 { return tree_
.find(key
, comp
); }
837 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
838 //! "value" or end() if that element does not exist.
840 //! <b>Complexity</b>: Logarithmic.
842 //! <b>Throws</b>: If the internal value_compare ordering function throws.
843 const_iterator
find_dont_splay(const_reference value
) const
844 { return tree_
.find_dont_splay(value
); }
846 //! <b>Requires</b>: comp must imply the same element order as
847 //! value_compare. Usually key is the part of the value_type
848 //! that is used in the ordering functor.
850 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
851 //! "key" according to the comparison functor or end() if that element
854 //! <b>Complexity</b>: Logarithmic.
856 //! <b>Throws</b>: If comp ordering function throws.
858 //! <b>Note</b>: This function is used when constructing a value_type
859 //! is expensive and the value_type can be compared with a cheaper
860 //! key type. Usually this key is part of the value_type.
861 template<class KeyType
, class KeyValueCompare
>
862 const_iterator
find_dont_splay(const KeyType
& key
, KeyValueCompare comp
) const
863 { return tree_
.find_dont_splay(key
, comp
); }
865 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
866 //! an empty range that indicates the position where those elements would be
867 //! if they there is no elements with key k.
869 //! <b>Complexity</b>: Amortized logarithmic.
871 //! <b>Throws</b>: If the internal value_compare ordering function throws.
872 std::pair
<iterator
,iterator
> equal_range(const_reference value
)
873 { return tree_
.equal_range(value
); }
875 //! <b>Requires</b>: comp must imply the same element order as
876 //! value_compare. Usually key is the part of the value_type
877 //! that is used in the ordering functor.
879 //! <b>Effects</b>: Finds a range containing all elements whose key is k
880 //! according to the comparison functor or an empty range
881 //! that indicates the position where those elements would be
882 //! if they there is no elements with key k.
884 //! <b>Complexity</b>: Amortized logarithmic.
886 //! <b>Throws</b>: If comp ordering function throws.
888 //! <b>Note</b>: This function is used when constructing a value_type
889 //! is expensive and the value_type can be compared with a cheaper
890 //! key type. Usually this key is part of the value_type.
891 template<class KeyType
, class KeyValueCompare
>
892 std::pair
<iterator
,iterator
> equal_range(const KeyType
& key
, KeyValueCompare comp
)
893 { return tree_
.equal_range(key
, comp
); }
895 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
896 //! an empty range that indicates the position where those elements would be
897 //! if they there is no elements with key k.
899 //! <b>Complexity</b>: Logarithmic.
901 //! <b>Throws</b>: If the internal value_compare ordering function throws.
902 std::pair
<const_iterator
, const_iterator
>
903 equal_range_dont_splay(const_reference value
) const
904 { return tree_
.equal_range_dont_splay(value
); }
906 //! <b>Requires</b>: comp must imply the same element order as
907 //! value_compare. Usually key is the part of the value_type
908 //! that is used in the ordering functor.
910 //! <b>Effects</b>: Finds a range containing all elements whose key is k
911 //! according to the comparison functor or an empty range
912 //! that indicates the position where those elements would be
913 //! if they there is no elements with key k.
915 //! <b>Complexity</b>: Logarithmic.
917 //! <b>Throws</b>: If comp ordering function throws.
919 //! <b>Note</b>: This function is used when constructing a value_type
920 //! is expensive and the value_type can be compared with a cheaper
921 //! key type. Usually this key is part of the value_type.
922 template<class KeyType
, class KeyValueCompare
>
923 std::pair
<const_iterator
, const_iterator
>
924 equal_range_dont_splay(const KeyType
& key
, KeyValueCompare comp
) const
925 { return tree_
.equal_range_dont_splay(key
, comp
); }
927 //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of
928 //! appropriate type. Otherwise the behavior is undefined.
930 //! <b>Effects</b>: Returns: a valid iterator i belonging to the splay_set
931 //! that points to the value
933 //! <b>Complexity</b>: Constant.
935 //! <b>Throws</b>: Nothing.
937 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
939 static iterator
s_iterator_to(reference value
)
940 { return tree_type::s_iterator_to(value
); }
942 //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of
943 //! appropriate type. Otherwise the behavior is undefined.
945 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
946 //! splay_set that points to the value
948 //! <b>Complexity</b>: Constant.
950 //! <b>Throws</b>: Nothing.
952 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
954 static const_iterator
s_iterator_to(const_reference value
)
955 { return tree_type::s_iterator_to(value
); }
957 //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of
958 //! appropriate type. Otherwise the behavior is undefined.
960 //! <b>Effects</b>: Returns: a valid iterator i belonging to the splay_set
961 //! that points to the value
963 //! <b>Complexity</b>: Constant.
965 //! <b>Throws</b>: Nothing.
966 iterator
iterator_to(reference value
)
967 { return tree_
.iterator_to(value
); }
969 //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of
970 //! appropriate type. Otherwise the behavior is undefined.
972 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
973 //! splay_set that points to the value
975 //! <b>Complexity</b>: Constant.
977 //! <b>Throws</b>: Nothing.
978 const_iterator
iterator_to(const_reference value
) const
979 { return tree_
.iterator_to(value
); }
981 //! <b>Requires</b>: value shall not be in a splay_set/multisplay_set.
983 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
986 //! <b>Throws</b>: Nothing.
988 //! <b>Complexity</b>: Constant time.
990 //! <b>Note</b>: This function puts the hook in the well-known default state
991 //! used by auto_unlink and safe hooks.
992 static void init_node(reference value
)
993 { tree_type::init_node(value
); }
995 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
997 //! <b>Complexity</b>: Average complexity is constant time.
999 //! <b>Throws</b>: Nothing.
1001 //! <b>Notes</b>: This function breaks the tree and the tree can
1002 //! only be used for more unlink_leftmost_without_rebalance calls.
1003 //! This function is normally used to achieve a step by step
1004 //! controlled destruction of the tree.
1005 pointer
unlink_leftmost_without_rebalance()
1006 { return tree_
.unlink_leftmost_without_rebalance(); }
1008 //! <b>Requires</b>: replace_this must be a valid iterator of *this
1009 //! and with_this must not be inserted in any tree.
1011 //! <b>Effects</b>: Replaces replace_this in its position in the
1012 //! tree with with_this. The tree does not need to be rebalanced.
1014 //! <b>Complexity</b>: Constant.
1016 //! <b>Throws</b>: Nothing.
1018 //! <b>Note</b>: This function will break container ordering invariants if
1019 //! with_this is not equivalent to *replace_this according to the
1020 //! ordering rules. This function is faster than erasing and inserting
1021 //! the node, since no rebalancing or comparison is needed.
1022 void replace_node(iterator replace_this
, reference with_this
)
1023 { tree_
.replace_node(replace_this
, with_this
); }
1025 //! <b>Requires</b>: i must be a valid iterator of *this.
1027 //! <b>Effects</b>: Rearranges the splay set so that the element pointed by i
1028 //! is placed as the root of the tree, improving future searches of this value.
1030 //! <b>Complexity</b>: Amortized logarithmic.
1032 //! <b>Throws</b>: Nothing.
1033 void splay_up(iterator i
)
1034 { tree_
.splay_up(i
); }
1036 //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
1037 //! with a key equivalent to value the element is placed as the root of the
1038 //! tree. If the element is not present returns the last node compared with the key.
1039 //! If the tree is empty, end() is returned.
1041 //! <b>Complexity</b>: Amortized logarithmic.
1043 //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
1045 //! <b>Throws</b>: If the comparison functor throws.
1046 template<class KeyType
, class KeyNodePtrCompare
>
1047 iterator
splay_down(const KeyType
&key
, KeyNodePtrCompare comp
)
1048 { return tree_
.splay_down(key
, comp
); }
1050 //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
1051 //! with a key equivalent to value the element is placed as the root of the
1054 //! <b>Complexity</b>: Amortized logarithmic.
1056 //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
1058 //! <b>Throws</b>: If the predicate throws.
1059 iterator
splay_down(const value_type
&value
)
1060 { return tree_
.splay_down(value
); }
1062 //! <b>Effects</b>: Rebalances the tree.
1064 //! <b>Throws</b>: Nothing.
1066 //! <b>Complexity</b>: Linear.
1068 { tree_
.rebalance(); }
1070 //! <b>Requires</b>: old_root is a node of a tree.
1072 //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
1074 //! <b>Returns</b>: The new root of the subtree.
1076 //! <b>Throws</b>: Nothing.
1078 //! <b>Complexity</b>: Linear to the elements in the subtree.
1079 iterator
rebalance_subtree(iterator root
)
1080 { return tree_
.rebalance_subtree(root
); }
1083 friend bool operator==(const splay_set_impl
&x
, const splay_set_impl
&y
)
1084 { return x
.tree_
== y
.tree_
; }
1086 friend bool operator<(const splay_set_impl
&x
, const splay_set_impl
&y
)
1087 { return x
.tree_
< y
.tree_
; }
1091 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1092 template<class T
, class ...Options
>
1094 template<class Config
>
1096 inline bool operator!=
1097 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1098 (const splay_set_impl
<T
, Options
...> &x
, const splay_set_impl
<T
, Options
...> &y
)
1100 (const splay_set_impl
<Config
> &x
, const splay_set_impl
<Config
> &y
)
1102 { return !(x
== y
); }
1104 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1105 template<class T
, class ...Options
>
1107 template<class Config
>
1109 inline bool operator>
1110 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1111 (const splay_set_impl
<T
, Options
...> &x
, const splay_set_impl
<T
, Options
...> &y
)
1113 (const splay_set_impl
<Config
> &x
, const splay_set_impl
<Config
> &y
)
1117 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1118 template<class T
, class ...Options
>
1120 template<class Config
>
1122 inline bool operator<=
1123 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1124 (const splay_set_impl
<T
, Options
...> &x
, const splay_set_impl
<T
, Options
...> &y
)
1126 (const splay_set_impl
<Config
> &x
, const splay_set_impl
<Config
> &y
)
1128 { return !(y
< x
); }
1130 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1131 template<class T
, class ...Options
>
1133 template<class Config
>
1135 inline bool operator>=
1136 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1137 (const splay_set_impl
<T
, Options
...> &x
, const splay_set_impl
<T
, Options
...> &y
)
1139 (const splay_set_impl
<Config
> &x
, const splay_set_impl
<Config
> &y
)
1141 { return !(x
< y
); }
1143 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1144 template<class T
, class ...Options
>
1146 template<class Config
>
1149 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1150 (splay_set_impl
<T
, Options
...> &x
, splay_set_impl
<T
, Options
...> &y
)
1152 (splay_set_impl
<Config
> &x
, splay_set_impl
<Config
> &y
)
1156 //! Helper metafunction to define a \c splay_set that yields to the same type when the
1157 //! same options (either explicitly or implicitly) are used.
1158 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1159 template<class T
, class ...Options
>
1161 template<class T
, class O1
= none
, class O2
= none
1162 , class O3
= none
, class O4
= none
>
1164 struct make_splay_set
1167 typedef splay_set_impl
1168 < typename make_splaytree_opt
<T
,
1169 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1175 > implementation_defined
;
1177 typedef implementation_defined type
;
1180 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1181 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1182 template<class T
, class O1
, class O2
, class O3
, class O4
>
1184 template<class T
, class ...Options
>
1187 : public make_splay_set
<T
,
1188 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1195 typedef typename make_splay_set
1197 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1205 typedef typename
Base::value_compare value_compare
;
1206 typedef typename
Base::value_traits value_traits
;
1207 typedef typename
Base::iterator iterator
;
1208 typedef typename
Base::const_iterator const_iterator
;
1210 //Assert if passed value traits are compatible with the type
1211 BOOST_STATIC_ASSERT((detail::is_same
<typename
value_traits::value_type
, T
>::value
));
1213 splay_set( const value_compare
&cmp
= value_compare()
1214 , const value_traits
&v_traits
= value_traits())
1215 : Base(cmp
, v_traits
)
1218 template<class Iterator
>
1219 splay_set( Iterator b
, Iterator e
1220 , const value_compare
&cmp
= value_compare()
1221 , const value_traits
&v_traits
= value_traits())
1222 : Base(b
, e
, cmp
, v_traits
)
1225 static splay_set
&container_from_end_iterator(iterator end_iterator
)
1226 { return static_cast<splay_set
&>(Base::container_from_end_iterator(end_iterator
)); }
1228 static const splay_set
&container_from_end_iterator(const_iterator end_iterator
)
1229 { return static_cast<const splay_set
&>(Base::container_from_end_iterator(end_iterator
)); }
1231 static splay_set
&container_from_iterator(iterator it
)
1232 { return static_cast<splay_set
&>(Base::container_from_iterator(it
)); }
1234 static const splay_set
&container_from_iterator(const_iterator it
)
1235 { return static_cast<const splay_set
&>(Base::container_from_iterator(it
)); }
1240 //! The class template splay_multiset is an intrusive container, that mimics most of
1241 //! the interface of std::multiset as described in the C++ standard.
1243 //! The template parameter \c T is the type to be managed by the container.
1244 //! The user can specify additional options and if no options are provided
1245 //! default options are used.
1247 //! The container supports the following options:
1248 //! \c base_hook<>/member_hook<>/value_traits<>,
1249 //! \c constant_time_size<>, \c size_type<> and
1251 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1252 template<class T
, class ...Options
>
1254 template<class Config
>
1256 class splay_multiset_impl
1259 typedef splaytree_impl
<Config
> tree_type
;
1261 //Non-copyable and non-assignable
1262 splay_multiset_impl (const splay_multiset_impl
&);
1263 splay_multiset_impl
&operator =(const splay_multiset_impl
&);
1264 typedef tree_type implementation_defined
;
1268 typedef typename
implementation_defined::value_type value_type
;
1269 typedef typename
implementation_defined::value_traits value_traits
;
1270 typedef typename
implementation_defined::pointer pointer
;
1271 typedef typename
implementation_defined::const_pointer const_pointer
;
1272 typedef typename
implementation_defined::reference reference
;
1273 typedef typename
implementation_defined::const_reference const_reference
;
1274 typedef typename
implementation_defined::difference_type difference_type
;
1275 typedef typename
implementation_defined::size_type size_type
;
1276 typedef typename
implementation_defined::value_compare value_compare
;
1277 typedef typename
implementation_defined::key_compare key_compare
;
1278 typedef typename
implementation_defined::iterator iterator
;
1279 typedef typename
implementation_defined::const_iterator const_iterator
;
1280 typedef typename
implementation_defined::reverse_iterator reverse_iterator
;
1281 typedef typename
implementation_defined::const_reverse_iterator const_reverse_iterator
;
1282 typedef typename
implementation_defined::insert_commit_data insert_commit_data
;
1283 typedef typename
implementation_defined::node_traits node_traits
;
1284 typedef typename
implementation_defined::node node
;
1285 typedef typename
implementation_defined::node_ptr node_ptr
;
1286 typedef typename
implementation_defined::const_node_ptr const_node_ptr
;
1287 typedef typename
implementation_defined::node_algorithms node_algorithms
;
1295 //! <b>Effects</b>: Constructs an empty splay_multiset.
1297 //! <b>Complexity</b>: Constant.
1299 //! <b>Throws</b>: If value_traits::node_traits::node
1300 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1301 //! or the copy constructor/operator() of the value_compare object throws.
1302 splay_multiset_impl( const value_compare
&cmp
= value_compare()
1303 , const value_traits
&v_traits
= value_traits())
1304 : tree_(cmp
, v_traits
)
1307 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
1308 //! cmp must be a comparison function that induces a strict weak ordering.
1310 //! <b>Effects</b>: Constructs an empty splay_multiset and inserts elements from
1313 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
1314 //! comp and otherwise amortized N * log N, where N is the distance between first and last.
1316 //! <b>Throws</b>: If value_traits::node_traits::node
1317 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1318 //! or the copy constructor/operator() of the value_compare object throws.
1319 template<class Iterator
>
1320 splay_multiset_impl( Iterator b
, Iterator e
1321 , const value_compare
&cmp
= value_compare()
1322 , const value_traits
&v_traits
= value_traits())
1323 : tree_(false, b
, e
, cmp
, v_traits
)
1326 //! <b>Effects</b>: Detaches all elements from this. The objects in the set
1327 //! are not deleted (i.e. no destructors are called).
1329 //! <b>Complexity</b>: Linear to the number of elements on the container.
1330 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1332 //! <b>Throws</b>: Nothing.
1333 ~splay_multiset_impl()
1336 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the splay_multiset.
1338 //! <b>Complexity</b>: Constant.
1340 //! <b>Throws</b>: Nothing.
1342 { return tree_
.begin(); }
1344 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_multiset.
1346 //! <b>Complexity</b>: Constant.
1348 //! <b>Throws</b>: Nothing.
1349 const_iterator
begin() const
1350 { return tree_
.begin(); }
1352 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_multiset.
1354 //! <b>Complexity</b>: Constant.
1356 //! <b>Throws</b>: Nothing.
1357 const_iterator
cbegin() const
1358 { return tree_
.cbegin(); }
1360 //! <b>Effects</b>: Returns an iterator pointing to the end of the splay_multiset.
1362 //! <b>Complexity</b>: Constant.
1364 //! <b>Throws</b>: Nothing.
1366 { return tree_
.end(); }
1368 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_multiset.
1370 //! <b>Complexity</b>: Constant.
1372 //! <b>Throws</b>: Nothing.
1373 const_iterator
end() const
1374 { return tree_
.end(); }
1376 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_multiset.
1378 //! <b>Complexity</b>: Constant.
1380 //! <b>Throws</b>: Nothing.
1381 const_iterator
cend() const
1382 { return tree_
.cend(); }
1384 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
1385 //! reversed splay_multiset.
1387 //! <b>Complexity</b>: Constant.
1389 //! <b>Throws</b>: Nothing.
1390 reverse_iterator
rbegin()
1391 { return tree_
.rbegin(); }
1393 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1394 //! of the reversed splay_multiset.
1396 //! <b>Complexity</b>: Constant.
1398 //! <b>Throws</b>: Nothing.
1399 const_reverse_iterator
rbegin() const
1400 { return tree_
.rbegin(); }
1402 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1403 //! of the reversed splay_multiset.
1405 //! <b>Complexity</b>: Constant.
1407 //! <b>Throws</b>: Nothing.
1408 const_reverse_iterator
crbegin() const
1409 { return tree_
.crbegin(); }
1411 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
1412 //! of the reversed splay_multiset.
1414 //! <b>Complexity</b>: Constant.
1416 //! <b>Throws</b>: Nothing.
1417 reverse_iterator
rend()
1418 { return tree_
.rend(); }
1420 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1421 //! of the reversed splay_multiset.
1423 //! <b>Complexity</b>: Constant.
1425 //! <b>Throws</b>: Nothing.
1426 const_reverse_iterator
rend() const
1427 { return tree_
.rend(); }
1429 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1430 //! of the reversed splay_multiset.
1432 //! <b>Complexity</b>: Constant.
1434 //! <b>Throws</b>: Nothing.
1435 const_reverse_iterator
crend() const
1436 { return tree_
.crend(); }
1438 //! <b>Precondition</b>: end_iterator must be a valid end iterator
1439 //! of splay_multiset.
1441 //! <b>Effects</b>: Returns a const reference to the splay_multiset associated to the end iterator
1443 //! <b>Throws</b>: Nothing.
1445 //! <b>Complexity</b>: Constant.
1446 static splay_multiset_impl
&container_from_end_iterator(iterator end_iterator
)
1448 return *detail::parent_from_member
<splay_multiset_impl
, tree_type
>
1449 ( &tree_type::container_from_end_iterator(end_iterator
)
1450 , &splay_multiset_impl::tree_
);
1453 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
1454 //! of splay_multiset.
1456 //! <b>Effects</b>: Returns a const reference to the splay_multiset associated to the end iterator
1458 //! <b>Throws</b>: Nothing.
1460 //! <b>Complexity</b>: Constant.
1461 static const splay_multiset_impl
&container_from_end_iterator(const_iterator end_iterator
)
1463 return *detail::parent_from_member
<splay_multiset_impl
, tree_type
>
1464 ( &tree_type::container_from_end_iterator(end_iterator
)
1465 , &splay_multiset_impl::tree_
);
1468 //! <b>Precondition</b>: it must be a valid iterator of multiset.
1470 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1472 //! <b>Throws</b>: Nothing.
1474 //! <b>Complexity</b>: Logarithmic.
1475 static splay_multiset_impl
&container_from_iterator(iterator it
)
1477 return *detail::parent_from_member
<splay_multiset_impl
, tree_type
>
1478 ( &tree_type::container_from_iterator(it
)
1479 , &splay_multiset_impl::tree_
);
1482 //! <b>Precondition</b>: it must be a valid const_iterator of multiset.
1484 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1486 //! <b>Throws</b>: Nothing.
1488 //! <b>Complexity</b>: Constant.
1489 static const splay_multiset_impl
&container_from_iterator(const_iterator it
)
1491 return *detail::parent_from_member
<splay_multiset_impl
, tree_type
>
1492 ( &tree_type::container_from_iterator(it
)
1493 , &splay_multiset_impl::tree_
);
1496 //! <b>Effects</b>: Returns the key_compare object used by the splay_multiset.
1498 //! <b>Complexity</b>: Constant.
1500 //! <b>Throws</b>: If key_compare copy-constructor throws.
1501 key_compare
key_comp() const
1502 { return tree_
.value_comp(); }
1504 //! <b>Effects</b>: Returns the value_compare object used by the splay_multiset.
1506 //! <b>Complexity</b>: Constant.
1508 //! <b>Throws</b>: If value_compare copy-constructor throws.
1509 value_compare
value_comp() const
1510 { return tree_
.value_comp(); }
1512 //! <b>Effects</b>: Returns true if the container is empty.
1514 //! <b>Complexity</b>: Constant.
1516 //! <b>Throws</b>: Nothing.
1518 { return tree_
.empty(); }
1520 //! <b>Effects</b>: Returns the number of elements stored in the splay_multiset.
1522 //! <b>Complexity</b>: Linear to elements contained in *this if,
1523 //! constant-time size option is enabled. Constant-time otherwise.
1525 //! <b>Throws</b>: Nothing.
1526 size_type
size() const
1527 { return tree_
.size(); }
1529 //! <b>Effects</b>: Swaps the contents of two splay_multisets.
1531 //! <b>Complexity</b>: Constant.
1533 //! <b>Throws</b>: If the swap() call for the comparison functor
1534 //! found using ADL throws. Strong guarantee.
1535 void swap(splay_multiset_impl
& other
)
1536 { tree_
.swap(other
.tree_
); }
1538 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1539 //! Cloner should yield to nodes equivalent to the original nodes.
1541 //! <b>Effects</b>: Erases all the elements from *this
1542 //! calling Disposer::operator()(pointer), clones all the
1543 //! elements from src calling Cloner::operator()(const_reference )
1544 //! and inserts them on *this. Copies the predicate from the source container.
1546 //! If cloner throws, all cloned elements are unlinked and disposed
1547 //! calling Disposer::operator()(pointer).
1549 //! <b>Complexity</b>: Linear to erased plus inserted elements.
1551 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
1552 template <class Cloner
, class Disposer
>
1553 void clone_from(const splay_multiset_impl
&src
, Cloner cloner
, Disposer disposer
)
1554 { tree_
.clone_from(src
.tree_
, cloner
, disposer
); }
1556 //! <b>Requires</b>: value must be an lvalue
1558 //! <b>Effects</b>: Inserts value into the splay_multiset.
1560 //! <b>Returns</b>: An iterator that points to the position where the new
1561 //! element was inserted.
1563 //! <b>Complexity</b>: Amortized logarithmic.
1565 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1567 //! <b>Note</b>: Does not affect the validity of iterators and references.
1568 //! No copy-constructors are called.
1569 iterator
insert(reference value
)
1570 { return tree_
.insert_equal(this->end(), value
); }
1572 //! <b>Requires</b>: value must be an lvalue
1574 //! <b>Effects</b>: Inserts x into the splay_multiset, using pos as a hint to
1575 //! where it will be inserted.
1577 //! <b>Returns</b>: An iterator that points to the position where the new
1578 //! element was inserted.
1580 //! <b>Complexity</b>: Amortized logarithmic in general, but it is amortized
1581 //! constant time if t is inserted immediately before hint.
1583 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1585 //! <b>Note</b>: Does not affect the validity of iterators and references.
1586 //! No copy-constructors are called.
1587 iterator
insert(const_iterator hint
, reference value
)
1588 { return tree_
.insert_equal(hint
, value
); }
1590 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
1591 //! of type value_type.
1593 //! <b>Effects</b>: Inserts a range into the splay_multiset.
1595 //! <b>Returns</b>: An iterator that points to the position where the new
1596 //! element was inserted.
1598 //! <b>Complexity</b>: Insert range is amortized O(N * log(N)), where N is the
1599 //! size of the range. However, it is linear in N if the range is already sorted
1600 //! by value_comp().
1602 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1604 //! <b>Note</b>: Does not affect the validity of iterators and references.
1605 //! No copy-constructors are called.
1606 template<class Iterator
>
1607 void insert(Iterator b
, Iterator e
)
1608 { tree_
.insert_equal(b
, e
); }
1610 //! <b>Effects</b>: Erases the element pointed to by pos.
1612 //! <b>Complexity</b>: Average complexity is constant time.
1614 //! <b>Returns</b>: An iterator to the element after the erased element.
1616 //! <b>Throws</b>: Nothing.
1618 //! <b>Note</b>: Invalidates the iterators (but not the references)
1619 //! to the erased elements. No destructors are called.
1620 iterator
erase(const_iterator i
)
1621 { return tree_
.erase(i
); }
1623 //! <b>Effects</b>: Erases the range pointed to by b end e.
1625 //! <b>Returns</b>: An iterator to the element after the erased elements.
1627 //! <b>Complexity</b>: Average complexity for erase range is amortized
1628 //! O(log(size() + N)), where N is the number of elements in the range.
1630 //! <b>Throws</b>: Nothing.
1632 //! <b>Note</b>: Invalidates the iterators (but not the references)
1633 //! to the erased elements. No destructors are called.
1634 iterator
erase(const_iterator b
, const_iterator e
)
1635 { return tree_
.erase(b
, e
); }
1637 //! <b>Effects</b>: Erases all the elements with the given value.
1639 //! <b>Returns</b>: The number of erased elements.
1641 //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)).
1643 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1645 //! <b>Note</b>: Invalidates the iterators (but not the references)
1646 //! to the erased elements. No destructors are called.
1647 size_type
erase(const_reference value
)
1648 { return tree_
.erase(value
); }
1650 //! <b>Effects</b>: Erases all the elements that compare equal with
1651 //! the given key and the given comparison functor.
1653 //! <b>Returns</b>: The number of erased elements.
1655 //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
1657 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1659 //! <b>Note</b>: Invalidates the iterators (but not the references)
1660 //! to the erased elements. No destructors are called.
1661 template<class KeyType
, class KeyValueCompare
>
1662 size_type
erase(const KeyType
& key
, KeyValueCompare comp
1664 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
1667 { return tree_
.erase(key
, comp
); }
1669 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1671 //! <b>Returns</b>: An iterator to the element after the erased element.
1673 //! <b>Effects</b>: Erases the element pointed to by pos.
1674 //! Disposer::operator()(pointer) is called for the removed element.
1676 //! <b>Complexity</b>: Average complexity for erase element is constant time.
1678 //! <b>Throws</b>: Nothing.
1680 //! <b>Note</b>: Invalidates the iterators
1681 //! to the erased elements.
1682 template<class Disposer
>
1683 iterator
erase_and_dispose(const_iterator i
, Disposer disposer
)
1684 { return tree_
.erase_and_dispose(i
, disposer
); }
1686 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1687 template<class Disposer
>
1688 iterator
erase_and_dispose(iterator i
, Disposer disposer
)
1689 { return this->erase_and_dispose(const_iterator(i
), disposer
); }
1692 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1694 //! <b>Returns</b>: An iterator to the element after the erased elements.
1696 //! <b>Effects</b>: Erases the range pointed to by b end e.
1697 //! Disposer::operator()(pointer) is called for the removed elements.
1699 //! <b>Complexity</b>: Average complexity for erase range is amortized
1700 //! O(log(size() + N)), where N is the number of elements in the range.
1702 //! <b>Throws</b>: Nothing.
1704 //! <b>Note</b>: Invalidates the iterators
1705 //! to the erased elements.
1706 template<class Disposer
>
1707 iterator
erase_and_dispose(const_iterator b
, const_iterator e
, Disposer disposer
)
1708 { return tree_
.erase_and_dispose(b
, e
, disposer
); }
1710 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1712 //! <b>Effects</b>: Erases all the elements with the given value.
1713 //! Disposer::operator()(pointer) is called for the removed elements.
1715 //! <b>Returns</b>: The number of erased elements.
1717 //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)).
1719 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1721 //! <b>Note</b>: Invalidates the iterators (but not the references)
1722 //! to the erased elements. No destructors are called.
1723 template<class Disposer
>
1724 size_type
erase_and_dispose(const_reference value
, Disposer disposer
)
1725 { return tree_
.erase_and_dispose(value
, disposer
); }
1727 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1729 //! <b>Effects</b>: Erases all the elements with the given key.
1730 //! according to the comparison functor "comp".
1731 //! Disposer::operator()(pointer) is called for the removed elements.
1733 //! <b>Returns</b>: The number of erased elements.
1735 //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
1737 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1739 //! <b>Note</b>: Invalidates the iterators
1740 //! to the erased elements.
1741 template<class KeyType
, class KeyValueCompare
, class Disposer
>
1742 size_type
erase_and_dispose(const KeyType
& key
, KeyValueCompare comp
, Disposer disposer
1744 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
1747 { return tree_
.erase_and_dispose(key
, comp
, disposer
); }
1749 //! <b>Effects</b>: Erases all the elements of the container.
1751 //! <b>Complexity</b>: Linear to the number of elements on the container.
1752 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1754 //! <b>Throws</b>: Nothing.
1756 //! <b>Note</b>: Invalidates the iterators (but not the references)
1757 //! to the erased elements. No destructors are called.
1759 { return tree_
.clear(); }
1761 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1763 //! <b>Effects</b>: Erases all the elements of the container.
1765 //! <b>Complexity</b>: Linear to the number of elements on the container.
1766 //! Disposer::operator()(pointer) is called for the removed elements.
1768 //! <b>Throws</b>: Nothing.
1770 //! <b>Note</b>: Invalidates the iterators (but not the references)
1771 //! to the erased elements. No destructors are called.
1772 template<class Disposer
>
1773 void clear_and_dispose(Disposer disposer
)
1774 { return tree_
.clear_and_dispose(disposer
); }
1776 //! <b>Effects</b>: Returns the number of contained elements with the given key
1778 //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
1779 //! to number of objects with the given key.
1781 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1782 size_type
count(const_reference value
)
1783 { return tree_
.count(value
); }
1785 //! <b>Effects</b>: Returns the number of contained elements with the same key
1786 //! compared with the given comparison functor.
1788 //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
1789 //! to number of objects with the given key.
1791 //! <b>Throws</b>: If comp ordering function throws.
1792 template<class KeyType
, class KeyValueCompare
>
1793 size_type
count(const KeyType
& key
, KeyValueCompare comp
)
1794 { return tree_
.count(key
, comp
); }
1796 //! <b>Effects</b>: Returns the number of contained elements with the given key
1798 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1799 //! to number of objects with the given key.
1801 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1802 size_type
count_dont_splay(const_reference value
) const
1803 { return tree_
.count_dont_splay(value
); }
1805 //! <b>Effects</b>: Returns the number of contained elements with the same key
1806 //! compared with the given comparison functor.
1808 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1809 //! to number of objects with the given key.
1811 //! <b>Throws</b>: If comp ordering function throws.
1812 template<class KeyType
, class KeyValueCompare
>
1813 size_type
count_dont_splay(const KeyType
& key
, KeyValueCompare comp
) const
1814 { return tree_
.count_dont_splay(key
, comp
); }
1816 //! <b>Effects</b>: Returns an iterator to the first element whose
1817 //! key is not less than k or end() if that element does not exist.
1819 //! <b>Complexity</b>: Amortized logarithmic.
1821 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1822 iterator
lower_bound(const_reference value
)
1823 { return tree_
.lower_bound(value
); }
1825 //! <b>Requires</b>: comp must imply the same element order as
1826 //! value_compare. Usually key is the part of the value_type
1827 //! that is used in the ordering functor.
1829 //! <b>Effects</b>: Returns an iterator to the first element whose
1830 //! key according to the comparison functor is not less than k or
1831 //! end() if that element does not exist.
1833 //! <b>Complexity</b>: Amortized logarithmic.
1835 //! <b>Throws</b>: If comp ordering function throws.
1837 //! <b>Note</b>: This function is used when constructing a value_type
1838 //! is expensive and the value_type can be compared with a cheaper
1839 //! key type. Usually this key is part of the value_type.
1840 template<class KeyType
, class KeyValueCompare
>
1841 iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
)
1842 { return tree_
.lower_bound(key
, comp
); }
1844 //! <b>Effects</b>: Returns a const iterator to the first element whose
1845 //! key is not less than k or end() if that element does not exist.
1847 //! <b>Complexity</b>: Logarithmic.
1849 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1850 const_iterator
lower_bound_dont_splay(const_reference value
) const
1851 { return tree_
.lower_bound_dont_splay(value
); }
1853 //! <b>Requires</b>: comp must imply the same element order as
1854 //! value_compare. Usually key is the part of the value_type
1855 //! that is used in the ordering functor.
1857 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1858 //! key according to the comparison functor is not less than k or
1859 //! end() if that element does not exist.
1861 //! <b>Complexity</b>: Logarithmic.
1863 //! <b>Throws</b>: If comp ordering function throws.
1865 //! <b>Note</b>: This function is used when constructing a value_type
1866 //! is expensive and the value_type can be compared with a cheaper
1867 //! key type. Usually this key is part of the value_type.
1868 template<class KeyType
, class KeyValueCompare
>
1869 const_iterator
lower_bound_dont_splay(const KeyType
& key
, KeyValueCompare comp
) const
1870 { return tree_
.lower_bound_dont_splay(key
, comp
); }
1872 //! <b>Effects</b>: Returns an iterator to the first element whose
1873 //! key is greater than k or end() if that element does not exist.
1875 //! <b>Complexity</b>: Amortized logarithmic.
1877 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1878 iterator
upper_bound(const_reference value
)
1879 { return tree_
.upper_bound(value
); }
1881 //! <b>Requires</b>: comp must imply the same element order as
1882 //! value_compare. Usually key is the part of the value_type
1883 //! that is used in the ordering functor.
1885 //! <b>Effects</b>: Returns an iterator to the first element whose
1886 //! key according to the comparison functor is greater than key or
1887 //! end() if that element does not exist.
1889 //! <b>Complexity</b>: Amortized logarithmic.
1891 //! <b>Throws</b>: If comp ordering function throws.
1893 //! <b>Note</b>: This function is used when constructing a value_type
1894 //! is expensive and the value_type can be compared with a cheaper
1895 //! key type. Usually this key is part of the value_type.
1896 template<class KeyType
, class KeyValueCompare
>
1897 iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
)
1898 { return tree_
.upper_bound(key
, comp
); }
1900 //! <b>Effects</b>: Returns an iterator to the first element whose
1901 //! key is greater than k or end() if that element does not exist.
1903 //! <b>Complexity</b>: Logarithmic.
1905 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1906 const_iterator
upper_bound_dont_splay(const_reference value
) const
1907 { return tree_
.upper_bound_dont_splay(value
); }
1909 //! <b>Requires</b>: comp must imply the same element order as
1910 //! value_compare. Usually key is the part of the value_type
1911 //! that is used in the ordering functor.
1913 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1914 //! key according to the comparison functor is greater than key or
1915 //! end() if that element does not exist.
1917 //! <b>Complexity</b>: Logarithmic.
1919 //! <b>Throws</b>: If comp ordering function throws.
1921 //! <b>Note</b>: This function is used when constructing a value_type
1922 //! is expensive and the value_type can be compared with a cheaper
1923 //! key type. Usually this key is part of the value_type.
1924 template<class KeyType
, class KeyValueCompare
>
1925 const_iterator
upper_bound_dont_splay(const KeyType
& key
, KeyValueCompare comp
) const
1926 { return tree_
.upper_bound_dont_splay(key
, comp
); }
1928 //! <b>Effects</b>: Finds an iterator to the first element whose value is
1929 //! "value" or end() if that element does not exist.
1931 //! <b>Complexity</b>: Amortized logarithmic.
1933 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1934 iterator
find(const_reference value
)
1935 { return tree_
.find(value
); }
1937 //! <b>Requires</b>: comp must imply the same element order as
1938 //! value_compare. Usually key is the part of the value_type
1939 //! that is used in the ordering functor.
1941 //! <b>Effects</b>: Finds an iterator to the first element whose key is
1942 //! "key" according to the comparison functor or end() if that element
1945 //! <b>Complexity</b>: Amortized logarithmic.
1947 //! <b>Throws</b>: If comp ordering function throws.
1949 //! <b>Note</b>: This function is used when constructing a value_type
1950 //! is expensive and the value_type can be compared with a cheaper
1951 //! key type. Usually this key is part of the value_type.
1952 template<class KeyType
, class KeyValueCompare
>
1953 iterator
find(const KeyType
& key
, KeyValueCompare comp
)
1954 { return tree_
.find(key
, comp
); }
1956 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
1957 //! "value" or end() if that element does not exist.
1959 //! <b>Complexity</b>: Logarithmic.
1961 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1962 const_iterator
find_dont_splay(const_reference value
) const
1963 { return tree_
.find_dont_splay(value
); }
1965 //! <b>Requires</b>: comp must imply the same element order as
1966 //! value_compare. Usually key is the part of the value_type
1967 //! that is used in the ordering functor.
1969 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
1970 //! "key" according to the comparison functor or end() if that element
1973 //! <b>Complexity</b>: Logarithmic.
1975 //! <b>Throws</b>: If comp ordering function throws.
1977 //! <b>Note</b>: This function is used when constructing a value_type
1978 //! is expensive and the value_type can be compared with a cheaper
1979 //! key type. Usually this key is part of the value_type.
1980 template<class KeyType
, class KeyValueCompare
>
1981 const_iterator
find_dont_splay(const KeyType
& key
, KeyValueCompare comp
) const
1982 { return tree_
.find_dont_splay(key
, comp
); }
1984 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1985 //! an empty range that indicates the position where those elements would be
1986 //! if they there is no elements with key k.
1988 //! <b>Complexity</b>: Amortized logarithmic.
1990 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1991 std::pair
<iterator
,iterator
> equal_range(const_reference value
)
1992 { return tree_
.equal_range(value
); }
1994 //! <b>Requires</b>: comp must imply the same element order as
1995 //! value_compare. Usually key is the part of the value_type
1996 //! that is used in the ordering functor.
1998 //! <b>Effects</b>: Finds a range containing all elements whose key is k
1999 //! according to the comparison functor or an empty range
2000 //! that indicates the position where those elements would be
2001 //! if they there is no elements with key k.
2003 //! <b>Complexity</b>: Amortized logarithmic.
2005 //! <b>Throws</b>: If comp ordering function throws.
2007 //! <b>Note</b>: This function is used when constructing a value_type
2008 //! is expensive and the value_type can be compared with a cheaper
2009 //! key type. Usually this key is part of the value_type.
2010 template<class KeyType
, class KeyValueCompare
>
2011 std::pair
<iterator
,iterator
> equal_range(const KeyType
& key
, KeyValueCompare comp
)
2012 { return tree_
.equal_range(key
, comp
); }
2014 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
2015 //! an empty range that indicates the position where those elements would be
2016 //! if they there is no elements with key k.
2018 //! <b>Complexity</b>: Logarithmic.
2020 //! <b>Throws</b>: If the internal value_compare ordering function throws.
2021 std::pair
<const_iterator
, const_iterator
>
2022 equal_range_dont_splay(const_reference value
) const
2023 { return tree_
.equal_range_dont_splay(value
); }
2025 //! <b>Requires</b>: comp must imply the same element order as
2026 //! value_compare. Usually key is the part of the value_type
2027 //! that is used in the ordering functor.
2029 //! <b>Effects</b>: Finds a range containing all elements whose key is k
2030 //! according to the comparison functor or an empty range
2031 //! that indicates the position where those elements would be
2032 //! if they there is no elements with key k.
2034 //! <b>Complexity</b>: Logarithmic.
2036 //! <b>Throws</b>: If comp ordering function throws.
2038 //! <b>Note</b>: This function is used when constructing a value_type
2039 //! is expensive and the value_type can be compared with a cheaper
2040 //! key type. Usually this key is part of the value_type.
2041 template<class KeyType
, class KeyValueCompare
>
2042 std::pair
<const_iterator
, const_iterator
>
2043 equal_range_dont_splay(const KeyType
& key
, KeyValueCompare comp
) const
2044 { return tree_
.equal_range_dont_splay(key
, comp
); }
2046 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
2047 //! appropriate type. Otherwise the behavior is undefined.
2049 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
2050 //! that points to the value
2052 //! <b>Complexity</b>: Constant.
2054 //! <b>Throws</b>: Nothing.
2056 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2058 static iterator
s_iterator_to(reference value
)
2059 { return tree_type::s_iterator_to(value
); }
2061 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
2062 //! appropriate type. Otherwise the behavior is undefined.
2064 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2065 //! set that points to the value
2067 //! <b>Complexity</b>: Constant.
2069 //! <b>Throws</b>: Nothing.
2071 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2073 static const_iterator
s_iterator_to(const_reference value
)
2074 { return tree_type::s_iterator_to(value
); }
2076 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
2077 //! appropriate type. Otherwise the behavior is undefined.
2079 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
2080 //! that points to the value
2082 //! <b>Complexity</b>: Constant.
2084 //! <b>Throws</b>: Nothing.
2085 iterator
iterator_to(reference value
)
2086 { return tree_
.iterator_to(value
); }
2088 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
2089 //! appropriate type. Otherwise the behavior is undefined.
2091 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2092 //! set that points to the value
2094 //! <b>Complexity</b>: Constant.
2096 //! <b>Throws</b>: Nothing.
2097 const_iterator
iterator_to(const_reference value
) const
2098 { return tree_
.iterator_to(value
); }
2100 //! <b>Requires</b>: value shall not be in a set/splay_multiset.
2102 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
2105 //! <b>Throws</b>: Nothing.
2107 //! <b>Complexity</b>: Constant time.
2109 //! <b>Note</b>: This function puts the hook in the well-known default state
2110 //! used by auto_unlink and safe hooks.
2111 static void init_node(reference value
)
2112 { tree_type::init_node(value
); }
2114 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
2116 //! <b>Complexity</b>: Average complexity is constant time.
2118 //! <b>Throws</b>: Nothing.
2120 //! <b>Notes</b>: This function breaks the tree and the tree can
2121 //! only be used for more unlink_leftmost_without_rebalance calls.
2122 //! This function is normally used to achieve a step by step
2123 //! controlled destruction of the tree.
2124 pointer
unlink_leftmost_without_rebalance()
2125 { return tree_
.unlink_leftmost_without_rebalance(); }
2127 //! <b>Requires</b>: replace_this must be a valid iterator of *this
2128 //! and with_this must not be inserted in any tree.
2130 //! <b>Effects</b>: Replaces replace_this in its position in the
2131 //! tree with with_this. The tree does not need to be rebalanced.
2133 //! <b>Complexity</b>: Constant.
2135 //! <b>Throws</b>: Nothing.
2137 //! <b>Note</b>: This function will break container ordering invariants if
2138 //! with_this is not equivalent to *replace_this according to the
2139 //! ordering rules. This function is faster than erasing and inserting
2140 //! the node, since no rebalancing or comparison is needed.
2141 void replace_node(iterator replace_this
, reference with_this
)
2142 { tree_
.replace_node(replace_this
, with_this
); }
2144 //! <b>Requires</b>: i must be a valid iterator of *this.
2146 //! <b>Effects</b>: Rearranges the splay set so that the element pointed by i
2147 //! is placed as the root of the tree, improving future searches of this value.
2149 //! <b>Complexity</b>: Amortized logarithmic.
2151 //! <b>Throws</b>: Nothing.
2152 void splay_up(iterator i
)
2153 { tree_
.splay_up(i
); }
2155 //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
2156 //! with a key equivalent to value the element is placed as the root of the
2157 //! tree. If the element is not present returns the last node compared with the key.
2158 //! If the tree is empty, end() is returned.
2160 //! <b>Complexity</b>: Amortized logarithmic.
2162 //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
2164 //! <b>Throws</b>: If the comparison functor throws.
2165 template<class KeyType
, class KeyNodePtrCompare
>
2166 iterator
splay_down(const KeyType
&key
, KeyNodePtrCompare comp
)
2167 { return tree_
.splay_down(key
, comp
); }
2169 //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
2170 //! with a key equivalent to value the element is placed as the root of the
2173 //! <b>Complexity</b>: Amortized logarithmic.
2175 //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
2177 //! <b>Throws</b>: If the predicate throws.
2178 iterator
splay_down(const value_type
&value
)
2179 { return tree_
.splay_down(value
); }
2181 //! <b>Effects</b>: Rebalances the tree.
2183 //! <b>Throws</b>: Nothing.
2185 //! <b>Complexity</b>: Linear.
2187 { tree_
.rebalance(); }
2189 //! <b>Requires</b>: old_root is a node of a tree.
2191 //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
2193 //! <b>Returns</b>: The new root of the subtree.
2195 //! <b>Throws</b>: Nothing.
2197 //! <b>Complexity</b>: Linear to the elements in the subtree.
2198 iterator
rebalance_subtree(iterator root
)
2199 { return tree_
.rebalance_subtree(root
); }
2202 friend bool operator==(const splay_multiset_impl
&x
, const splay_multiset_impl
&y
)
2203 { return x
.tree_
== y
.tree_
; }
2205 friend bool operator<(const splay_multiset_impl
&x
, const splay_multiset_impl
&y
)
2206 { return x
.tree_
< y
.tree_
; }
2210 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2211 template<class T
, class ...Options
>
2213 template<class Config
>
2215 inline bool operator!=
2216 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2217 (const splay_multiset_impl
<T
, Options
...> &x
, const splay_multiset_impl
<T
, Options
...> &y
)
2219 (const splay_multiset_impl
<Config
> &x
, const splay_multiset_impl
<Config
> &y
)
2221 { return !(x
== y
); }
2223 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2224 template<class T
, class ...Options
>
2226 template<class Config
>
2228 inline bool operator>
2229 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2230 (const splay_multiset_impl
<T
, Options
...> &x
, const splay_multiset_impl
<T
, Options
...> &y
)
2232 (const splay_multiset_impl
<Config
> &x
, const splay_multiset_impl
<Config
> &y
)
2236 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2237 template<class T
, class ...Options
>
2239 template<class Config
>
2241 inline bool operator<=
2242 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2243 (const splay_multiset_impl
<T
, Options
...> &x
, const splay_multiset_impl
<T
, Options
...> &y
)
2245 (const splay_multiset_impl
<Config
> &x
, const splay_multiset_impl
<Config
> &y
)
2247 { return !(y
< x
); }
2249 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2250 template<class T
, class ...Options
>
2252 template<class Config
>
2254 inline bool operator>=
2255 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2256 (const splay_multiset_impl
<T
, Options
...> &x
, const splay_multiset_impl
<T
, Options
...> &y
)
2258 (const splay_multiset_impl
<Config
> &x
, const splay_multiset_impl
<Config
> &y
)
2260 { return !(x
< y
); }
2262 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2263 template<class T
, class ...Options
>
2265 template<class Config
>
2268 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2269 (splay_multiset_impl
<T
, Options
...> &x
, splay_multiset_impl
<T
, Options
...> &y
)
2271 (splay_multiset_impl
<Config
> &x
, splay_multiset_impl
<Config
> &y
)
2275 //! Helper metafunction to define a \c splay_multiset that yields to the same type when the
2276 //! same options (either explicitly or implicitly) are used.
2277 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2278 template<class T
, class ...Options
>
2280 template<class T
, class O1
= none
, class O2
= none
2281 , class O3
= none
, class O4
= none
>
2283 struct make_splay_multiset
2286 typedef splay_multiset_impl
2287 < typename make_splaytree_opt
<T
,
2288 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2294 > implementation_defined
;
2296 typedef implementation_defined type
;
2299 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
2301 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2302 template<class T
, class O1
, class O2
, class O3
, class O4
>
2304 template<class T
, class ...Options
>
2306 class splay_multiset
2307 : public make_splay_multiset
<T
,
2308 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2315 typedef typename make_splay_multiset
2317 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2325 typedef typename
Base::value_compare value_compare
;
2326 typedef typename
Base::value_traits value_traits
;
2327 typedef typename
Base::iterator iterator
;
2328 typedef typename
Base::const_iterator const_iterator
;
2330 //Assert if passed value traits are compatible with the type
2331 BOOST_STATIC_ASSERT((detail::is_same
<typename
value_traits::value_type
, T
>::value
));
2333 splay_multiset( const value_compare
&cmp
= value_compare()
2334 , const value_traits
&v_traits
= value_traits())
2335 : Base(cmp
, v_traits
)
2338 template<class Iterator
>
2339 splay_multiset( Iterator b
, Iterator e
2340 , const value_compare
&cmp
= value_compare()
2341 , const value_traits
&v_traits
= value_traits())
2342 : Base(b
, e
, cmp
, v_traits
)
2345 static splay_multiset
&container_from_end_iterator(iterator end_iterator
)
2346 { return static_cast<splay_multiset
&>(Base::container_from_end_iterator(end_iterator
)); }
2348 static const splay_multiset
&container_from_end_iterator(const_iterator end_iterator
)
2349 { return static_cast<const splay_multiset
&>(Base::container_from_end_iterator(end_iterator
)); }
2351 static splay_multiset
&container_from_iterator(iterator it
)
2352 { return static_cast<splay_multiset
&>(Base::container_from_iterator(it
)); }
2354 static const splay_multiset
&container_from_iterator(const_iterator it
)
2355 { return static_cast<const splay_multiset
&>(Base::container_from_iterator(it
)); }
2360 } //namespace intrusive
2363 #include <boost/intrusive/detail/config_end.hpp>
2365 #endif //BOOST_INTRUSIVE_SPLAY_SET_HPP