fix doc example typo
[boost.git] / boost / intrusive / splay_set.hpp
blob79bdbc1c7082c38d3a3c612606914d6a6e111fe1
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2007-2008
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/intrusive for documentation.
11 /////////////////////////////////////////////////////////////////////////////
12 #ifndef BOOST_INTRUSIVE_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>
19 #include <iterator>
21 namespace boost {
22 namespace intrusive {
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.
26 //!
27 //! The template parameter \c T is the type to be managed by the container.
28 //! The user can specify additional options and if no options are provided
29 //! default options are used.
30 //!
31 //! The container supports the following options:
32 //! \c base_hook<>/member_hook<>/value_traits<>,
33 //! \c constant_time_size<>, \c size_type<> and
34 //! \c compare<>.
35 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
36 template<class T, class ...Options>
37 #else
38 template<class Config>
39 #endif
40 class splay_set_impl
42 /// @cond
43 typedef splaytree_impl<Config> tree_type;
44 //! This class is
45 //! non-copyable
46 splay_set_impl (const splay_set_impl&);
48 //! This class is
49 //! non-assignable
50 splay_set_impl &operator =(const splay_set_impl&);
52 typedef tree_type implementation_defined;
53 /// @endcond
55 public:
56 typedef typename implementation_defined::value_type value_type;
57 typedef typename implementation_defined::value_traits value_traits;
58 typedef typename implementation_defined::pointer pointer;
59 typedef typename implementation_defined::const_pointer const_pointer;
60 typedef typename implementation_defined::reference reference;
61 typedef typename implementation_defined::const_reference const_reference;
62 typedef typename implementation_defined::difference_type difference_type;
63 typedef typename implementation_defined::size_type size_type;
64 typedef typename implementation_defined::value_compare value_compare;
65 typedef typename implementation_defined::key_compare key_compare;
66 typedef typename implementation_defined::iterator iterator;
67 typedef typename implementation_defined::const_iterator const_iterator;
68 typedef typename implementation_defined::reverse_iterator reverse_iterator;
69 typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
70 typedef typename implementation_defined::insert_commit_data insert_commit_data;
71 typedef typename implementation_defined::node_traits node_traits;
72 typedef typename implementation_defined::node node;
73 typedef typename implementation_defined::node_ptr node_ptr;
74 typedef typename implementation_defined::const_node_ptr const_node_ptr;
75 typedef typename implementation_defined::node_algorithms node_algorithms;
77 /// @cond
78 private:
79 tree_type tree_;
80 /// @endcond
82 public:
83 //! <b>Effects</b>: Constructs an empty splay_set.
84 //!
85 //! <b>Complexity</b>: Constant.
86 //!
87 //! <b>Throws</b>: If value_traits::node_traits::node
88 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
89 //! or the copy constructor of the value_compare object throws.
90 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.
97 //!
98 //! <b>Effects</b>: Constructs an empty splay_set and inserts elements from
99 //! [b, e).
100 //!
101 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
102 //! comp and otherwise amortized N * log N, where N is std::distance(last, first).
103 //!
104 //! <b>Throws</b>: If value_traits::node_traits::node
105 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
106 //! or the copy constructor/operator() of the value_compare object throws.
107 template<class Iterator>
108 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).
116 //!
117 //! <b>Complexity</b>: Linear to the number of elements on the container.
118 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
119 //!
120 //! <b>Throws</b>: Nothing.
121 ~splay_set_impl()
124 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the splay_set.
125 //!
126 //! <b>Complexity</b>: Constant.
127 //!
128 //! <b>Throws</b>: Nothing.
129 iterator begin()
130 { return tree_.begin(); }
132 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_set.
133 //!
134 //! <b>Complexity</b>: Constant.
135 //!
136 //! <b>Throws</b>: Nothing.
137 const_iterator begin() const
138 { return tree_.begin(); }
140 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_set.
141 //!
142 //! <b>Complexity</b>: Constant.
143 //!
144 //! <b>Throws</b>: Nothing.
145 const_iterator cbegin() const
146 { return tree_.cbegin(); }
148 //! <b>Effects</b>: Returns an iterator pointing to the end of the splay_set.
149 //!
150 //! <b>Complexity</b>: Constant.
151 //!
152 //! <b>Throws</b>: Nothing.
153 iterator end()
154 { return tree_.end(); }
156 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_set.
157 //!
158 //! <b>Complexity</b>: Constant.
159 //!
160 //! <b>Throws</b>: Nothing.
161 const_iterator end() const
162 { return tree_.end(); }
164 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_set.
165 //!
166 //! <b>Complexity</b>: Constant.
167 //!
168 //! <b>Throws</b>: Nothing.
169 const_iterator cend() const
170 { return tree_.cend(); }
172 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
173 //! reversed splay_set.
174 //!
175 //! <b>Complexity</b>: Constant.
176 //!
177 //! <b>Throws</b>: Nothing.
178 reverse_iterator rbegin()
179 { return tree_.rbegin(); }
181 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
182 //! of the reversed splay_set.
183 //!
184 //! <b>Complexity</b>: Constant.
185 //!
186 //! <b>Throws</b>: Nothing.
187 const_reverse_iterator rbegin() const
188 { return tree_.rbegin(); }
190 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
191 //! of the reversed splay_set.
192 //!
193 //! <b>Complexity</b>: Constant.
194 //!
195 //! <b>Throws</b>: Nothing.
196 const_reverse_iterator crbegin() const
197 { return tree_.crbegin(); }
199 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
200 //! of the reversed splay_set.
201 //!
202 //! <b>Complexity</b>: Constant.
203 //!
204 //! <b>Throws</b>: Nothing.
205 reverse_iterator rend()
206 { return tree_.rend(); }
208 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
209 //! of the reversed splay_set.
210 //!
211 //! <b>Complexity</b>: Constant.
212 //!
213 //! <b>Throws</b>: Nothing.
214 const_reverse_iterator rend() const
215 { return tree_.rend(); }
217 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
218 //! of the reversed splay_set.
219 //!
220 //! <b>Complexity</b>: Constant.
221 //!
222 //! <b>Throws</b>: Nothing.
223 const_reverse_iterator crend() const
224 { return tree_.crend(); }
226 //! <b>Precondition</b>: end_iterator must be a valid end iterator
227 //! of splay_set.
228 //!
229 //! <b>Effects</b>: Returns a const reference to the splay_set associated to the end iterator
230 //!
231 //! <b>Throws</b>: Nothing.
232 //!
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
242 //! of splay_set.
243 //!
244 //! <b>Effects</b>: Returns a const reference to the splay_set associated to the end iterator
245 //!
246 //! <b>Throws</b>: Nothing.
247 //!
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.
257 //!
258 //! <b>Effects</b>: Returns a reference to the set associated to the iterator
259 //!
260 //! <b>Throws</b>: Nothing.
261 //!
262 //! <b>Complexity</b>: 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.
271 //!
272 //! <b>Effects</b>: Returns a const reference to the set associated to the iterator
273 //!
274 //! <b>Throws</b>: Nothing.
275 //!
276 //! <b>Complexity</b>: Logarithmic.
277 static const 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.
285 //!
286 //! <b>Complexity</b>: Constant.
287 //!
288 //! <b>Throws</b>: If key_compare copy-constructor throws.
289 key_compare key_comp() const
290 { return tree_.value_comp(); }
292 //! <b>Effects</b>: Returns the value_compare object used by the splay_set.
293 //!
294 //! <b>Complexity</b>: Constant.
295 //!
296 //! <b>Throws</b>: If value_compare copy-constructor throws.
297 value_compare value_comp() const
298 { return tree_.value_comp(); }
300 //! <b>Effects</b>: Returns true if the container is empty.
301 //!
302 //! <b>Complexity</b>: Constant.
303 //!
304 //! <b>Throws</b>: Nothing.
305 bool empty() const
306 { return tree_.empty(); }
308 //! <b>Effects</b>: Returns the number of elements stored in the splay_set.
309 //!
310 //! <b>Complexity</b>: Linear to elements contained in *this if,
311 //! constant-time size option is enabled. Constant-time otherwise.
312 //!
313 //! <b>Throws</b>: Nothing.
314 size_type size() const
315 { return tree_.size(); }
317 //! <b>Effects</b>: Swaps the contents of two splay_sets.
318 //!
319 //! <b>Complexity</b>: Constant.
320 //!
321 //! <b>Throws</b>: If the swap() call for the comparison functor
322 //! found using ADL throws. Strong guarantee.
323 void swap(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).
336 //!
337 //! <b>Complexity</b>: Linear to erased plus inserted elements.
338 //!
339 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
340 template <class Cloner, class Disposer>
341 void clone_from(const 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
345 //!
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
352 //! and false.
353 //!
354 //! <b>Complexity</b>: Amortized logarithmic.
355 //!
356 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
357 //!
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
364 //!
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.
370 //!
371 //! <b>Complexity</b>: Amortized logarithmic in general, but it's amortized
372 //! constant time if t is inserted immediately before hint.
373 //!
374 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
375 //!
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.
384 //!
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.
393 //!
394 //! <b>Complexity</b>: Amortized logarithmic.
396 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
397 //!
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.
419 //!
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.
429 //!
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.
434 //!
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)).
445 //!
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".
458 //!
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.
463 //!
464 //! <b>Complexity</b>: Constant time.
466 //! <b>Throws</b>: Nothing.
467 //!
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.
476 //!
477 //! <b>Effects</b>: Inserts a range into the splay_set.
478 //!
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
481 //! by value_comp().
482 //!
483 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
484 //!
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.
492 //!
493 //! <b>Complexity</b>: Average complexity is constant time.
494 //!
495 //! <b>Returns</b>: An iterator to the element after the erased element.
497 //! <b>Throws</b>: Nothing.
498 //!
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.
505 //!
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.
508 //!
509 //! <b>Returns</b>: An iterator to the element after the erased elements.
510 //!
511 //! <b>Throws</b>: Nothing.
512 //!
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.
519 //!
520 //! <b>Returns</b>: The number of erased elements.
521 //!
522 //! <b>Complexity</b>: Amortized O(log(size()) + this->count(value)).
523 //!
524 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
525 //!
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.
533 //!
534 //! <b>Returns</b>: The number of erased elements.
535 //!
536 //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
537 //!
538 //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee.
539 //!
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
544 /// @cond
545 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
546 /// @endcond
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.
554 //!
555 //! <b>Complexity</b>: Average complexity for erase element is constant time.
556 //!
557 //! <b>Returns</b>: An iterator to the element after the erased element.
558 //!
559 //! <b>Throws</b>: Nothing.
560 //!
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); }
571 #endif
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.
577 //!
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.
580 //!
581 //! <b>Returns</b>: An iterator to the element after the erased elements.
582 //!
583 //! <b>Throws</b>: Nothing.
584 //!
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.
595 //!
596 //! <b>Throws</b>: If the internal value_compare ordering function throws.
597 //!
598 //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)). Basic guarantee.
599 //!
600 //! <b>Throws</b>: Nothing.
601 //!
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.
615 //!
616 //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
617 //!
618 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
619 //!
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
624 /// @cond
625 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
626 /// @endcond
628 { return tree_.erase_and_dispose(key, comp, disposer); }
630 //! <b>Effects</b>: Erases all the elements of the container.
631 //!
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.
634 //!
635 //! <b>Throws</b>: Nothing.
636 //!
637 //! <b>Note</b>: Invalidates the iterators (but not the references)
638 //! to the erased elements. No destructors are called.
639 void clear()
640 { return tree_.clear(); }
642 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
643 //!
644 //! <b>Effects</b>: Erases all the elements of the container.
645 //!
646 //! <b>Complexity</b>: Linear to the number of elements on the container.
647 //! Disposer::operator()(pointer) is called for the removed elements.
648 //!
649 //! <b>Throws</b>: Nothing.
650 //!
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
658 //!
659 //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
660 //! to number of objects with the given key.
661 //!
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.
668 //!
669 //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
670 //! to number of objects with the given key.
671 //!
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
678 //!
679 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
680 //! to number of objects with the given key.
681 //!
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.
688 //!
689 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
690 //! to number of objects with the given key.
691 //!
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.
699 //!
700 //! <b>Complexity</b>: Amortized logarithmic.
701 //!
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.
713 //!
714 //! <b>Complexity</b>: Amortized logarithmic.
715 //!
716 //! <b>Throws</b>: If comp ordering function throws.
717 //!
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.
727 //!
728 //! <b>Complexity</b>: Logarithmic.
729 //!
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.
741 //!
742 //! <b>Complexity</b>: Logarithmic.
743 //!
744 //! <b>Throws</b>: If comp ordering function throws.
745 //!
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.
755 //!
756 //! <b>Complexity</b>: Amortized logarithmic.
757 //!
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.
769 //!
770 //! <b>Complexity</b>: Amortized logarithmic.
771 //!
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.
783 //!
784 //! <b>Complexity</b>: Logarithmic.
785 //!
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.
797 //!
798 //! <b>Complexity</b>: Logarithmic.
799 //!
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.
813 //!
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
824 //! does not exist.
826 //! <b>Complexity</b>: Amortized logarithmic.
827 //!
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.
839 //!
840 //! <b>Complexity</b>: Logarithmic.
841 //!
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
852 //! does not exist.
853 //!
854 //! <b>Complexity</b>: Logarithmic.
855 //!
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.
868 //!
869 //! <b>Complexity</b>: Amortized logarithmic.
870 //!
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.
883 //!
884 //! <b>Complexity</b>: Amortized logarithmic.
885 //!
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.
898 //!
899 //! <b>Complexity</b>: Logarithmic.
900 //!
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.
914 //!
915 //! <b>Complexity</b>: Logarithmic.
916 //!
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.
929 //!
930 //! <b>Effects</b>: Returns: a valid iterator i belonging to the splay_set
931 //! that points to the value
932 //!
933 //! <b>Complexity</b>: Constant.
934 //!
935 //! <b>Throws</b>: Nothing.
936 //!
937 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
938 //! is stateless.
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.
944 //!
945 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
946 //! splay_set that points to the value
947 //!
948 //! <b>Complexity</b>: Constant.
949 //!
950 //! <b>Throws</b>: Nothing.
951 //!
952 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
953 //! is stateless.
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.
959 //!
960 //! <b>Effects</b>: Returns: a valid iterator i belonging to the splay_set
961 //! that points to the value
962 //!
963 //! <b>Complexity</b>: Constant.
964 //!
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.
971 //!
972 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
973 //! splay_set that points to the value
974 //!
975 //! <b>Complexity</b>: Constant.
976 //!
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.
982 //!
983 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
984 //! state.
985 //!
986 //! <b>Throws</b>: Nothing.
987 //!
988 //! <b>Complexity</b>: Constant time.
989 //!
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.
996 //!
997 //! <b>Complexity</b>: Average complexity is constant time.
998 //!
999 //! <b>Throws</b>: Nothing.
1000 //!
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.
1010 //!
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.
1013 //!
1014 //! <b>Complexity</b>: Constant.
1015 //!
1016 //! <b>Throws</b>: Nothing.
1017 //!
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.
1026 //!
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.
1029 //!
1030 //! <b>Complexity</b>: Amortized logarithmic.
1031 //!
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.
1040 //!
1041 //! <b>Complexity</b>: Amortized logarithmic.
1042 //!
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
1052 //! tree.
1053 //!
1054 //! <b>Complexity</b>: Amortized logarithmic.
1055 //!
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.
1063 //!
1064 //! <b>Throws</b>: Nothing.
1065 //!
1066 //! <b>Complexity</b>: Linear.
1067 void rebalance()
1068 { tree_.rebalance(); }
1070 //! <b>Requires</b>: old_root is a node of a tree.
1071 //!
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.
1077 //!
1078 //! <b>Complexity</b>: Linear to the elements in the subtree.
1079 iterator rebalance_subtree(iterator root)
1080 { return tree_.rebalance_subtree(root); }
1082 /// @cond
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_; }
1088 /// @endcond
1091 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1092 template<class T, class ...Options>
1093 #else
1094 template<class Config>
1095 #endif
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)
1099 #else
1100 (const splay_set_impl<Config> &x, const splay_set_impl<Config> &y)
1101 #endif
1102 { return !(x == y); }
1104 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1105 template<class T, class ...Options>
1106 #else
1107 template<class Config>
1108 #endif
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)
1112 #else
1113 (const splay_set_impl<Config> &x, const splay_set_impl<Config> &y)
1114 #endif
1115 { return y < x; }
1117 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1118 template<class T, class ...Options>
1119 #else
1120 template<class Config>
1121 #endif
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)
1125 #else
1126 (const splay_set_impl<Config> &x, const splay_set_impl<Config> &y)
1127 #endif
1128 { return !(y < x); }
1130 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1131 template<class T, class ...Options>
1132 #else
1133 template<class Config>
1134 #endif
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)
1138 #else
1139 (const splay_set_impl<Config> &x, const splay_set_impl<Config> &y)
1140 #endif
1141 { return !(x < y); }
1143 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1144 template<class T, class ...Options>
1145 #else
1146 template<class Config>
1147 #endif
1148 inline void swap
1149 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1150 (splay_set_impl<T, Options...> &x, splay_set_impl<T, Options...> &y)
1151 #else
1152 (splay_set_impl<Config> &x, splay_set_impl<Config> &y)
1153 #endif
1154 { x.swap(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>
1160 #else
1161 template<class T, class O1 = none, class O2 = none
1162 , class O3 = none, class O4 = none>
1163 #endif
1164 struct make_splay_set
1166 /// @cond
1167 typedef splay_set_impl
1168 < typename make_splaytree_opt<T,
1169 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1170 O1, O2, O3, O4
1171 #else
1172 Options...
1173 #endif
1174 >::type
1175 > implementation_defined;
1176 /// @endcond
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>
1183 #else
1184 template<class T, class ...Options>
1185 #endif
1186 class splay_set
1187 : public make_splay_set<T,
1188 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1189 O1, O2, O3, O4
1190 #else
1191 Options...
1192 #endif
1193 >::type
1195 typedef typename make_splay_set
1196 <T,
1197 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1198 O1, O2, O3, O4
1199 #else
1200 Options...
1201 #endif
1202 >::type Base;
1204 public:
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)); }
1238 #endif
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.
1242 //!
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
1250 //! \c compare<>.
1251 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1252 template<class T, class ...Options>
1253 #else
1254 template<class Config>
1255 #endif
1256 class splay_multiset_impl
1258 /// @cond
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;
1265 /// @endcond
1267 public:
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;
1289 /// @cond
1290 private:
1291 tree_type tree_;
1292 /// @endcond
1294 public:
1295 //! <b>Effects</b>: Constructs an empty splay_multiset.
1296 //!
1297 //! <b>Complexity</b>: Constant.
1298 //!
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.
1309 //!
1310 //! <b>Effects</b>: Constructs an empty splay_multiset and inserts elements from
1311 //! [b, e).
1312 //!
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.
1315 //!
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).
1328 //!
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.
1331 //!
1332 //! <b>Throws</b>: Nothing.
1333 ~splay_multiset_impl()
1336 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the splay_multiset.
1337 //!
1338 //! <b>Complexity</b>: Constant.
1339 //!
1340 //! <b>Throws</b>: Nothing.
1341 iterator begin()
1342 { return tree_.begin(); }
1344 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_multiset.
1345 //!
1346 //! <b>Complexity</b>: Constant.
1347 //!
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.
1353 //!
1354 //! <b>Complexity</b>: Constant.
1355 //!
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.
1361 //!
1362 //! <b>Complexity</b>: Constant.
1363 //!
1364 //! <b>Throws</b>: Nothing.
1365 iterator end()
1366 { return tree_.end(); }
1368 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_multiset.
1369 //!
1370 //! <b>Complexity</b>: Constant.
1371 //!
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.
1377 //!
1378 //! <b>Complexity</b>: Constant.
1379 //!
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.
1386 //!
1387 //! <b>Complexity</b>: Constant.
1388 //!
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.
1395 //!
1396 //! <b>Complexity</b>: Constant.
1397 //!
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.
1404 //!
1405 //! <b>Complexity</b>: Constant.
1406 //!
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.
1413 //!
1414 //! <b>Complexity</b>: Constant.
1415 //!
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.
1422 //!
1423 //! <b>Complexity</b>: Constant.
1424 //!
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.
1431 //!
1432 //! <b>Complexity</b>: Constant.
1433 //!
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.
1440 //!
1441 //! <b>Effects</b>: Returns a const reference to the splay_multiset associated to the end iterator
1442 //!
1443 //! <b>Throws</b>: Nothing.
1444 //!
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.
1455 //!
1456 //! <b>Effects</b>: Returns a const reference to the splay_multiset associated to the end iterator
1457 //!
1458 //! <b>Throws</b>: Nothing.
1459 //!
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.
1469 //!
1470 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1471 //!
1472 //! <b>Throws</b>: Nothing.
1473 //!
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.
1483 //!
1484 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1485 //!
1486 //! <b>Throws</b>: Nothing.
1487 //!
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.
1497 //!
1498 //! <b>Complexity</b>: Constant.
1499 //!
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.
1505 //!
1506 //! <b>Complexity</b>: Constant.
1507 //!
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.
1513 //!
1514 //! <b>Complexity</b>: Constant.
1515 //!
1516 //! <b>Throws</b>: Nothing.
1517 bool empty() const
1518 { return tree_.empty(); }
1520 //! <b>Effects</b>: Returns the number of elements stored in the splay_multiset.
1521 //!
1522 //! <b>Complexity</b>: Linear to elements contained in *this if,
1523 //! constant-time size option is enabled. Constant-time otherwise.
1524 //!
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.
1530 //!
1531 //! <b>Complexity</b>: Constant.
1532 //!
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).
1548 //!
1549 //! <b>Complexity</b>: Linear to erased plus inserted elements.
1550 //!
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
1557 //!
1558 //! <b>Effects</b>: Inserts value into the splay_multiset.
1559 //!
1560 //! <b>Returns</b>: An iterator that points to the position where the new
1561 //! element was inserted.
1562 //!
1563 //! <b>Complexity</b>: Amortized logarithmic.
1564 //!
1565 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1566 //!
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
1573 //!
1574 //! <b>Effects</b>: Inserts x into the splay_multiset, using pos as a hint to
1575 //! where it will be inserted.
1576 //!
1577 //! <b>Returns</b>: An iterator that points to the position where the new
1578 //! element was inserted.
1579 //!
1580 //! <b>Complexity</b>: Amortized logarithmic in general, but it is amortized
1581 //! constant time if t is inserted immediately before hint.
1582 //!
1583 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1584 //!
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.
1592 //!
1593 //! <b>Effects</b>: Inserts a range into the splay_multiset.
1594 //!
1595 //! <b>Returns</b>: An iterator that points to the position where the new
1596 //! element was inserted.
1597 //!
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().
1601 //!
1602 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1603 //!
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.
1611 //!
1612 //! <b>Complexity</b>: Average complexity is constant time.
1613 //!
1614 //! <b>Returns</b>: An iterator to the element after the erased element.
1616 //! <b>Throws</b>: Nothing.
1617 //!
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.
1626 //!
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.
1629 //!
1630 //! <b>Throws</b>: Nothing.
1631 //!
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.
1638 //!
1639 //! <b>Returns</b>: The number of erased elements.
1640 //!
1641 //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)).
1642 //!
1643 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1644 //!
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.
1652 //!
1653 //! <b>Returns</b>: The number of erased elements.
1654 //!
1655 //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
1656 //!
1657 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1658 //!
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
1663 /// @cond
1664 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
1665 /// @endcond
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.
1675 //!
1676 //! <b>Complexity</b>: Average complexity for erase element is constant time.
1677 //!
1678 //! <b>Throws</b>: Nothing.
1679 //!
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); }
1690 #endif
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.
1698 //!
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.
1701 //!
1702 //! <b>Throws</b>: Nothing.
1703 //!
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.
1714 //!
1715 //! <b>Returns</b>: The number of erased elements.
1716 //!
1717 //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)).
1718 //!
1719 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1720 //!
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.
1734 //!
1735 //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
1736 //!
1737 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1738 //!
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
1743 /// @cond
1744 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
1745 /// @endcond
1747 { return tree_.erase_and_dispose(key, comp, disposer); }
1749 //! <b>Effects</b>: Erases all the elements of the container.
1750 //!
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.
1753 //!
1754 //! <b>Throws</b>: Nothing.
1755 //!
1756 //! <b>Note</b>: Invalidates the iterators (but not the references)
1757 //! to the erased elements. No destructors are called.
1758 void clear()
1759 { return tree_.clear(); }
1761 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1762 //!
1763 //! <b>Effects</b>: Erases all the elements of the container.
1764 //!
1765 //! <b>Complexity</b>: Linear to the number of elements on the container.
1766 //! Disposer::operator()(pointer) is called for the removed elements.
1767 //!
1768 //! <b>Throws</b>: Nothing.
1769 //!
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
1777 //!
1778 //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
1779 //! to number of objects with the given key.
1780 //!
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.
1787 //!
1788 //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
1789 //! to number of objects with the given key.
1790 //!
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
1797 //!
1798 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1799 //! to number of objects with the given key.
1800 //!
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.
1807 //!
1808 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1809 //! to number of objects with the given key.
1810 //!
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.
1818 //!
1819 //! <b>Complexity</b>: Amortized logarithmic.
1820 //!
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.
1832 //!
1833 //! <b>Complexity</b>: Amortized logarithmic.
1834 //!
1835 //! <b>Throws</b>: If comp ordering function throws.
1836 //!
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.
1846 //!
1847 //! <b>Complexity</b>: Logarithmic.
1848 //!
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.
1860 //!
1861 //! <b>Complexity</b>: Logarithmic.
1862 //!
1863 //! <b>Throws</b>: If comp ordering function throws.
1864 //!
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.
1874 //!
1875 //! <b>Complexity</b>: Amortized logarithmic.
1876 //!
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.
1888 //!
1889 //! <b>Complexity</b>: Amortized logarithmic.
1890 //!
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.
1902 //!
1903 //! <b>Complexity</b>: Logarithmic.
1904 //!
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.
1916 //!
1917 //! <b>Complexity</b>: Logarithmic.
1918 //!
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.
1932 //!
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
1943 //! does not exist.
1945 //! <b>Complexity</b>: Amortized logarithmic.
1946 //!
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.
1958 //!
1959 //! <b>Complexity</b>: Logarithmic.
1960 //!
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
1971 //! does not exist.
1972 //!
1973 //! <b>Complexity</b>: Logarithmic.
1974 //!
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.
1987 //!
1988 //! <b>Complexity</b>: Amortized logarithmic.
1989 //!
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.
2002 //!
2003 //! <b>Complexity</b>: Amortized logarithmic.
2004 //!
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.
2017 //!
2018 //! <b>Complexity</b>: Logarithmic.
2019 //!
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.
2033 //!
2034 //! <b>Complexity</b>: Logarithmic.
2035 //!
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.
2048 //!
2049 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
2050 //! that points to the value
2051 //!
2052 //! <b>Complexity</b>: Constant.
2053 //!
2054 //! <b>Throws</b>: Nothing.
2055 //!
2056 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2057 //! is stateless.
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.
2063 //!
2064 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2065 //! set that points to the value
2066 //!
2067 //! <b>Complexity</b>: Constant.
2068 //!
2069 //! <b>Throws</b>: Nothing.
2070 //!
2071 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2072 //! is stateless.
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.
2078 //!
2079 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
2080 //! that points to the value
2081 //!
2082 //! <b>Complexity</b>: Constant.
2083 //!
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.
2090 //!
2091 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
2092 //! set that points to the value
2093 //!
2094 //! <b>Complexity</b>: Constant.
2095 //!
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.
2101 //!
2102 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
2103 //! state.
2104 //!
2105 //! <b>Throws</b>: Nothing.
2106 //!
2107 //! <b>Complexity</b>: Constant time.
2108 //!
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.
2115 //!
2116 //! <b>Complexity</b>: Average complexity is constant time.
2117 //!
2118 //! <b>Throws</b>: Nothing.
2119 //!
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.
2129 //!
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.
2132 //!
2133 //! <b>Complexity</b>: Constant.
2134 //!
2135 //! <b>Throws</b>: Nothing.
2136 //!
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.
2145 //!
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.
2148 //!
2149 //! <b>Complexity</b>: Amortized logarithmic.
2150 //!
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.
2159 //!
2160 //! <b>Complexity</b>: Amortized logarithmic.
2161 //!
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
2171 //! tree.
2172 //!
2173 //! <b>Complexity</b>: Amortized logarithmic.
2174 //!
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.
2182 //!
2183 //! <b>Throws</b>: Nothing.
2184 //!
2185 //! <b>Complexity</b>: Linear.
2186 void rebalance()
2187 { tree_.rebalance(); }
2189 //! <b>Requires</b>: old_root is a node of a tree.
2190 //!
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.
2196 //!
2197 //! <b>Complexity</b>: Linear to the elements in the subtree.
2198 iterator rebalance_subtree(iterator root)
2199 { return tree_.rebalance_subtree(root); }
2201 /// @cond
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_; }
2207 /// @endcond
2210 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2211 template<class T, class ...Options>
2212 #else
2213 template<class Config>
2214 #endif
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)
2218 #else
2219 (const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y)
2220 #endif
2221 { return !(x == y); }
2223 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2224 template<class T, class ...Options>
2225 #else
2226 template<class Config>
2227 #endif
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)
2231 #else
2232 (const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y)
2233 #endif
2234 { return y < x; }
2236 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2237 template<class T, class ...Options>
2238 #else
2239 template<class Config>
2240 #endif
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)
2244 #else
2245 (const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y)
2246 #endif
2247 { return !(y < x); }
2249 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2250 template<class T, class ...Options>
2251 #else
2252 template<class Config>
2253 #endif
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)
2257 #else
2258 (const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y)
2259 #endif
2260 { return !(x < y); }
2262 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2263 template<class T, class ...Options>
2264 #else
2265 template<class Config>
2266 #endif
2267 inline void swap
2268 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2269 (splay_multiset_impl<T, Options...> &x, splay_multiset_impl<T, Options...> &y)
2270 #else
2271 (splay_multiset_impl<Config> &x, splay_multiset_impl<Config> &y)
2272 #endif
2273 { x.swap(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>
2279 #else
2280 template<class T, class O1 = none, class O2 = none
2281 , class O3 = none, class O4 = none>
2282 #endif
2283 struct make_splay_multiset
2285 /// @cond
2286 typedef splay_multiset_impl
2287 < typename make_splaytree_opt<T,
2288 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2289 O1, O2, O3, O4
2290 #else
2291 Options...
2292 #endif
2293 >::type
2294 > implementation_defined;
2295 /// @endcond
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>
2303 #else
2304 template<class T, class ...Options>
2305 #endif
2306 class splay_multiset
2307 : public make_splay_multiset<T,
2308 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2309 O1, O2, O3, O4
2310 #else
2311 Options...
2312 #endif
2313 >::type
2315 typedef typename make_splay_multiset
2316 <T,
2317 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2318 O1, O2, O3, O4
2319 #else
2320 Options...
2321 #endif
2322 >::type Base;
2324 public:
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)); }
2358 #endif
2360 } //namespace intrusive
2361 } //namespace boost
2363 #include <boost/intrusive/detail/config_end.hpp>
2365 #endif //BOOST_INTRUSIVE_SPLAY_SET_HPP