Chris@16
|
1 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Ion Gaztanaga 2008-2013
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //
|
Chris@16
|
9 // See http://www.boost.org/libs/intrusive for documentation.
|
Chris@16
|
10 //
|
Chris@16
|
11 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
12 #ifndef BOOST_INTRUSIVE_TREAP_HPP
|
Chris@16
|
13 #define BOOST_INTRUSIVE_TREAP_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/intrusive/detail/config_begin.hpp>
|
Chris@101
|
16 #include <boost/intrusive/intrusive_fwd.hpp>
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/intrusive/detail/assert.hpp>
|
Chris@16
|
19 #include <boost/intrusive/bs_set_hook.hpp>
|
Chris@16
|
20 #include <boost/intrusive/bstree.hpp>
|
Chris@16
|
21 #include <boost/intrusive/detail/tree_node.hpp>
|
Chris@16
|
22 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
|
Chris@16
|
23 #include <boost/intrusive/pointer_traits.hpp>
|
Chris@101
|
24 #include <boost/intrusive/detail/get_value_traits.hpp>
|
Chris@16
|
25 #include <boost/intrusive/detail/mpl.hpp>
|
Chris@16
|
26 #include <boost/intrusive/treap_algorithms.hpp>
|
Chris@16
|
27 #include <boost/intrusive/link_mode.hpp>
|
Chris@16
|
28 #include <boost/intrusive/priority_compare.hpp>
|
Chris@101
|
29 #include <boost/intrusive/detail/node_cloner_disposer.hpp>
|
Chris@101
|
30 #include <boost/intrusive/detail/key_nodeptr_comp.hpp>
|
Chris@101
|
31
|
Chris@101
|
32 #include <boost/static_assert.hpp>
|
Chris@101
|
33 #include <boost/move/utility_core.hpp>
|
Chris@101
|
34 #include <boost/move/adl_move_swap.hpp>
|
Chris@101
|
35
|
Chris@101
|
36 #include <cstddef>
|
Chris@101
|
37 #include <boost/intrusive/detail/minimal_less_equal_header.hpp>
|
Chris@101
|
38 #include <boost/intrusive/detail/minimal_pair_header.hpp> //std::pair
|
Chris@101
|
39
|
Chris@101
|
40 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@101
|
41 # pragma once
|
Chris@101
|
42 #endif
|
Chris@16
|
43
|
Chris@16
|
44 namespace boost {
|
Chris@16
|
45 namespace intrusive {
|
Chris@16
|
46
|
Chris@16
|
47 /// @cond
|
Chris@16
|
48
|
Chris@16
|
49 struct treap_defaults
|
Chris@16
|
50 {
|
Chris@101
|
51 typedef default_bstree_hook_applier proto_value_traits;
|
Chris@16
|
52 static const bool constant_time_size = true;
|
Chris@16
|
53 typedef std::size_t size_type;
|
Chris@16
|
54 typedef void compare;
|
Chris@16
|
55 typedef void priority;
|
Chris@101
|
56 typedef void header_holder_type;
|
Chris@16
|
57 };
|
Chris@16
|
58
|
Chris@16
|
59 /// @endcond
|
Chris@16
|
60
|
Chris@16
|
61 //! The class template treap is an intrusive treap container that
|
Chris@16
|
62 //! is used to construct intrusive set and multiset containers. The no-throw
|
Chris@16
|
63 //! guarantee holds only, if the value_compare object and priority_compare object
|
Chris@16
|
64 //! don't throw.
|
Chris@16
|
65 //!
|
Chris@16
|
66 //! The template parameter \c T is the type to be managed by the container.
|
Chris@16
|
67 //! The user can specify additional options and if no options are provided
|
Chris@16
|
68 //! default options are used.
|
Chris@16
|
69 //!
|
Chris@16
|
70 //! The container supports the following options:
|
Chris@16
|
71 //! \c base_hook<>/member_hook<>/value_traits<>,
|
Chris@16
|
72 //! \c constant_time_size<>, \c size_type<>,
|
Chris@16
|
73 //! \c compare<> and \c priority_compare<>
|
Chris@16
|
74 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
75 template<class T, class ...Options>
|
Chris@16
|
76 #else
|
Chris@101
|
77 template<class ValueTraits, class VoidOrKeyComp, class VoidOrPrioComp, class SizeType, bool ConstantTimeSize, typename HeaderHolder>
|
Chris@16
|
78 #endif
|
Chris@16
|
79 class treap_impl
|
Chris@16
|
80 /// @cond
|
Chris@101
|
81 : public bstree_impl<ValueTraits, VoidOrKeyComp, SizeType, ConstantTimeSize, BsTreeAlgorithms, HeaderHolder>
|
Chris@101
|
82 //Use public inheritance to avoid MSVC bugs with closures
|
Chris@101
|
83 , public detail::ebo_functor_holder
|
Chris@16
|
84 < typename get_prio
|
Chris@16
|
85 < VoidOrPrioComp
|
Chris@16
|
86 , typename bstree_impl
|
Chris@101
|
87 <ValueTraits, VoidOrKeyComp, SizeType, ConstantTimeSize, BsTreeAlgorithms, HeaderHolder>::value_type>::type
|
Chris@16
|
88 >
|
Chris@16
|
89 /// @endcond
|
Chris@16
|
90 {
|
Chris@16
|
91 public:
|
Chris@16
|
92 typedef ValueTraits value_traits;
|
Chris@16
|
93 /// @cond
|
Chris@16
|
94 typedef bstree_impl< ValueTraits, VoidOrKeyComp, SizeType
|
Chris@101
|
95 , ConstantTimeSize, BsTreeAlgorithms
|
Chris@101
|
96 , HeaderHolder> tree_type;
|
Chris@16
|
97 typedef tree_type implementation_defined;
|
Chris@16
|
98 typedef get_prio
|
Chris@16
|
99 < VoidOrPrioComp
|
Chris@16
|
100 , typename tree_type::value_type> get_prio_type;
|
Chris@16
|
101
|
Chris@16
|
102 typedef detail::ebo_functor_holder
|
Chris@16
|
103 <typename get_prio_type::type> prio_base;
|
Chris@16
|
104
|
Chris@16
|
105 /// @endcond
|
Chris@16
|
106
|
Chris@16
|
107 typedef typename implementation_defined::pointer pointer;
|
Chris@16
|
108 typedef typename implementation_defined::const_pointer const_pointer;
|
Chris@16
|
109 typedef typename implementation_defined::value_type value_type;
|
Chris@16
|
110 typedef typename implementation_defined::key_type key_type;
|
Chris@16
|
111 typedef typename implementation_defined::reference reference;
|
Chris@16
|
112 typedef typename implementation_defined::const_reference const_reference;
|
Chris@16
|
113 typedef typename implementation_defined::difference_type difference_type;
|
Chris@16
|
114 typedef typename implementation_defined::size_type size_type;
|
Chris@16
|
115 typedef typename implementation_defined::value_compare value_compare;
|
Chris@16
|
116 typedef typename implementation_defined::key_compare key_compare;
|
Chris@16
|
117 typedef typename implementation_defined::iterator iterator;
|
Chris@16
|
118 typedef typename implementation_defined::const_iterator const_iterator;
|
Chris@16
|
119 typedef typename implementation_defined::reverse_iterator reverse_iterator;
|
Chris@16
|
120 typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
|
Chris@16
|
121 typedef typename implementation_defined::node_traits node_traits;
|
Chris@16
|
122 typedef typename implementation_defined::node node;
|
Chris@16
|
123 typedef typename implementation_defined::node_ptr node_ptr;
|
Chris@16
|
124 typedef typename implementation_defined::const_node_ptr const_node_ptr;
|
Chris@16
|
125 typedef BOOST_INTRUSIVE_IMPDEF(treap_algorithms<node_traits>) node_algorithms;
|
Chris@16
|
126 typedef BOOST_INTRUSIVE_IMPDEF(typename get_prio_type::type) priority_compare;
|
Chris@16
|
127
|
Chris@16
|
128 static const bool constant_time_size = implementation_defined::constant_time_size;
|
Chris@16
|
129 static const bool stateful_value_traits = implementation_defined::stateful_value_traits;
|
Chris@101
|
130 static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
|
Chris@16
|
131
|
Chris@16
|
132 /// @cond
|
Chris@16
|
133 private:
|
Chris@16
|
134
|
Chris@16
|
135 //noncopyable
|
Chris@16
|
136 BOOST_MOVABLE_BUT_NOT_COPYABLE(treap_impl)
|
Chris@16
|
137
|
Chris@16
|
138 const priority_compare &priv_pcomp() const
|
Chris@16
|
139 { return static_cast<const prio_base&>(*this).get(); }
|
Chris@16
|
140
|
Chris@16
|
141 priority_compare &priv_pcomp()
|
Chris@16
|
142 { return static_cast<prio_base&>(*this).get(); }
|
Chris@16
|
143
|
Chris@16
|
144 /// @endcond
|
Chris@16
|
145
|
Chris@16
|
146 public:
|
Chris@16
|
147 typedef typename node_algorithms::insert_commit_data insert_commit_data;
|
Chris@16
|
148
|
Chris@16
|
149 //! <b>Effects</b>: Constructs an empty container.
|
Chris@16
|
150 //!
|
Chris@16
|
151 //! <b>Complexity</b>: Constant.
|
Chris@16
|
152 //!
|
Chris@16
|
153 //! <b>Throws</b>: If value_traits::node_traits::node
|
Chris@16
|
154 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
|
Chris@16
|
155 //! or the copy constructor of the value_compare/priority_compare objects throw. Basic guarantee.
|
Chris@16
|
156 explicit treap_impl( const value_compare &cmp = value_compare()
|
Chris@16
|
157 , const priority_compare &pcmp = priority_compare()
|
Chris@16
|
158 , const value_traits &v_traits = value_traits())
|
Chris@16
|
159 : tree_type(cmp, v_traits), prio_base(pcmp)
|
Chris@16
|
160 {}
|
Chris@16
|
161
|
Chris@16
|
162 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
|
Chris@16
|
163 //! cmp must be a comparison function that induces a strict weak ordering.
|
Chris@16
|
164 //!
|
Chris@16
|
165 //! <b>Effects</b>: Constructs an empty container and inserts elements from
|
Chris@16
|
166 //! [b, e).
|
Chris@16
|
167 //!
|
Chris@16
|
168 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
|
Chris@16
|
169 //! comp and otherwise N * log N, where N is the distance between first and last.
|
Chris@16
|
170 //!
|
Chris@16
|
171 //! <b>Throws</b>: If value_traits::node_traits::node
|
Chris@16
|
172 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
|
Chris@16
|
173 //! or the copy constructor/operator() of the value_compare/priority_compare objects
|
Chris@16
|
174 //! throw. Basic guarantee.
|
Chris@16
|
175 template<class Iterator>
|
Chris@16
|
176 treap_impl( bool unique, Iterator b, Iterator e
|
Chris@16
|
177 , const value_compare &cmp = value_compare()
|
Chris@16
|
178 , const priority_compare &pcmp = priority_compare()
|
Chris@16
|
179 , const value_traits &v_traits = value_traits())
|
Chris@16
|
180 : tree_type(cmp, v_traits), prio_base(pcmp)
|
Chris@16
|
181 {
|
Chris@16
|
182 if(unique)
|
Chris@16
|
183 this->insert_unique(b, e);
|
Chris@16
|
184 else
|
Chris@16
|
185 this->insert_equal(b, e);
|
Chris@16
|
186 }
|
Chris@16
|
187
|
Chris@16
|
188 //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&)
|
Chris@16
|
189 treap_impl(BOOST_RV_REF(treap_impl) x)
|
Chris@101
|
190 : tree_type(BOOST_MOVE_BASE(tree_type, x))
|
Chris@16
|
191 , prio_base(::boost::move(x.priv_pcomp()))
|
Chris@16
|
192 {}
|
Chris@16
|
193
|
Chris@16
|
194 //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&)
|
Chris@16
|
195 treap_impl& operator=(BOOST_RV_REF(treap_impl) x)
|
Chris@16
|
196 { this->swap(x); return *this; }
|
Chris@16
|
197
|
Chris@16
|
198 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
199 //! @copydoc ::boost::intrusive::bstree::~bstree()
|
Chris@16
|
200 ~treap_impl();
|
Chris@16
|
201
|
Chris@16
|
202 //! @copydoc ::boost::intrusive::bstree::begin()
|
Chris@16
|
203 iterator begin();
|
Chris@16
|
204
|
Chris@16
|
205 //! @copydoc ::boost::intrusive::bstree::begin()const
|
Chris@16
|
206 const_iterator begin() const;
|
Chris@16
|
207
|
Chris@16
|
208 //! @copydoc ::boost::intrusive::bstree::cbegin()const
|
Chris@16
|
209 const_iterator cbegin() const;
|
Chris@16
|
210
|
Chris@16
|
211 //! @copydoc ::boost::intrusive::bstree::end()
|
Chris@16
|
212 iterator end();
|
Chris@16
|
213
|
Chris@16
|
214 //! @copydoc ::boost::intrusive::bstree::end()const
|
Chris@16
|
215 const_iterator end() const;
|
Chris@16
|
216
|
Chris@16
|
217 //! @copydoc ::boost::intrusive::bstree::cend()const
|
Chris@16
|
218 const_iterator cend() const;
|
Chris@16
|
219 #endif
|
Chris@16
|
220
|
Chris@16
|
221 //! <b>Effects</b>: Returns an iterator pointing to the highest priority object of the treap.
|
Chris@16
|
222 //!
|
Chris@16
|
223 //! <b>Complexity</b>: Constant.
|
Chris@16
|
224 //!
|
Chris@16
|
225 //! <b>Throws</b>: Nothing.
|
Chris@16
|
226 iterator top()
|
Chris@101
|
227 { return this->tree_type::root(); }
|
Chris@16
|
228
|
Chris@16
|
229 //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the treap..
|
Chris@16
|
230 //!
|
Chris@16
|
231 //! <b>Complexity</b>: Constant.
|
Chris@16
|
232 //!
|
Chris@16
|
233 //! <b>Throws</b>: Nothing.
|
Chris@16
|
234 const_iterator top() const
|
Chris@16
|
235 { return this->ctop(); }
|
Chris@16
|
236
|
Chris@16
|
237 //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the treap..
|
Chris@16
|
238 //!
|
Chris@16
|
239 //! <b>Complexity</b>: Constant.
|
Chris@16
|
240 //!
|
Chris@16
|
241 //! <b>Throws</b>: Nothing.
|
Chris@16
|
242 const_iterator ctop() const
|
Chris@101
|
243 { return this->tree_type::root(); }
|
Chris@16
|
244
|
Chris@16
|
245 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
246 //! @copydoc ::boost::intrusive::bstree::rbegin()
|
Chris@16
|
247 reverse_iterator rbegin();
|
Chris@16
|
248
|
Chris@16
|
249 //! @copydoc ::boost::intrusive::bstree::rbegin()const
|
Chris@16
|
250 const_reverse_iterator rbegin() const;
|
Chris@16
|
251
|
Chris@16
|
252 //! @copydoc ::boost::intrusive::bstree::crbegin()const
|
Chris@16
|
253 const_reverse_iterator crbegin() const;
|
Chris@16
|
254
|
Chris@16
|
255 //! @copydoc ::boost::intrusive::bstree::rend()
|
Chris@16
|
256 reverse_iterator rend();
|
Chris@16
|
257
|
Chris@16
|
258 //! @copydoc ::boost::intrusive::bstree::rend()const
|
Chris@16
|
259 const_reverse_iterator rend() const;
|
Chris@16
|
260
|
Chris@16
|
261 //! @copydoc ::boost::intrusive::bstree::crend()const
|
Chris@16
|
262 const_reverse_iterator crend() const;
|
Chris@16
|
263 #endif
|
Chris@16
|
264
|
Chris@16
|
265 //! <b>Effects</b>: Returns a reverse_iterator pointing to the highest priority object of the
|
Chris@16
|
266 //! reversed treap.
|
Chris@16
|
267 //!
|
Chris@16
|
268 //! <b>Complexity</b>: Constant.
|
Chris@16
|
269 //!
|
Chris@16
|
270 //! <b>Throws</b>: Nothing.
|
Chris@16
|
271 reverse_iterator rtop()
|
Chris@16
|
272 { return reverse_iterator(this->top()); }
|
Chris@16
|
273
|
Chris@16
|
274 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority objec
|
Chris@16
|
275 //! of the reversed treap.
|
Chris@16
|
276 //!
|
Chris@16
|
277 //! <b>Complexity</b>: Constant.
|
Chris@16
|
278 //!
|
Chris@16
|
279 //! <b>Throws</b>: Nothing.
|
Chris@16
|
280 const_reverse_iterator rtop() const
|
Chris@16
|
281 { return const_reverse_iterator(this->top()); }
|
Chris@16
|
282
|
Chris@16
|
283 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority object
|
Chris@16
|
284 //! of the reversed treap.
|
Chris@16
|
285 //!
|
Chris@16
|
286 //! <b>Complexity</b>: Constant.
|
Chris@16
|
287 //!
|
Chris@16
|
288 //! <b>Throws</b>: Nothing.
|
Chris@16
|
289 const_reverse_iterator crtop() const
|
Chris@16
|
290 { return const_reverse_iterator(this->top()); }
|
Chris@16
|
291
|
Chris@16
|
292 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
293 //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator)
|
Chris@16
|
294 static treap_impl &container_from_end_iterator(iterator end_iterator);
|
Chris@16
|
295
|
Chris@16
|
296 //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator)
|
Chris@16
|
297 static const treap_impl &container_from_end_iterator(const_iterator end_iterator);
|
Chris@16
|
298
|
Chris@16
|
299 //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator)
|
Chris@16
|
300 static treap_impl &container_from_iterator(iterator it);
|
Chris@16
|
301
|
Chris@16
|
302 //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator)
|
Chris@16
|
303 static const treap_impl &container_from_iterator(const_iterator it);
|
Chris@16
|
304
|
Chris@16
|
305 //! @copydoc ::boost::intrusive::bstree::key_comp()const
|
Chris@16
|
306 key_compare key_comp() const;
|
Chris@16
|
307
|
Chris@16
|
308 //! @copydoc ::boost::intrusive::bstree::value_comp()const
|
Chris@16
|
309 value_compare value_comp() const;
|
Chris@16
|
310
|
Chris@16
|
311 //! @copydoc ::boost::intrusive::bstree::empty()const
|
Chris@16
|
312 bool empty() const;
|
Chris@16
|
313
|
Chris@16
|
314 //! @copydoc ::boost::intrusive::bstree::size()const
|
Chris@16
|
315 size_type size() const;
|
Chris@16
|
316 #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
317
|
Chris@16
|
318 //! <b>Effects</b>: Returns the priority_compare object used by the container.
|
Chris@16
|
319 //!
|
Chris@16
|
320 //! <b>Complexity</b>: Constant.
|
Chris@16
|
321 //!
|
Chris@16
|
322 //! <b>Throws</b>: If priority_compare copy-constructor throws.
|
Chris@16
|
323 priority_compare priority_comp() const
|
Chris@16
|
324 { return this->priv_pcomp(); }
|
Chris@16
|
325
|
Chris@16
|
326 //! <b>Effects</b>: Swaps the contents of two treaps.
|
Chris@16
|
327 //!
|
Chris@16
|
328 //! <b>Complexity</b>: Constant.
|
Chris@16
|
329 //!
|
Chris@16
|
330 //! <b>Throws</b>: If the comparison functor's swap call throws.
|
Chris@16
|
331 void swap(treap_impl& other)
|
Chris@16
|
332 {
|
Chris@16
|
333 tree_type::swap(other);
|
Chris@16
|
334 //This can throw
|
Chris@101
|
335 ::boost::adl_move_swap(this->priv_pcomp(), other.priv_pcomp());
|
Chris@16
|
336 }
|
Chris@16
|
337
|
Chris@16
|
338 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
339 //! Cloner should yield to nodes equivalent to the original nodes.
|
Chris@16
|
340 //!
|
Chris@16
|
341 //! <b>Effects</b>: Erases all the elements from *this
|
Chris@16
|
342 //! calling Disposer::operator()(pointer), clones all the
|
Chris@16
|
343 //! elements from src calling Cloner::operator()(const_reference )
|
Chris@16
|
344 //! and inserts them on *this. Copies the predicate from the source container.
|
Chris@16
|
345 //!
|
Chris@16
|
346 //! If cloner throws, all cloned elements are unlinked and disposed
|
Chris@16
|
347 //! calling Disposer::operator()(pointer).
|
Chris@16
|
348 //!
|
Chris@16
|
349 //! <b>Complexity</b>: Linear to erased plus inserted elements.
|
Chris@16
|
350 //!
|
Chris@16
|
351 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
|
Chris@16
|
352 template <class Cloner, class Disposer>
|
Chris@16
|
353 void clone_from(const treap_impl &src, Cloner cloner, Disposer disposer)
|
Chris@16
|
354 {
|
Chris@16
|
355 tree_type::clone_from(src, cloner, disposer);
|
Chris@16
|
356 this->priv_pcomp() = src.priv_pcomp();
|
Chris@16
|
357 }
|
Chris@16
|
358
|
Chris@16
|
359 //! <b>Requires</b>: value must be an lvalue
|
Chris@16
|
360 //!
|
Chris@16
|
361 //! <b>Effects</b>: Inserts value into the container before the upper bound.
|
Chris@16
|
362 //!
|
Chris@16
|
363 //! <b>Complexity</b>: Average complexity for insert element is at
|
Chris@16
|
364 //! most logarithmic.
|
Chris@16
|
365 //!
|
Chris@16
|
366 //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw. Strong guarantee.
|
Chris@16
|
367 //!
|
Chris@16
|
368 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
369 //! No copy-constructors are called.
|
Chris@16
|
370 iterator insert_equal(reference value)
|
Chris@16
|
371 {
|
Chris@101
|
372 detail::key_nodeptr_comp<value_compare, value_traits>
|
Chris@101
|
373 key_node_comp(this->value_comp(), &this->get_value_traits());
|
Chris@101
|
374 detail::key_nodeptr_comp<priority_compare, value_traits>
|
Chris@101
|
375 key_node_pcomp(this->priv_pcomp(), &this->get_value_traits());
|
Chris@101
|
376 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
|
Chris@16
|
377 if(safemode_or_autounlink)
|
Chris@16
|
378 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
379 iterator ret(node_algorithms::insert_equal_upper_bound
|
Chris@101
|
380 (this->tree_type::header_ptr(), to_insert, key_node_comp, key_node_pcomp), this->priv_value_traits_ptr());
|
Chris@16
|
381 this->tree_type::sz_traits().increment();
|
Chris@16
|
382 return ret;
|
Chris@16
|
383 }
|
Chris@16
|
384
|
Chris@16
|
385 //! <b>Requires</b>: value must be an lvalue, and "hint" must be
|
Chris@16
|
386 //! a valid iterator.
|
Chris@16
|
387 //!
|
Chris@16
|
388 //! <b>Effects</b>: Inserts x into the container, using "hint" as a hint to
|
Chris@16
|
389 //! where it will be inserted. If "hint" is the upper_bound
|
Chris@16
|
390 //! the insertion takes constant time (two comparisons in the worst case)
|
Chris@16
|
391 //!
|
Chris@16
|
392 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
|
Chris@16
|
393 //! constant time if t is inserted immediately before hint.
|
Chris@16
|
394 //!
|
Chris@16
|
395 //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw. Strong guarantee.
|
Chris@16
|
396 //!
|
Chris@16
|
397 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
398 //! No copy-constructors are called.
|
Chris@16
|
399 iterator insert_equal(const_iterator hint, reference value)
|
Chris@16
|
400 {
|
Chris@101
|
401 detail::key_nodeptr_comp<value_compare, value_traits>
|
Chris@101
|
402 key_node_comp(this->value_comp(), &this->get_value_traits());
|
Chris@101
|
403 detail::key_nodeptr_comp<priority_compare, value_traits>
|
Chris@101
|
404 key_node_pcomp(this->priv_pcomp(), &this->get_value_traits());
|
Chris@101
|
405 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
|
Chris@16
|
406 if(safemode_or_autounlink)
|
Chris@16
|
407 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
408 iterator ret (node_algorithms::insert_equal
|
Chris@101
|
409 (this->tree_type::header_ptr(), hint.pointed_node(), to_insert, key_node_comp, key_node_pcomp), this->priv_value_traits_ptr());
|
Chris@16
|
410 this->tree_type::sz_traits().increment();
|
Chris@16
|
411 return ret;
|
Chris@16
|
412 }
|
Chris@16
|
413
|
Chris@16
|
414 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
|
Chris@16
|
415 //! of type value_type.
|
Chris@16
|
416 //!
|
Chris@16
|
417 //! <b>Effects</b>: Inserts a each element of a range into the container
|
Chris@16
|
418 //! before the upper bound of the key of each element.
|
Chris@16
|
419 //!
|
Chris@16
|
420 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
|
Chris@16
|
421 //! size of the range. However, it is linear in N if the range is already sorted
|
Chris@16
|
422 //! by value_comp().
|
Chris@16
|
423 //!
|
Chris@16
|
424 //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw.
|
Chris@16
|
425 //! Strong guarantee.
|
Chris@16
|
426 //!
|
Chris@16
|
427 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
428 //! No copy-constructors are called.
|
Chris@16
|
429 template<class Iterator>
|
Chris@16
|
430 void insert_equal(Iterator b, Iterator e)
|
Chris@16
|
431 {
|
Chris@16
|
432 iterator iend(this->end());
|
Chris@16
|
433 for (; b != e; ++b)
|
Chris@16
|
434 this->insert_equal(iend, *b);
|
Chris@16
|
435 }
|
Chris@16
|
436
|
Chris@16
|
437 //! <b>Requires</b>: value must be an lvalue
|
Chris@16
|
438 //!
|
Chris@16
|
439 //! <b>Effects</b>: Inserts value into the container if the value
|
Chris@16
|
440 //! is not already present.
|
Chris@16
|
441 //!
|
Chris@16
|
442 //! <b>Complexity</b>: Average complexity for insert element is at
|
Chris@16
|
443 //! most logarithmic.
|
Chris@16
|
444 //!
|
Chris@16
|
445 //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw.
|
Chris@16
|
446 //! Strong guarantee.
|
Chris@16
|
447 //!
|
Chris@16
|
448 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
449 //! No copy-constructors are called.
|
Chris@16
|
450 std::pair<iterator, bool> insert_unique(reference value)
|
Chris@16
|
451 {
|
Chris@16
|
452 insert_commit_data commit_data;
|
Chris@16
|
453 std::pair<iterator, bool> ret = insert_unique_check(value, this->value_comp(), this->priv_pcomp(), commit_data);
|
Chris@16
|
454 if(!ret.second)
|
Chris@16
|
455 return ret;
|
Chris@16
|
456 return std::pair<iterator, bool> (insert_unique_commit(value, commit_data), true);
|
Chris@16
|
457 }
|
Chris@16
|
458
|
Chris@16
|
459 //! <b>Requires</b>: value must be an lvalue, and "hint" must be
|
Chris@16
|
460 //! a valid iterator
|
Chris@16
|
461 //!
|
Chris@16
|
462 //! <b>Effects</b>: Tries to insert x into the container, using "hint" as a hint
|
Chris@16
|
463 //! to where it will be inserted.
|
Chris@16
|
464 //!
|
Chris@16
|
465 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
|
Chris@16
|
466 //! constant time (two comparisons in the worst case)
|
Chris@16
|
467 //! if t is inserted immediately before hint.
|
Chris@16
|
468 //!
|
Chris@16
|
469 //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw.
|
Chris@16
|
470 //! Strong guarantee.
|
Chris@16
|
471 //!
|
Chris@16
|
472 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
473 //! No copy-constructors are called.
|
Chris@16
|
474 iterator insert_unique(const_iterator hint, reference value)
|
Chris@16
|
475 {
|
Chris@16
|
476 insert_commit_data commit_data;
|
Chris@16
|
477 std::pair<iterator, bool> ret = insert_unique_check(hint, value, this->value_comp(), this->priv_pcomp(), commit_data);
|
Chris@16
|
478 if(!ret.second)
|
Chris@16
|
479 return ret.first;
|
Chris@16
|
480 return insert_unique_commit(value, commit_data);
|
Chris@16
|
481 }
|
Chris@16
|
482
|
Chris@16
|
483 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
|
Chris@16
|
484 //! of type value_type.
|
Chris@16
|
485 //!
|
Chris@16
|
486 //! <b>Effects</b>: Tries to insert each element of a range into the container.
|
Chris@16
|
487 //!
|
Chris@16
|
488 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
|
Chris@16
|
489 //! size of the range. However, it is linear in N if the range is already sorted
|
Chris@16
|
490 //! by value_comp().
|
Chris@16
|
491 //!
|
Chris@16
|
492 //! <b>Throws</b>: If the internal value_compare or priority_compare functions throw.
|
Chris@16
|
493 //! Strong guarantee.
|
Chris@16
|
494 //!
|
Chris@16
|
495 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
496 //! No copy-constructors are called.
|
Chris@16
|
497 template<class Iterator>
|
Chris@16
|
498 void insert_unique(Iterator b, Iterator e)
|
Chris@16
|
499 {
|
Chris@16
|
500 if(this->empty()){
|
Chris@16
|
501 iterator iend(this->end());
|
Chris@16
|
502 for (; b != e; ++b)
|
Chris@16
|
503 this->insert_unique(iend, *b);
|
Chris@16
|
504 }
|
Chris@16
|
505 else{
|
Chris@16
|
506 for (; b != e; ++b)
|
Chris@16
|
507 this->insert_unique(*b);
|
Chris@16
|
508 }
|
Chris@16
|
509 }
|
Chris@16
|
510
|
Chris@16
|
511 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
|
Chris@16
|
512 //! the same strict weak ordering as value_compare.
|
Chris@16
|
513 //! key_value_pcomp must be a comparison function that induces
|
Chris@16
|
514 //! the same strict weak ordering as priority_compare. The difference is that
|
Chris@16
|
515 //! key_value_pcomp and key_value_comp compare an arbitrary key with the contained values.
|
Chris@16
|
516 //!
|
Chris@16
|
517 //! <b>Effects</b>: Checks if a value can be inserted in the container, using
|
Chris@16
|
518 //! a user provided key instead of the value itself.
|
Chris@16
|
519 //!
|
Chris@16
|
520 //! <b>Returns</b>: If there is an equivalent value
|
Chris@16
|
521 //! returns a pair containing an iterator to the already present value
|
Chris@16
|
522 //! and false. If the value can be inserted returns true in the returned
|
Chris@16
|
523 //! pair boolean and fills "commit_data" that is meant to be used with
|
Chris@16
|
524 //! the "insert_commit" function.
|
Chris@16
|
525 //!
|
Chris@16
|
526 //! <b>Complexity</b>: Average complexity is at most logarithmic.
|
Chris@16
|
527 //!
|
Chris@16
|
528 //! <b>Throws</b>: If the key_value_comp or key_value_pcomp
|
Chris@16
|
529 //! ordering functions throw. Strong guarantee.
|
Chris@16
|
530 //!
|
Chris@16
|
531 //! <b>Notes</b>: This function is used to improve performance when constructing
|
Chris@16
|
532 //! a value_type is expensive: if there is an equivalent value
|
Chris@16
|
533 //! the constructed object must be discarded. Many times, the part of the
|
Chris@16
|
534 //! node that is used to impose the order is much cheaper to construct
|
Chris@16
|
535 //! than the value_type and this function offers the possibility to use that
|
Chris@16
|
536 //! part to check if the insertion will be successful.
|
Chris@16
|
537 //!
|
Chris@16
|
538 //! If the check is successful, the user can construct the value_type and use
|
Chris@16
|
539 //! "insert_commit" to insert the object in constant-time. This gives a total
|
Chris@16
|
540 //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
|
Chris@16
|
541 //!
|
Chris@16
|
542 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
|
Chris@16
|
543 //! objects are inserted or erased from the container.
|
Chris@16
|
544 template<class KeyType, class KeyValueCompare, class KeyValuePrioCompare>
|
Chris@16
|
545 std::pair<iterator, bool> insert_unique_check
|
Chris@16
|
546 ( const KeyType &key, KeyValueCompare key_value_comp
|
Chris@16
|
547 , KeyValuePrioCompare key_value_pcomp, insert_commit_data &commit_data)
|
Chris@16
|
548 {
|
Chris@101
|
549 detail::key_nodeptr_comp<KeyValueCompare, value_traits>
|
Chris@101
|
550 ocomp(key_value_comp, &this->get_value_traits());
|
Chris@101
|
551 detail::key_nodeptr_comp<KeyValuePrioCompare, value_traits>
|
Chris@101
|
552 pcomp(key_value_pcomp, &this->get_value_traits());
|
Chris@16
|
553 std::pair<node_ptr, bool> ret =
|
Chris@16
|
554 (node_algorithms::insert_unique_check
|
Chris@16
|
555 (this->tree_type::header_ptr(), key, ocomp, pcomp, commit_data));
|
Chris@101
|
556 return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second);
|
Chris@16
|
557 }
|
Chris@16
|
558
|
Chris@16
|
559 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
|
Chris@16
|
560 //! the same strict weak ordering as value_compare.
|
Chris@16
|
561 //! key_value_pcomp must be a comparison function that induces
|
Chris@16
|
562 //! the same strict weak ordering as priority_compare. The difference is that
|
Chris@16
|
563 //! key_value_pcomp and key_value_comp compare an arbitrary key with the contained values.
|
Chris@16
|
564 //!
|
Chris@16
|
565 //! <b>Effects</b>: Checks if a value can be inserted in the container, using
|
Chris@16
|
566 //! a user provided key instead of the value itself, using "hint"
|
Chris@16
|
567 //! as a hint to where it will be inserted.
|
Chris@16
|
568 //!
|
Chris@16
|
569 //! <b>Returns</b>: If there is an equivalent value
|
Chris@16
|
570 //! returns a pair containing an iterator to the already present value
|
Chris@16
|
571 //! and false. If the value can be inserted returns true in the returned
|
Chris@16
|
572 //! pair boolean and fills "commit_data" that is meant to be used with
|
Chris@16
|
573 //! the "insert_commit" function.
|
Chris@16
|
574 //!
|
Chris@16
|
575 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
|
Chris@16
|
576 //! constant time if t is inserted immediately before hint.
|
Chris@16
|
577 //!
|
Chris@16
|
578 //! <b>Throws</b>: If the key_value_comp or key_value_pcomp
|
Chris@16
|
579 //! ordering functions throw. Strong guarantee.
|
Chris@16
|
580 //!
|
Chris@16
|
581 //! <b>Notes</b>: This function is used to improve performance when constructing
|
Chris@16
|
582 //! a value_type is expensive: if there is an equivalent value
|
Chris@16
|
583 //! the constructed object must be discarded. Many times, the part of the
|
Chris@16
|
584 //! constructing that is used to impose the order is much cheaper to construct
|
Chris@16
|
585 //! than the value_type and this function offers the possibility to use that key
|
Chris@16
|
586 //! to check if the insertion will be successful.
|
Chris@16
|
587 //!
|
Chris@16
|
588 //! If the check is successful, the user can construct the value_type and use
|
Chris@16
|
589 //! "insert_commit" to insert the object in constant-time. This can give a total
|
Chris@16
|
590 //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
|
Chris@16
|
591 //!
|
Chris@16
|
592 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
|
Chris@16
|
593 //! objects are inserted or erased from the container.
|
Chris@16
|
594 template<class KeyType, class KeyValueCompare, class KeyValuePrioCompare>
|
Chris@16
|
595 std::pair<iterator, bool> insert_unique_check
|
Chris@16
|
596 ( const_iterator hint, const KeyType &key
|
Chris@16
|
597 , KeyValueCompare key_value_comp
|
Chris@16
|
598 , KeyValuePrioCompare key_value_pcomp
|
Chris@16
|
599 , insert_commit_data &commit_data)
|
Chris@16
|
600 {
|
Chris@101
|
601 detail::key_nodeptr_comp<KeyValueCompare, value_traits>
|
Chris@101
|
602 ocomp(key_value_comp, &this->get_value_traits());
|
Chris@101
|
603 detail::key_nodeptr_comp<KeyValuePrioCompare, value_traits>
|
Chris@101
|
604 pcomp(key_value_pcomp, &this->get_value_traits());
|
Chris@16
|
605 std::pair<node_ptr, bool> ret =
|
Chris@16
|
606 (node_algorithms::insert_unique_check
|
Chris@16
|
607 (this->tree_type::header_ptr(), hint.pointed_node(), key, ocomp, pcomp, commit_data));
|
Chris@101
|
608 return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second);
|
Chris@16
|
609 }
|
Chris@16
|
610
|
Chris@16
|
611 //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
|
Chris@16
|
612 //! must have been obtained from a previous call to "insert_check".
|
Chris@16
|
613 //! No objects should have been inserted or erased from the container between
|
Chris@16
|
614 //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
|
Chris@16
|
615 //!
|
Chris@16
|
616 //! <b>Effects</b>: Inserts the value in the avl_set using the information obtained
|
Chris@16
|
617 //! from the "commit_data" that a previous "insert_check" filled.
|
Chris@16
|
618 //!
|
Chris@16
|
619 //! <b>Returns</b>: An iterator to the newly inserted object.
|
Chris@16
|
620 //!
|
Chris@16
|
621 //! <b>Complexity</b>: Constant time.
|
Chris@16
|
622 //!
|
Chris@16
|
623 //! <b>Throws</b>: Nothing
|
Chris@16
|
624 //!
|
Chris@16
|
625 //! <b>Notes</b>: This function has only sense if a "insert_check" has been
|
Chris@16
|
626 //! previously executed to fill "commit_data". No value should be inserted or
|
Chris@16
|
627 //! erased between the "insert_check" and "insert_commit" calls.
|
Chris@16
|
628 iterator insert_unique_commit(reference value, const insert_commit_data &commit_data)
|
Chris@16
|
629 {
|
Chris@101
|
630 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
|
Chris@16
|
631 if(safemode_or_autounlink)
|
Chris@16
|
632 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@16
|
633 node_algorithms::insert_unique_commit(this->tree_type::header_ptr(), to_insert, commit_data);
|
Chris@16
|
634 this->tree_type::sz_traits().increment();
|
Chris@101
|
635 return iterator(to_insert, this->priv_value_traits_ptr());
|
Chris@16
|
636 }
|
Chris@16
|
637
|
Chris@16
|
638 //! <b>Requires</b>: value must be an lvalue, "pos" must be
|
Chris@16
|
639 //! a valid iterator (or end) and must be the succesor of value
|
Chris@16
|
640 //! once inserted according to the predicate
|
Chris@16
|
641 //!
|
Chris@16
|
642 //! <b>Effects</b>: Inserts x into the container before "pos".
|
Chris@16
|
643 //!
|
Chris@16
|
644 //! <b>Complexity</b>: Constant time.
|
Chris@16
|
645 //!
|
Chris@16
|
646 //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee.
|
Chris@16
|
647 //!
|
Chris@16
|
648 //! <b>Note</b>: This function does not check preconditions so if "pos" is not
|
Chris@16
|
649 //! the successor of "value" container ordering invariant will be broken.
|
Chris@16
|
650 //! This is a low-level function to be used only for performance reasons
|
Chris@16
|
651 //! by advanced users.
|
Chris@16
|
652 iterator insert_before(const_iterator pos, reference value)
|
Chris@16
|
653 {
|
Chris@101
|
654 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
|
Chris@16
|
655 if(safemode_or_autounlink)
|
Chris@16
|
656 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@101
|
657 detail::key_nodeptr_comp<priority_compare, value_traits>
|
Chris@101
|
658 pcomp(this->priv_pcomp(), &this->get_value_traits());
|
Chris@16
|
659 iterator ret (node_algorithms::insert_before
|
Chris@101
|
660 (this->tree_type::header_ptr(), pos.pointed_node(), to_insert, pcomp), this->priv_value_traits_ptr());
|
Chris@16
|
661 this->tree_type::sz_traits().increment();
|
Chris@16
|
662 return ret;
|
Chris@16
|
663 }
|
Chris@16
|
664
|
Chris@16
|
665 //! <b>Requires</b>: value must be an lvalue, and it must be no less
|
Chris@16
|
666 //! than the greatest inserted key
|
Chris@16
|
667 //!
|
Chris@16
|
668 //! <b>Effects</b>: Inserts x into the container in the last position.
|
Chris@16
|
669 //!
|
Chris@16
|
670 //! <b>Complexity</b>: Constant time.
|
Chris@16
|
671 //!
|
Chris@16
|
672 //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee.
|
Chris@16
|
673 //!
|
Chris@16
|
674 //! <b>Note</b>: This function does not check preconditions so if value is
|
Chris@16
|
675 //! less than the greatest inserted key container ordering invariant will be broken.
|
Chris@16
|
676 //! This function is slightly more efficient than using "insert_before".
|
Chris@16
|
677 //! This is a low-level function to be used only for performance reasons
|
Chris@16
|
678 //! by advanced users.
|
Chris@16
|
679 void push_back(reference value)
|
Chris@16
|
680 {
|
Chris@101
|
681 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
|
Chris@16
|
682 if(safemode_or_autounlink)
|
Chris@16
|
683 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@101
|
684 detail::key_nodeptr_comp<priority_compare, value_traits>
|
Chris@101
|
685 pcomp(this->priv_pcomp(), &this->get_value_traits());
|
Chris@16
|
686 node_algorithms::push_back(this->tree_type::header_ptr(), to_insert, pcomp);
|
Chris@16
|
687 this->tree_type::sz_traits().increment();
|
Chris@16
|
688 }
|
Chris@16
|
689
|
Chris@16
|
690 //! <b>Requires</b>: value must be an lvalue, and it must be no greater
|
Chris@16
|
691 //! than the minimum inserted key
|
Chris@16
|
692 //!
|
Chris@16
|
693 //! <b>Effects</b>: Inserts x into the container in the first position.
|
Chris@16
|
694 //!
|
Chris@16
|
695 //! <b>Complexity</b>: Constant time.
|
Chris@16
|
696 //!
|
Chris@16
|
697 //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee.
|
Chris@16
|
698 //!
|
Chris@16
|
699 //! <b>Note</b>: This function does not check preconditions so if value is
|
Chris@16
|
700 //! greater than the minimum inserted key container ordering invariant will be broken.
|
Chris@16
|
701 //! This function is slightly more efficient than using "insert_before".
|
Chris@16
|
702 //! This is a low-level function to be used only for performance reasons
|
Chris@16
|
703 //! by advanced users.
|
Chris@16
|
704 void push_front(reference value)
|
Chris@16
|
705 {
|
Chris@101
|
706 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
|
Chris@16
|
707 if(safemode_or_autounlink)
|
Chris@16
|
708 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
|
Chris@101
|
709 detail::key_nodeptr_comp<priority_compare, value_traits>
|
Chris@101
|
710 pcomp(this->priv_pcomp(), &this->get_value_traits());
|
Chris@16
|
711 node_algorithms::push_front(this->tree_type::header_ptr(), to_insert, pcomp);
|
Chris@16
|
712 this->tree_type::sz_traits().increment();
|
Chris@16
|
713 }
|
Chris@16
|
714
|
Chris@101
|
715 //! <b>Effects</b>: Erases the element pointed to by i.
|
Chris@16
|
716 //!
|
Chris@16
|
717 //! <b>Complexity</b>: Average complexity for erase element is constant time.
|
Chris@16
|
718 //!
|
Chris@16
|
719 //! <b>Throws</b>: if the internal priority_compare function throws. Strong guarantee.
|
Chris@16
|
720 //!
|
Chris@16
|
721 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
722 //! to the erased elements. No destructors are called.
|
Chris@16
|
723 iterator erase(const_iterator i)
|
Chris@16
|
724 {
|
Chris@16
|
725 const_iterator ret(i);
|
Chris@16
|
726 ++ret;
|
Chris@16
|
727 node_ptr to_erase(i.pointed_node());
|
Chris@16
|
728 if(safemode_or_autounlink)
|
Chris@16
|
729 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase));
|
Chris@101
|
730 detail::key_nodeptr_comp<priority_compare, value_traits>
|
Chris@101
|
731 key_node_pcomp(this->priv_pcomp(), &this->get_value_traits());
|
Chris@16
|
732 node_algorithms::erase(this->tree_type::header_ptr(), to_erase, key_node_pcomp);
|
Chris@16
|
733 this->tree_type::sz_traits().decrement();
|
Chris@16
|
734 if(safemode_or_autounlink)
|
Chris@16
|
735 node_algorithms::init(to_erase);
|
Chris@16
|
736 return ret.unconst();
|
Chris@16
|
737 }
|
Chris@16
|
738
|
Chris@16
|
739 //! <b>Effects</b>: Erases the range pointed to by b end e.
|
Chris@16
|
740 //!
|
Chris@16
|
741 //! <b>Complexity</b>: Average complexity for erase range is at most
|
Chris@16
|
742 //! O(log(size() + N)), where N is the number of elements in the range.
|
Chris@16
|
743 //!
|
Chris@16
|
744 //! <b>Throws</b>: if the internal priority_compare function throws. Strong guarantee.
|
Chris@16
|
745 //!
|
Chris@16
|
746 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
747 //! to the erased elements. No destructors are called.
|
Chris@16
|
748 iterator erase(const_iterator b, const_iterator e)
|
Chris@16
|
749 { size_type n; return private_erase(b, e, n); }
|
Chris@16
|
750
|
Chris@16
|
751 //! <b>Effects</b>: Erases all the elements with the given value.
|
Chris@16
|
752 //!
|
Chris@16
|
753 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
754 //!
|
Chris@16
|
755 //! <b>Complexity</b>: O(log(size() + N).
|
Chris@16
|
756 //!
|
Chris@16
|
757 //! <b>Throws</b>: if the internal priority_compare function throws. Strong guarantee.
|
Chris@16
|
758 //!
|
Chris@16
|
759 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
760 //! to the erased elements. No destructors are called.
|
Chris@16
|
761 size_type erase(const_reference value)
|
Chris@16
|
762 { return this->erase(value, this->value_comp()); }
|
Chris@16
|
763
|
Chris@16
|
764 //! <b>Effects</b>: Erases all the elements with the given key.
|
Chris@16
|
765 //! according to the comparison functor "comp".
|
Chris@16
|
766 //!
|
Chris@16
|
767 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
768 //!
|
Chris@16
|
769 //! <b>Complexity</b>: O(log(size() + N).
|
Chris@16
|
770 //!
|
Chris@16
|
771 //! <b>Throws</b>: if the internal priority_compare function throws.
|
Chris@16
|
772 //! Equivalent guarantee to <i>while(beg != end) erase(beg++);</i>
|
Chris@16
|
773 //!
|
Chris@16
|
774 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
775 //! to the erased elements. No destructors are called.
|
Chris@16
|
776 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
777 size_type erase(const KeyType& key, KeyValueCompare comp
|
Chris@16
|
778 /// @cond
|
Chris@16
|
779 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
|
Chris@16
|
780 /// @endcond
|
Chris@16
|
781 )
|
Chris@16
|
782 {
|
Chris@16
|
783 std::pair<iterator,iterator> p = this->equal_range(key, comp);
|
Chris@16
|
784 size_type n;
|
Chris@16
|
785 private_erase(p.first, p.second, n);
|
Chris@16
|
786 return n;
|
Chris@16
|
787 }
|
Chris@16
|
788
|
Chris@16
|
789 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
790 //!
|
Chris@101
|
791 //! <b>Effects</b>: Erases the element pointed to by i.
|
Chris@16
|
792 //! Disposer::operator()(pointer) is called for the removed element.
|
Chris@16
|
793 //!
|
Chris@16
|
794 //! <b>Complexity</b>: Average complexity for erase element is constant time.
|
Chris@16
|
795 //!
|
Chris@16
|
796 //! <b>Throws</b>: if the internal priority_compare function throws. Strong guarantee.
|
Chris@16
|
797 //!
|
Chris@16
|
798 //! <b>Note</b>: Invalidates the iterators
|
Chris@16
|
799 //! to the erased elements.
|
Chris@16
|
800 template<class Disposer>
|
Chris@16
|
801 iterator erase_and_dispose(const_iterator i, Disposer disposer)
|
Chris@16
|
802 {
|
Chris@16
|
803 node_ptr to_erase(i.pointed_node());
|
Chris@16
|
804 iterator ret(this->erase(i));
|
Chris@101
|
805 disposer(this->get_value_traits().to_value_ptr(to_erase));
|
Chris@16
|
806 return ret;
|
Chris@16
|
807 }
|
Chris@16
|
808
|
Chris@16
|
809 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
810 template<class Disposer>
|
Chris@16
|
811 iterator erase_and_dispose(iterator i, Disposer disposer)
|
Chris@16
|
812 { return this->erase_and_dispose(const_iterator(i), disposer); }
|
Chris@16
|
813 #endif
|
Chris@16
|
814
|
Chris@16
|
815 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
816 //!
|
Chris@16
|
817 //! <b>Effects</b>: Erases the range pointed to by b end e.
|
Chris@16
|
818 //! Disposer::operator()(pointer) is called for the removed elements.
|
Chris@16
|
819 //!
|
Chris@16
|
820 //! <b>Complexity</b>: Average complexity for erase range is at most
|
Chris@16
|
821 //! O(log(size() + N)), where N is the number of elements in the range.
|
Chris@16
|
822 //!
|
Chris@16
|
823 //! <b>Throws</b>: if the internal priority_compare function throws. Strong guarantee.
|
Chris@16
|
824 //!
|
Chris@16
|
825 //! <b>Note</b>: Invalidates the iterators
|
Chris@16
|
826 //! to the erased elements.
|
Chris@16
|
827 template<class Disposer>
|
Chris@16
|
828 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
|
Chris@16
|
829 { size_type n; return private_erase(b, e, n, disposer); }
|
Chris@16
|
830
|
Chris@16
|
831 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
832 //!
|
Chris@16
|
833 //! <b>Effects</b>: Erases all the elements with the given value.
|
Chris@16
|
834 //! Disposer::operator()(pointer) is called for the removed elements.
|
Chris@16
|
835 //!
|
Chris@16
|
836 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
837 //!
|
Chris@16
|
838 //! <b>Complexity</b>: O(log(size() + N).
|
Chris@16
|
839 //!
|
Chris@16
|
840 //! <b>Throws</b>: if the priority_compare function throws then weak guarantee and heap invariants are broken.
|
Chris@16
|
841 //! The safest thing would be to clear or destroy the container.
|
Chris@16
|
842 //!
|
Chris@16
|
843 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
844 //! to the erased elements. No destructors are called.
|
Chris@16
|
845 template<class Disposer>
|
Chris@16
|
846 size_type erase_and_dispose(const_reference value, Disposer disposer)
|
Chris@16
|
847 {
|
Chris@16
|
848 std::pair<iterator,iterator> p = this->equal_range(value);
|
Chris@16
|
849 size_type n;
|
Chris@16
|
850 private_erase(p.first, p.second, n, disposer);
|
Chris@16
|
851 return n;
|
Chris@16
|
852 }
|
Chris@16
|
853
|
Chris@16
|
854 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
855 //!
|
Chris@16
|
856 //! <b>Effects</b>: Erases all the elements with the given key.
|
Chris@16
|
857 //! according to the comparison functor "comp".
|
Chris@16
|
858 //! Disposer::operator()(pointer) is called for the removed elements.
|
Chris@16
|
859 //!
|
Chris@16
|
860 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
861 //!
|
Chris@16
|
862 //! <b>Complexity</b>: O(log(size() + N).
|
Chris@16
|
863 //!
|
Chris@16
|
864 //! <b>Throws</b>: if the priority_compare function throws then weak guarantee and heap invariants are broken.
|
Chris@16
|
865 //! The safest thing would be to clear or destroy the container.
|
Chris@16
|
866 //!
|
Chris@16
|
867 //! <b>Note</b>: Invalidates the iterators
|
Chris@16
|
868 //! to the erased elements.
|
Chris@16
|
869 template<class KeyType, class KeyValueCompare, class Disposer>
|
Chris@16
|
870 size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer
|
Chris@16
|
871 /// @cond
|
Chris@16
|
872 , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
|
Chris@16
|
873 /// @endcond
|
Chris@16
|
874 )
|
Chris@16
|
875 {
|
Chris@16
|
876 std::pair<iterator,iterator> p = this->equal_range(key, comp);
|
Chris@16
|
877 size_type n;
|
Chris@16
|
878 private_erase(p.first, p.second, n, disposer);
|
Chris@16
|
879 return n;
|
Chris@16
|
880 }
|
Chris@16
|
881
|
Chris@16
|
882 //! <b>Effects</b>: Erases all of the elements.
|
Chris@16
|
883 //!
|
Chris@16
|
884 //! <b>Complexity</b>: Linear to the number of elements on the container.
|
Chris@16
|
885 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
|
Chris@16
|
886 //!
|
Chris@16
|
887 //! <b>Throws</b>: Nothing.
|
Chris@16
|
888 //!
|
Chris@16
|
889 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
890 //! to the erased elements. No destructors are called.
|
Chris@16
|
891 void clear()
|
Chris@16
|
892 { tree_type::clear(); }
|
Chris@16
|
893
|
Chris@16
|
894 //! <b>Effects</b>: Erases all of the elements calling disposer(p) for
|
Chris@16
|
895 //! each node to be erased.
|
Chris@16
|
896 //! <b>Complexity</b>: Average complexity for is at most O(log(size() + N)),
|
Chris@16
|
897 //! where N is the number of elements in the container.
|
Chris@16
|
898 //!
|
Chris@16
|
899 //! <b>Throws</b>: Nothing.
|
Chris@16
|
900 //!
|
Chris@16
|
901 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
902 //! to the erased elements. Calls N times to disposer functor.
|
Chris@16
|
903 template<class Disposer>
|
Chris@16
|
904 void clear_and_dispose(Disposer disposer)
|
Chris@16
|
905 {
|
Chris@16
|
906 node_algorithms::clear_and_dispose(this->tree_type::header_ptr()
|
Chris@101
|
907 , detail::node_disposer<Disposer, value_traits, TreapAlgorithms>(disposer, &this->get_value_traits()));
|
Chris@16
|
908 node_algorithms::init_header(this->tree_type::header_ptr());
|
Chris@16
|
909 this->tree_type::sz_traits().set_size(0);
|
Chris@16
|
910 }
|
Chris@16
|
911
|
Chris@101
|
912 //! @copydoc ::boost::intrusive::bstree::check(ExtraChecker)const
|
Chris@101
|
913 template <class ExtraChecker>
|
Chris@101
|
914 void check(ExtraChecker extra_checker) const
|
Chris@101
|
915 {
|
Chris@101
|
916 typedef detail::key_nodeptr_comp<priority_compare, value_traits> nodeptr_prio_comp_t;
|
Chris@101
|
917 nodeptr_prio_comp_t nodeptr_prio_comp(priv_pcomp(), &this->get_value_traits());
|
Chris@101
|
918 tree_type::check(detail::treap_node_extra_checker<ValueTraits, nodeptr_prio_comp_t, ExtraChecker>(nodeptr_prio_comp, extra_checker));
|
Chris@101
|
919 }
|
Chris@101
|
920
|
Chris@101
|
921 //! @copydoc ::boost::intrusive::bstree::check()const
|
Chris@101
|
922 void check() const
|
Chris@101
|
923 { check(detail::empty_node_checker<ValueTraits>()); }
|
Chris@101
|
924
|
Chris@16
|
925 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
926 //! @copydoc ::boost::intrusive::bstree::count(const_reference)const
|
Chris@16
|
927 size_type count(const_reference value) const;
|
Chris@16
|
928
|
Chris@16
|
929 //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const
|
Chris@16
|
930 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
931 size_type count(const KeyType& key, KeyValueCompare comp) const;
|
Chris@101
|
932
|
Chris@16
|
933 //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)
|
Chris@16
|
934 iterator lower_bound(const_reference value);
|
Chris@101
|
935
|
Chris@16
|
936 //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)
|
Chris@16
|
937 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
938 iterator lower_bound(const KeyType& key, KeyValueCompare comp);
|
Chris@16
|
939
|
Chris@16
|
940 //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const
|
Chris@16
|
941 const_iterator lower_bound(const_reference value) const;
|
Chris@16
|
942
|
Chris@16
|
943 //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const
|
Chris@16
|
944 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
945 const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const;
|
Chris@16
|
946
|
Chris@16
|
947 //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)
|
Chris@16
|
948 iterator upper_bound(const_reference value);
|
Chris@16
|
949
|
Chris@16
|
950 //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)
|
Chris@16
|
951 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
952 iterator upper_bound(const KeyType& key, KeyValueCompare comp);
|
Chris@16
|
953
|
Chris@16
|
954 //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const
|
Chris@16
|
955 const_iterator upper_bound(const_reference value) const;
|
Chris@16
|
956
|
Chris@16
|
957 //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const
|
Chris@16
|
958 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
959 const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const;
|
Chris@16
|
960
|
Chris@16
|
961 //! @copydoc ::boost::intrusive::bstree::find(const_reference)
|
Chris@16
|
962 iterator find(const_reference value);
|
Chris@16
|
963
|
Chris@16
|
964 //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)
|
Chris@16
|
965 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
966 iterator find(const KeyType& key, KeyValueCompare comp);
|
Chris@16
|
967
|
Chris@16
|
968 //! @copydoc ::boost::intrusive::bstree::find(const_reference)const
|
Chris@16
|
969 const_iterator find(const_reference value) const;
|
Chris@16
|
970
|
Chris@16
|
971 //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const
|
Chris@16
|
972 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
973 const_iterator find(const KeyType& key, KeyValueCompare comp) const;
|
Chris@16
|
974
|
Chris@16
|
975 //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)
|
Chris@16
|
976 std::pair<iterator,iterator> equal_range(const_reference value);
|
Chris@16
|
977
|
Chris@16
|
978 //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)
|
Chris@16
|
979 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
980 std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp);
|
Chris@16
|
981
|
Chris@16
|
982 //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const
|
Chris@16
|
983 std::pair<const_iterator, const_iterator>
|
Chris@16
|
984 equal_range(const_reference value) const;
|
Chris@16
|
985
|
Chris@16
|
986 //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)const
|
Chris@16
|
987 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
988 std::pair<const_iterator, const_iterator>
|
Chris@16
|
989 equal_range(const KeyType& key, KeyValueCompare comp) const;
|
Chris@16
|
990
|
Chris@16
|
991 //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)
|
Chris@16
|
992 std::pair<iterator,iterator> bounded_range
|
Chris@16
|
993 (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed);
|
Chris@16
|
994
|
Chris@16
|
995 //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)
|
Chris@16
|
996 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
997 std::pair<iterator,iterator> bounded_range
|
Chris@16
|
998 (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed);
|
Chris@16
|
999
|
Chris@16
|
1000 //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const
|
Chris@16
|
1001 std::pair<const_iterator, const_iterator>
|
Chris@16
|
1002 bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const;
|
Chris@16
|
1003
|
Chris@16
|
1004 //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const
|
Chris@16
|
1005 template<class KeyType, class KeyValueCompare>
|
Chris@16
|
1006 std::pair<const_iterator, const_iterator> bounded_range
|
Chris@16
|
1007 (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const;
|
Chris@16
|
1008
|
Chris@16
|
1009 //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference)
|
Chris@16
|
1010 static iterator s_iterator_to(reference value);
|
Chris@16
|
1011
|
Chris@16
|
1012 //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference)
|
Chris@16
|
1013 static const_iterator s_iterator_to(const_reference value);
|
Chris@16
|
1014
|
Chris@16
|
1015 //! @copydoc ::boost::intrusive::bstree::iterator_to(reference)
|
Chris@16
|
1016 iterator iterator_to(reference value);
|
Chris@16
|
1017
|
Chris@16
|
1018 //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const
|
Chris@16
|
1019 const_iterator iterator_to(const_reference value) const;
|
Chris@16
|
1020
|
Chris@16
|
1021 //! @copydoc ::boost::intrusive::bstree::init_node(reference)
|
Chris@16
|
1022 static void init_node(reference value);
|
Chris@16
|
1023
|
Chris@16
|
1024 //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance
|
Chris@16
|
1025 pointer unlink_leftmost_without_rebalance();
|
Chris@16
|
1026
|
Chris@16
|
1027 //! @copydoc ::boost::intrusive::bstree::replace_node
|
Chris@16
|
1028 void replace_node(iterator replace_this, reference with_this);
|
Chris@16
|
1029
|
Chris@16
|
1030 //! @copydoc ::boost::intrusive::bstree::remove_node
|
Chris@16
|
1031 void remove_node(reference value);
|
Chris@16
|
1032
|
Chris@16
|
1033 #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
1034
|
Chris@16
|
1035 /// @cond
|
Chris@16
|
1036 private:
|
Chris@16
|
1037 template<class Disposer>
|
Chris@16
|
1038 iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
|
Chris@16
|
1039 {
|
Chris@16
|
1040 for(n = 0; b != e; ++n)
|
Chris@16
|
1041 this->erase_and_dispose(b++, disposer);
|
Chris@16
|
1042 return b.unconst();
|
Chris@16
|
1043 }
|
Chris@16
|
1044
|
Chris@16
|
1045 iterator private_erase(const_iterator b, const_iterator e, size_type &n)
|
Chris@16
|
1046 {
|
Chris@16
|
1047 for(n = 0; b != e; ++n)
|
Chris@16
|
1048 this->erase(b++);
|
Chris@16
|
1049 return b.unconst();
|
Chris@16
|
1050 }
|
Chris@16
|
1051 /// @endcond
|
Chris@16
|
1052 };
|
Chris@16
|
1053
|
Chris@16
|
1054 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1055
|
Chris@16
|
1056 template<class T, class ...Options>
|
Chris@16
|
1057 bool operator< (const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
|
Chris@16
|
1058
|
Chris@16
|
1059 template<class T, class ...Options>
|
Chris@16
|
1060 bool operator==(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
|
Chris@16
|
1061
|
Chris@16
|
1062 template<class T, class ...Options>
|
Chris@16
|
1063 bool operator!= (const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
|
Chris@16
|
1064
|
Chris@16
|
1065 template<class T, class ...Options>
|
Chris@16
|
1066 bool operator>(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
|
Chris@16
|
1067
|
Chris@16
|
1068 template<class T, class ...Options>
|
Chris@16
|
1069 bool operator<=(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
|
Chris@16
|
1070
|
Chris@16
|
1071 template<class T, class ...Options>
|
Chris@16
|
1072 bool operator>=(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y);
|
Chris@16
|
1073
|
Chris@16
|
1074 template<class T, class ...Options>
|
Chris@16
|
1075 void swap(treap_impl<T, Options...> &x, treap_impl<T, Options...> &y);
|
Chris@16
|
1076
|
Chris@16
|
1077 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1078
|
Chris@16
|
1079 //! Helper metafunction to define a \c treap that yields to the same type when the
|
Chris@16
|
1080 //! same options (either explicitly or implicitly) are used.
|
Chris@16
|
1081 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
1082 template<class T, class ...Options>
|
Chris@16
|
1083 #else
|
Chris@16
|
1084 template<class T, class O1 = void, class O2 = void
|
Chris@101
|
1085 , class O3 = void, class O4 = void
|
Chris@101
|
1086 , class O5 = void>
|
Chris@16
|
1087 #endif
|
Chris@16
|
1088 struct make_treap
|
Chris@16
|
1089 {
|
Chris@16
|
1090 typedef typename pack_options
|
Chris@16
|
1091 < treap_defaults,
|
Chris@16
|
1092 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@101
|
1093 O1, O2, O3, O4, O5
|
Chris@16
|
1094 #else
|
Chris@16
|
1095 Options...
|
Chris@16
|
1096 #endif
|
Chris@16
|
1097 >::type packed_options;
|
Chris@16
|
1098
|
Chris@16
|
1099 typedef typename detail::get_value_traits
|
Chris@16
|
1100 <T, typename packed_options::proto_value_traits>::type value_traits;
|
Chris@16
|
1101
|
Chris@16
|
1102 typedef treap_impl
|
Chris@16
|
1103 < value_traits
|
Chris@16
|
1104 , typename packed_options::compare
|
Chris@16
|
1105 , typename packed_options::priority
|
Chris@16
|
1106 , typename packed_options::size_type
|
Chris@16
|
1107 , packed_options::constant_time_size
|
Chris@101
|
1108 , typename packed_options::header_holder_type
|
Chris@16
|
1109 > implementation_defined;
|
Chris@16
|
1110 /// @endcond
|
Chris@16
|
1111 typedef implementation_defined type;
|
Chris@16
|
1112 };
|
Chris@16
|
1113
|
Chris@16
|
1114 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
1115
|
Chris@16
|
1116 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@101
|
1117 template<class T, class O1, class O2, class O3, class O4, class O5>
|
Chris@16
|
1118 #else
|
Chris@16
|
1119 template<class T, class ...Options>
|
Chris@16
|
1120 #endif
|
Chris@16
|
1121 class treap
|
Chris@16
|
1122 : public make_treap<T,
|
Chris@16
|
1123 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@101
|
1124 O1, O2, O3, O4, O5
|
Chris@16
|
1125 #else
|
Chris@16
|
1126 Options...
|
Chris@16
|
1127 #endif
|
Chris@16
|
1128 >::type
|
Chris@16
|
1129 {
|
Chris@16
|
1130 typedef typename make_treap
|
Chris@16
|
1131 <T,
|
Chris@16
|
1132 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@101
|
1133 O1, O2, O3, O4, O5
|
Chris@16
|
1134 #else
|
Chris@16
|
1135 Options...
|
Chris@16
|
1136 #endif
|
Chris@16
|
1137 >::type Base;
|
Chris@16
|
1138 BOOST_MOVABLE_BUT_NOT_COPYABLE(treap)
|
Chris@16
|
1139
|
Chris@16
|
1140 public:
|
Chris@16
|
1141 typedef typename Base::value_compare value_compare;
|
Chris@16
|
1142 typedef typename Base::priority_compare priority_compare;
|
Chris@16
|
1143 typedef typename Base::value_traits value_traits;
|
Chris@16
|
1144 typedef typename Base::iterator iterator;
|
Chris@16
|
1145 typedef typename Base::const_iterator const_iterator;
|
Chris@16
|
1146 typedef typename Base::reverse_iterator reverse_iterator;
|
Chris@16
|
1147 typedef typename Base::const_reverse_iterator const_reverse_iterator;
|
Chris@16
|
1148
|
Chris@16
|
1149 //Assert if passed value traits are compatible with the type
|
Chris@101
|
1150 BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
|
Chris@16
|
1151
|
Chris@16
|
1152 explicit treap( const value_compare &cmp = value_compare()
|
Chris@16
|
1153 , const priority_compare &pcmp = priority_compare()
|
Chris@16
|
1154 , const value_traits &v_traits = value_traits())
|
Chris@16
|
1155 : Base(cmp, pcmp, v_traits)
|
Chris@16
|
1156 {}
|
Chris@16
|
1157
|
Chris@16
|
1158 template<class Iterator>
|
Chris@16
|
1159 treap( bool unique, Iterator b, Iterator e
|
Chris@16
|
1160 , const value_compare &cmp = value_compare()
|
Chris@16
|
1161 , const priority_compare &pcmp = priority_compare()
|
Chris@16
|
1162 , const value_traits &v_traits = value_traits())
|
Chris@16
|
1163 : Base(unique, b, e, cmp, pcmp, v_traits)
|
Chris@16
|
1164 {}
|
Chris@16
|
1165
|
Chris@16
|
1166 treap(BOOST_RV_REF(treap) x)
|
Chris@101
|
1167 : Base(BOOST_MOVE_BASE(Base, x))
|
Chris@16
|
1168 {}
|
Chris@16
|
1169
|
Chris@16
|
1170 treap& operator=(BOOST_RV_REF(treap) x)
|
Chris@101
|
1171 { return static_cast<treap&>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
|
Chris@16
|
1172
|
Chris@16
|
1173 static treap &container_from_end_iterator(iterator end_iterator)
|
Chris@16
|
1174 { return static_cast<treap &>(Base::container_from_end_iterator(end_iterator)); }
|
Chris@16
|
1175
|
Chris@16
|
1176 static const treap &container_from_end_iterator(const_iterator end_iterator)
|
Chris@16
|
1177 { return static_cast<const treap &>(Base::container_from_end_iterator(end_iterator)); }
|
Chris@16
|
1178
|
Chris@16
|
1179 static treap &container_from_iterator(iterator it)
|
Chris@16
|
1180 { return static_cast<treap &>(Base::container_from_iterator(it)); }
|
Chris@16
|
1181
|
Chris@16
|
1182 static const treap &container_from_iterator(const_iterator it)
|
Chris@16
|
1183 { return static_cast<const treap &>(Base::container_from_iterator(it)); }
|
Chris@16
|
1184 };
|
Chris@16
|
1185
|
Chris@16
|
1186 #endif
|
Chris@16
|
1187
|
Chris@16
|
1188 } //namespace intrusive
|
Chris@16
|
1189 } //namespace boost
|
Chris@16
|
1190
|
Chris@16
|
1191 #include <boost/intrusive/detail/config_end.hpp>
|
Chris@16
|
1192
|
Chris@16
|
1193 #endif //BOOST_INTRUSIVE_TREAP_HPP
|