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