File indexing completed on 2025-01-18 09:38:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_INTRUSIVE_AVLTREE_HPP
0013 #define BOOST_INTRUSIVE_AVLTREE_HPP
0014
0015 #include <boost/intrusive/detail/config_begin.hpp>
0016 #include <boost/intrusive/intrusive_fwd.hpp>
0017 #include <cstddef>
0018 #include <boost/intrusive/detail/minimal_less_equal_header.hpp>
0019 #include <boost/intrusive/detail/minimal_pair_header.hpp>
0020
0021 #include <boost/static_assert.hpp>
0022 #include <boost/intrusive/avl_set_hook.hpp>
0023 #include <boost/intrusive/detail/avltree_node.hpp>
0024 #include <boost/intrusive/bstree.hpp>
0025 #include <boost/intrusive/detail/tree_node.hpp>
0026 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
0027 #include <boost/intrusive/detail/mpl.hpp>
0028 #include <boost/intrusive/pointer_traits.hpp>
0029 #include <boost/intrusive/detail/get_value_traits.hpp>
0030 #include <boost/intrusive/avltree_algorithms.hpp>
0031 #include <boost/intrusive/link_mode.hpp>
0032 #include <boost/move/utility_core.hpp>
0033
0034 #if defined(BOOST_HAS_PRAGMA_ONCE)
0035 # pragma once
0036 #endif
0037
0038 namespace boost {
0039 namespace intrusive {
0040
0041
0042
0043 struct default_avltree_hook_applier
0044 { template <class T> struct apply{ typedef typename T::default_avltree_hook type; }; };
0045
0046 template<>
0047 struct is_default_hook_tag<default_avltree_hook_applier>
0048 { static const bool value = true; };
0049
0050 struct avltree_defaults
0051 : bstree_defaults
0052 {
0053 typedef default_avltree_hook_applier proto_value_traits;
0054 };
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
0072 template<class T, class ...Options>
0073 #else
0074 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, class SizeType, bool ConstantTimeSize, typename HeaderHolder>
0075 #endif
0076 class avltree_impl
0077
0078 : public bstree_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, SizeType, ConstantTimeSize, AvlTreeAlgorithms, HeaderHolder>
0079
0080 {
0081 public:
0082 typedef ValueTraits value_traits;
0083
0084 typedef bstree_impl< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, SizeType
0085 , ConstantTimeSize, AvlTreeAlgorithms
0086 , HeaderHolder> tree_type;
0087 typedef tree_type implementation_defined;
0088
0089
0090 typedef typename implementation_defined::pointer pointer;
0091 typedef typename implementation_defined::const_pointer const_pointer;
0092 typedef typename implementation_defined::value_type value_type;
0093 typedef typename implementation_defined::key_type key_type;
0094 typedef typename implementation_defined::key_of_value key_of_value;
0095 typedef typename implementation_defined::reference reference;
0096 typedef typename implementation_defined::const_reference const_reference;
0097 typedef typename implementation_defined::difference_type difference_type;
0098 typedef typename implementation_defined::size_type size_type;
0099 typedef typename implementation_defined::value_compare value_compare;
0100 typedef typename implementation_defined::key_compare key_compare;
0101 typedef typename implementation_defined::iterator iterator;
0102 typedef typename implementation_defined::const_iterator const_iterator;
0103 typedef typename implementation_defined::reverse_iterator reverse_iterator;
0104 typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
0105 typedef typename implementation_defined::node_traits node_traits;
0106 typedef typename implementation_defined::node node;
0107 typedef typename implementation_defined::node_ptr node_ptr;
0108 typedef typename implementation_defined::const_node_ptr const_node_ptr;
0109 typedef typename implementation_defined::node_algorithms node_algorithms;
0110
0111 static const bool constant_time_size = implementation_defined::constant_time_size;
0112
0113 private:
0114
0115
0116 BOOST_MOVABLE_BUT_NOT_COPYABLE(avltree_impl)
0117
0118
0119
0120 public:
0121
0122 typedef typename implementation_defined::insert_commit_data insert_commit_data;
0123
0124
0125 avltree_impl()
0126 : tree_type()
0127 {}
0128
0129
0130 explicit avltree_impl( const key_compare &cmp, const value_traits &v_traits = value_traits())
0131 : tree_type(cmp, v_traits)
0132 {}
0133
0134
0135 template<class Iterator>
0136 avltree_impl( bool unique, Iterator b, Iterator e
0137 , const key_compare &cmp = key_compare()
0138 , const value_traits &v_traits = value_traits())
0139 : tree_type(unique, b, e, cmp, v_traits)
0140 {}
0141
0142
0143 avltree_impl(BOOST_RV_REF(avltree_impl) x)
0144 : tree_type(BOOST_MOVE_BASE(tree_type, x))
0145 {}
0146
0147
0148 avltree_impl& operator=(BOOST_RV_REF(avltree_impl) x)
0149 { return static_cast<avltree_impl&>(tree_type::operator=(BOOST_MOVE_BASE(tree_type, x))); }
0150
0151 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
0152
0153
0154 ~avltree_impl();
0155
0156
0157 iterator begin() BOOST_NOEXCEPT;
0158
0159
0160 const_iterator begin() const BOOST_NOEXCEPT;
0161
0162
0163 const_iterator cbegin() const BOOST_NOEXCEPT;
0164
0165
0166 iterator end() BOOST_NOEXCEPT;
0167
0168
0169 const_iterator end() const BOOST_NOEXCEPT;
0170
0171
0172 const_iterator cend() const BOOST_NOEXCEPT;
0173
0174
0175 reverse_iterator rbegin() BOOST_NOEXCEPT;
0176
0177
0178 const_reverse_iterator rbegin() const BOOST_NOEXCEPT;
0179
0180
0181 const_reverse_iterator crbegin() const BOOST_NOEXCEPT;
0182
0183
0184 reverse_iterator rend() BOOST_NOEXCEPT;
0185
0186
0187 const_reverse_iterator rend() const BOOST_NOEXCEPT;
0188
0189
0190 const_reverse_iterator crend() const BOOST_NOEXCEPT;
0191
0192
0193 iterator root() BOOST_NOEXCEPT;
0194
0195
0196 const_iterator root() const BOOST_NOEXCEPT;
0197
0198
0199 const_iterator croot() const BOOST_NOEXCEPT;
0200
0201
0202 static avltree_impl &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT;
0203
0204
0205 static const avltree_impl &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT;
0206
0207
0208 static avltree_impl &container_from_iterator(iterator it) BOOST_NOEXCEPT;
0209
0210
0211 static const avltree_impl &container_from_iterator(const_iterator it) BOOST_NOEXCEPT;
0212
0213
0214 key_compare key_comp() const;
0215
0216
0217 value_compare value_comp() const;
0218
0219
0220 bool empty() const BOOST_NOEXCEPT;
0221
0222
0223 size_type size() const BOOST_NOEXCEPT;
0224
0225
0226 void swap(avltree_impl& other);
0227
0228
0229 template <class Cloner, class Disposer>
0230 void clone_from(const avltree_impl &src, Cloner cloner, Disposer disposer);
0231
0232 #else
0233
0234 using tree_type::clone_from;
0235
0236 #endif
0237
0238
0239 template <class Cloner, class Disposer>
0240 void clone_from(BOOST_RV_REF(avltree_impl) src, Cloner cloner, Disposer disposer)
0241 { tree_type::clone_from(BOOST_MOVE_BASE(tree_type, src), cloner, disposer); }
0242
0243 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
0244
0245
0246 iterator insert_equal(reference value);
0247
0248
0249 iterator insert_equal(const_iterator hint, reference value);
0250
0251
0252 template<class Iterator>
0253 void insert_equal(Iterator b, Iterator e);
0254
0255
0256 std::pair<iterator, bool> insert_unique(reference value);
0257
0258
0259 iterator insert_unique(const_iterator hint, reference value);
0260
0261
0262 template<class KeyType, class KeyTypeKeyCompare>
0263 std::pair<iterator, bool> insert_unique_check
0264 (const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data);
0265
0266
0267 template<class KeyType, class KeyTypeKeyCompare>
0268 std::pair<iterator, bool> insert_unique_check
0269 (const_iterator hint, const KeyType &key
0270 ,KeyTypeKeyCompare comp, insert_commit_data &commit_data);
0271
0272
0273 std::pair<iterator, bool> insert_unique_check
0274 (const key_type &key, insert_commit_data &commit_data);
0275
0276
0277 std::pair<iterator, bool> insert_unique_check
0278 (const_iterator hint, const key_type &key, insert_commit_data &commit_data);
0279
0280
0281 iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) BOOST_NOEXCEPT;
0282
0283
0284 template<class Iterator>
0285 void insert_unique(Iterator b, Iterator e);
0286
0287
0288 iterator insert_before(const_iterator pos, reference value) BOOST_NOEXCEPT;
0289
0290
0291 void push_back(reference value) BOOST_NOEXCEPT;
0292
0293
0294 void push_front(reference value) BOOST_NOEXCEPT;
0295
0296
0297 iterator erase(const_iterator i) BOOST_NOEXCEPT;
0298
0299
0300 iterator erase(const_iterator b, const_iterator e) BOOST_NOEXCEPT;
0301
0302
0303 size_type erase(const key_type &key);
0304
0305
0306 template<class KeyType, class KeyTypeKeyCompare>
0307 size_type erase(const KeyType& key, KeyTypeKeyCompare comp);
0308
0309
0310 template<class Disposer>
0311 iterator erase_and_dispose(const_iterator i, Disposer disposer) BOOST_NOEXCEPT;
0312
0313
0314 template<class Disposer>
0315 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) BOOST_NOEXCEPT;
0316
0317
0318 template<class Disposer>
0319 size_type erase_and_dispose(const key_type &key, Disposer disposer);
0320
0321
0322 template<class KeyType, class KeyTypeKeyCompare, class Disposer>
0323 size_type erase_and_dispose(const KeyType& key, KeyTypeKeyCompare comp, Disposer disposer);
0324
0325
0326 void clear() BOOST_NOEXCEPT;
0327
0328
0329 template<class Disposer>
0330 void clear_and_dispose(Disposer disposer) BOOST_NOEXCEPT;
0331
0332
0333 size_type count(const key_type &key) const;
0334
0335
0336 template<class KeyType, class KeyTypeKeyCompare>
0337 size_type count(const KeyType& key, KeyTypeKeyCompare comp) const;
0338
0339
0340 iterator lower_bound(const key_type &key);
0341
0342
0343 template<class KeyType, class KeyTypeKeyCompare>
0344 iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp);
0345
0346
0347 const_iterator lower_bound(const key_type &key) const;
0348
0349
0350 template<class KeyType, class KeyTypeKeyCompare>
0351 const_iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
0352
0353
0354 iterator upper_bound(const key_type &key);
0355
0356
0357 template<class KeyType, class KeyTypeKeyCompare>
0358 iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp);
0359
0360
0361 const_iterator upper_bound(const key_type &key) const;
0362
0363
0364 template<class KeyType, class KeyTypeKeyCompare>
0365 const_iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
0366
0367
0368 iterator find(const key_type &key);
0369
0370
0371 template<class KeyType, class KeyTypeKeyCompare>
0372 iterator find(const KeyType& key, KeyTypeKeyCompare comp);
0373
0374
0375 const_iterator find(const key_type &key) const;
0376
0377
0378 template<class KeyType, class KeyTypeKeyCompare>
0379 const_iterator find(const KeyType& key, KeyTypeKeyCompare comp) const;
0380
0381
0382 std::pair<iterator,iterator> equal_range(const key_type &key);
0383
0384
0385 template<class KeyType, class KeyTypeKeyCompare>
0386 std::pair<iterator,iterator> equal_range(const KeyType& key, KeyTypeKeyCompare comp);
0387
0388
0389 std::pair<const_iterator, const_iterator>
0390 equal_range(const key_type &key) const;
0391
0392
0393 template<class KeyType, class KeyTypeKeyCompare>
0394 std::pair<const_iterator, const_iterator>
0395 equal_range(const KeyType& key, KeyTypeKeyCompare comp) const;
0396
0397
0398 std::pair<iterator,iterator> bounded_range
0399 (const key_type &lower, const key_type &upper_key, bool left_closed, bool right_closed);
0400
0401
0402 template<class KeyType, class KeyTypeKeyCompare>
0403 std::pair<iterator,iterator> bounded_range
0404 (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed);
0405
0406
0407 std::pair<const_iterator, const_iterator>
0408 bounded_range(const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const;
0409
0410
0411 template<class KeyType, class KeyTypeKeyCompare>
0412 std::pair<const_iterator, const_iterator> bounded_range
0413 (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const;
0414
0415
0416 static iterator s_iterator_to(reference value) BOOST_NOEXCEPT;
0417
0418
0419 static const_iterator s_iterator_to(const_reference value) BOOST_NOEXCEPT;
0420
0421
0422 iterator iterator_to(reference value) BOOST_NOEXCEPT;
0423
0424
0425 const_iterator iterator_to(const_reference value) const BOOST_NOEXCEPT;
0426
0427
0428 static void init_node(reference value) BOOST_NOEXCEPT;
0429
0430
0431 pointer unlink_leftmost_without_rebalance() BOOST_NOEXCEPT;
0432
0433
0434 void replace_node(iterator replace_this, reference with_this) BOOST_NOEXCEPT;
0435
0436
0437 void remove_node(reference value) BOOST_NOEXCEPT;
0438
0439
0440 template<class T, class ...Options2>
0441 void merge_unique(avltree<T, Options2...> &);
0442
0443
0444 template<class T, class ...Options2>
0445 void merge_equal(avltree<T, Options2...> &);
0446
0447 friend bool operator< (const avltree_impl &x, const avltree_impl &y);
0448
0449 friend bool operator==(const avltree_impl &x, const avltree_impl &y);
0450
0451 friend bool operator!= (const avltree_impl &x, const avltree_impl &y);
0452
0453 friend bool operator>(const avltree_impl &x, const avltree_impl &y);
0454
0455 friend bool operator<=(const avltree_impl &x, const avltree_impl &y);
0456
0457 friend bool operator>=(const avltree_impl &x, const avltree_impl &y);
0458
0459 friend void swap(avltree_impl &x, avltree_impl &y);
0460 #endif
0461 };
0462
0463
0464
0465
0466 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
0467 template<class T, class ...Options>
0468 #else
0469 template<class T, class O1 = void, class O2 = void
0470 , class O3 = void, class O4 = void
0471 , class O5 = void, class O6 = void>
0472 #endif
0473 struct make_avltree
0474 {
0475
0476 typedef typename pack_options
0477 < avltree_defaults,
0478 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
0479 O1, O2, O3, O4, O5, O6
0480 #else
0481 Options...
0482 #endif
0483 >::type packed_options;
0484
0485 typedef typename detail::get_value_traits
0486 <T, typename packed_options::proto_value_traits>::type value_traits;
0487
0488 typedef avltree_impl
0489 < value_traits
0490 , typename packed_options::key_of_value
0491 , typename packed_options::compare
0492 , typename packed_options::size_type
0493 , packed_options::constant_time_size
0494 , typename packed_options::header_holder_type
0495 > implementation_defined;
0496
0497 typedef implementation_defined type;
0498 };
0499
0500
0501 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
0502
0503 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
0504 template<class T, class O1, class O2, class O3, class O4, class O5, class O6>
0505 #else
0506 template<class T, class ...Options>
0507 #endif
0508 class avltree
0509 : public make_avltree<T,
0510 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
0511 O1, O2, O3, O4, O5, O6
0512 #else
0513 Options...
0514 #endif
0515 >::type
0516 {
0517 typedef typename make_avltree
0518 <T,
0519 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
0520 O1, O2, O3, O4, O5, O6
0521 #else
0522 Options...
0523 #endif
0524 >::type Base;
0525 BOOST_MOVABLE_BUT_NOT_COPYABLE(avltree)
0526
0527 public:
0528 typedef typename Base::key_compare key_compare;
0529 typedef typename Base::value_traits value_traits;
0530 typedef typename Base::iterator iterator;
0531 typedef typename Base::const_iterator const_iterator;
0532 typedef typename Base::reverse_iterator reverse_iterator;
0533 typedef typename Base::const_reverse_iterator const_reverse_iterator;
0534
0535
0536 BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
0537
0538 BOOST_INTRUSIVE_FORCEINLINE avltree()
0539 : Base()
0540 {}
0541
0542 BOOST_INTRUSIVE_FORCEINLINE explicit avltree( const key_compare &cmp, const value_traits &v_traits = value_traits())
0543 : Base(cmp, v_traits)
0544 {}
0545
0546 template<class Iterator>
0547 BOOST_INTRUSIVE_FORCEINLINE avltree( bool unique, Iterator b, Iterator e
0548 , const key_compare &cmp = key_compare()
0549 , const value_traits &v_traits = value_traits())
0550 : Base(unique, b, e, cmp, v_traits)
0551 {}
0552
0553 BOOST_INTRUSIVE_FORCEINLINE avltree(BOOST_RV_REF(avltree) x)
0554 : Base(BOOST_MOVE_BASE(Base, x))
0555 {}
0556
0557 BOOST_INTRUSIVE_FORCEINLINE avltree& operator=(BOOST_RV_REF(avltree) x)
0558 { return static_cast<avltree &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
0559
0560 template <class Cloner, class Disposer>
0561 BOOST_INTRUSIVE_FORCEINLINE void clone_from(const avltree &src, Cloner cloner, Disposer disposer)
0562 { Base::clone_from(src, cloner, disposer); }
0563
0564 template <class Cloner, class Disposer>
0565 BOOST_INTRUSIVE_FORCEINLINE void clone_from(BOOST_RV_REF(avltree) src, Cloner cloner, Disposer disposer)
0566 { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
0567
0568 BOOST_INTRUSIVE_FORCEINLINE static avltree &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT
0569 { return static_cast<avltree &>(Base::container_from_end_iterator(end_iterator)); }
0570
0571 BOOST_INTRUSIVE_FORCEINLINE static const avltree &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT
0572 { return static_cast<const avltree &>(Base::container_from_end_iterator(end_iterator)); }
0573
0574 BOOST_INTRUSIVE_FORCEINLINE static avltree &container_from_iterator(iterator it) BOOST_NOEXCEPT
0575 { return static_cast<avltree &>(Base::container_from_iterator(it)); }
0576
0577 BOOST_INTRUSIVE_FORCEINLINE static const avltree &container_from_iterator(const_iterator it) BOOST_NOEXCEPT
0578 { return static_cast<const avltree &>(Base::container_from_iterator(it)); }
0579 };
0580
0581 #endif
0582
0583 }
0584 }
0585
0586 #include <boost/intrusive/detail/config_end.hpp>
0587
0588 #endif