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