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