File indexing completed on 2025-07-15 08:37:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_INTRUSIVE_TREAP_HPP
0013 #define BOOST_INTRUSIVE_TREAP_HPP
0014
0015 #include <boost/intrusive/detail/config_begin.hpp>
0016 #include <boost/intrusive/intrusive_fwd.hpp>
0017
0018 #include <boost/intrusive/detail/assert.hpp>
0019 #include <boost/intrusive/bs_set_hook.hpp>
0020 #include <boost/intrusive/bstree.hpp>
0021 #include <boost/intrusive/detail/tree_node.hpp>
0022 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
0023 #include <boost/intrusive/pointer_traits.hpp>
0024 #include <boost/intrusive/detail/get_value_traits.hpp>
0025 #include <boost/intrusive/detail/mpl.hpp>
0026 #include <boost/intrusive/treap_algorithms.hpp>
0027 #include <boost/intrusive/link_mode.hpp>
0028 #include <boost/intrusive/priority_compare.hpp>
0029 #include <boost/intrusive/detail/node_cloner_disposer.hpp>
0030 #include <boost/intrusive/detail/key_nodeptr_comp.hpp>
0031
0032 #include <boost/move/utility_core.hpp>
0033 #include <boost/move/adl_move_swap.hpp>
0034
0035 #include <cstddef>
0036 #include <boost/intrusive/detail/minimal_less_equal_header.hpp>
0037 #include <boost/intrusive/detail/minimal_pair_header.hpp> //std::pair
0038
0039 #if defined(BOOST_HAS_PRAGMA_ONCE)
0040 # pragma once
0041 #endif
0042
0043 namespace boost {
0044 namespace intrusive {
0045
0046
0047
0048 struct treap_defaults
0049 : bstree_defaults
0050 {
0051 typedef void priority;
0052 typedef void priority_of_value;
0053 };
0054
0055 template<class ValuePtr, class VoidOrPrioOfValue, class VoidOrPrioComp>
0056 struct treap_prio_types
0057 {
0058 typedef typename
0059 boost::movelib::pointer_element<ValuePtr>::type value_type;
0060 typedef typename get_key_of_value
0061 < VoidOrPrioOfValue, value_type>::type priority_of_value;
0062 typedef typename priority_of_value::type priority_type;
0063 typedef typename get_prio_comp< VoidOrPrioComp
0064 , priority_type
0065 >::type priority_compare;
0066 };
0067
0068 struct treap_tag;
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
0086 template<class T, class ...Options>
0087 #else
0088 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, class VoidOrPrioOfValue, class VoidOrPrioComp, class SizeType, bool ConstantTimeSize, typename HeaderHolder>
0089 #endif
0090 class treap_impl
0091
0092 : public bstree_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, SizeType, ConstantTimeSize, BsTreeAlgorithms, HeaderHolder>
0093
0094 , public detail::ebo_functor_holder
0095 < typename treap_prio_types<typename ValueTraits::pointer, VoidOrPrioOfValue, VoidOrPrioComp>::priority_compare
0096 , treap_tag>
0097
0098 {
0099 public:
0100 typedef ValueTraits value_traits;
0101
0102 typedef bstree_impl< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, SizeType
0103 , ConstantTimeSize, BsTreeAlgorithms
0104 , HeaderHolder> tree_type;
0105 typedef tree_type implementation_defined;
0106 typedef treap_prio_types
0107 < typename ValueTraits::pointer
0108 , VoidOrPrioOfValue, VoidOrPrioComp> treap_prio_types_t;
0109
0110 typedef detail::ebo_functor_holder
0111 <typename treap_prio_types_t::priority_compare, treap_tag> prio_base;
0112
0113
0114
0115 typedef typename implementation_defined::pointer pointer;
0116 typedef typename implementation_defined::const_pointer const_pointer;
0117 typedef typename implementation_defined::value_type value_type;
0118 typedef typename implementation_defined::key_type key_type;
0119 typedef typename implementation_defined::key_of_value key_of_value;
0120 typedef typename implementation_defined::reference reference;
0121 typedef typename implementation_defined::const_reference const_reference;
0122 typedef typename implementation_defined::difference_type difference_type;
0123 typedef typename implementation_defined::size_type size_type;
0124 typedef typename implementation_defined::value_compare value_compare;
0125 typedef typename implementation_defined::key_compare key_compare;
0126 typedef typename implementation_defined::iterator iterator;
0127 typedef typename implementation_defined::const_iterator const_iterator;
0128 typedef typename implementation_defined::reverse_iterator reverse_iterator;
0129 typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
0130 typedef typename implementation_defined::node_traits node_traits;
0131 typedef typename implementation_defined::node node;
0132 typedef typename implementation_defined::node_ptr node_ptr;
0133 typedef typename implementation_defined::const_node_ptr const_node_ptr;
0134 typedef BOOST_INTRUSIVE_IMPDEF(treap_algorithms<node_traits>) node_algorithms;
0135 typedef BOOST_INTRUSIVE_IMPDEF
0136 (typename treap_prio_types_t::priority_type) priority_type;
0137 typedef BOOST_INTRUSIVE_IMPDEF
0138 (typename treap_prio_types_t::priority_of_value) priority_of_value;
0139 typedef BOOST_INTRUSIVE_IMPDEF
0140 (typename treap_prio_types_t::priority_compare) priority_compare;
0141
0142 static const bool constant_time_size = implementation_defined::constant_time_size;
0143 static const bool stateful_value_traits = implementation_defined::stateful_value_traits;
0144 static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
0145
0146 typedef detail::key_nodeptr_comp<priority_compare, value_traits, priority_of_value> prio_node_prio_comp_t;
0147
0148 template<class PrioPrioComp>
0149 detail::key_nodeptr_comp<PrioPrioComp, value_traits, priority_of_value> prio_node_prio_comp(PrioPrioComp priopriocomp) const
0150 { return detail::key_nodeptr_comp<PrioPrioComp, value_traits, priority_of_value>(priopriocomp, &this->get_value_traits()); }
0151
0152
0153 private:
0154
0155
0156 BOOST_MOVABLE_BUT_NOT_COPYABLE(treap_impl)
0157
0158 const priority_compare &priv_pcomp() const
0159 { return static_cast<const prio_base&>(*this).get(); }
0160
0161 priority_compare &priv_pcomp()
0162 { return static_cast<prio_base&>(*this).get(); }
0163
0164
0165
0166 public:
0167 typedef typename node_algorithms::insert_commit_data insert_commit_data;
0168
0169
0170
0171
0172
0173
0174
0175
0176 treap_impl()
0177 : tree_type(), prio_base()
0178 {}
0179
0180
0181
0182
0183
0184
0185
0186
0187 explicit treap_impl( const key_compare &cmp
0188 , const priority_compare &pcmp = priority_compare()
0189 , const value_traits &v_traits = value_traits())
0190 : tree_type(cmp, v_traits), prio_base(pcmp)
0191 {}
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206 template<class Iterator>
0207 treap_impl( bool unique, Iterator b, Iterator e
0208 , const key_compare &cmp = key_compare()
0209 , const priority_compare &pcmp = priority_compare()
0210 , const value_traits &v_traits = value_traits())
0211 : tree_type(cmp, v_traits), prio_base(pcmp)
0212 {
0213 if(unique)
0214 this->insert_unique(b, e);
0215 else
0216 this->insert_equal(b, e);
0217 }
0218
0219
0220 treap_impl(BOOST_RV_REF(treap_impl) x)
0221 : tree_type(BOOST_MOVE_BASE(tree_type, x))
0222 , prio_base(::boost::move(x.priv_pcomp()))
0223 {}
0224
0225
0226 treap_impl& operator=(BOOST_RV_REF(treap_impl) x)
0227 { this->swap(x); return *this; }
0228
0229 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
0230
0231 ~treap_impl();
0232
0233
0234 iterator begin() BOOST_NOEXCEPT;
0235
0236
0237 const_iterator begin() const BOOST_NOEXCEPT;
0238
0239
0240 const_iterator cbegin() const BOOST_NOEXCEPT;
0241
0242
0243 iterator end() BOOST_NOEXCEPT;
0244
0245
0246 const_iterator end() const BOOST_NOEXCEPT;
0247
0248
0249 const_iterator cend() const BOOST_NOEXCEPT;
0250 #endif
0251
0252
0253
0254
0255
0256
0257 inline iterator top() BOOST_NOEXCEPT
0258 { return this->tree_type::root(); }
0259
0260
0261
0262
0263
0264
0265 inline const_iterator top() const BOOST_NOEXCEPT
0266 { return this->ctop(); }
0267
0268
0269
0270
0271
0272
0273 inline const_iterator ctop() const BOOST_NOEXCEPT
0274 { return this->tree_type::root(); }
0275
0276 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
0277
0278 reverse_iterator rbegin() BOOST_NOEXCEPT;
0279
0280
0281 const_reverse_iterator rbegin() const BOOST_NOEXCEPT;
0282
0283
0284 const_reverse_iterator crbegin() const BOOST_NOEXCEPT;
0285
0286
0287 reverse_iterator rend() BOOST_NOEXCEPT;
0288
0289
0290 const_reverse_iterator rend() const BOOST_NOEXCEPT;
0291
0292
0293 const_reverse_iterator crend() const BOOST_NOEXCEPT;
0294
0295
0296 iterator root() BOOST_NOEXCEPT;
0297
0298
0299 const_iterator root() const BOOST_NOEXCEPT;
0300
0301
0302 const_iterator croot() const BOOST_NOEXCEPT;
0303
0304 #endif
0305
0306
0307
0308
0309
0310
0311
0312 inline reverse_iterator rtop() BOOST_NOEXCEPT
0313 { return reverse_iterator(this->top()); }
0314
0315
0316
0317
0318
0319
0320
0321 inline const_reverse_iterator rtop() const BOOST_NOEXCEPT
0322 { return const_reverse_iterator(this->top()); }
0323
0324
0325
0326
0327
0328
0329
0330 inline const_reverse_iterator crtop() const BOOST_NOEXCEPT
0331 { return const_reverse_iterator(this->top()); }
0332
0333 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
0334
0335 static treap_impl &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT;
0336
0337
0338 static const treap_impl &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT;
0339
0340
0341 static treap_impl &container_from_iterator(iterator it) BOOST_NOEXCEPT;
0342
0343
0344 static const treap_impl &container_from_iterator(const_iterator it) BOOST_NOEXCEPT;
0345
0346
0347 key_compare key_comp() const;
0348
0349
0350 value_compare value_comp() const;
0351
0352
0353 bool empty() const BOOST_NOEXCEPT;
0354
0355
0356 size_type size() const BOOST_NOEXCEPT;
0357 #endif
0358
0359
0360
0361
0362
0363
0364 priority_compare priority_comp() const
0365 { return this->priv_pcomp(); }
0366
0367
0368
0369
0370
0371
0372 void swap(treap_impl& other)
0373 {
0374
0375 ::boost::adl_move_swap(this->priv_pcomp(), other.priv_pcomp());
0376 tree_type::swap(other);
0377 }
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393 template <class Cloner, class Disposer>
0394 void clone_from(const treap_impl &src, Cloner cloner, Disposer disposer)
0395 {
0396 tree_type::clone_from(src, cloner, disposer);
0397 this->priv_pcomp() = src.priv_pcomp();
0398 }
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414 template <class Cloner, class Disposer>
0415 void clone_from(BOOST_RV_REF(treap_impl) src, Cloner cloner, Disposer disposer)
0416 {
0417 tree_type::clone_from(BOOST_MOVE_BASE(tree_type, src), cloner, disposer);
0418 this->priv_pcomp() = ::boost::move(src.priv_pcomp());
0419 }
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432 iterator insert_equal(reference value)
0433 {
0434 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
0435 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
0436 iterator ret
0437 ( node_algorithms::insert_equal_upper_bound
0438 ( this->tree_type::header_ptr()
0439 , to_insert
0440 , this->key_node_comp(this->key_comp())
0441 , this->prio_node_prio_comp(this->priv_pcomp()))
0442 , this->priv_value_traits_ptr());
0443 this->tree_type::sz_traits().increment();
0444 return ret;
0445 }
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461 iterator insert_equal(const_iterator hint, reference value)
0462 {
0463 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
0464 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
0465 iterator ret
0466 (node_algorithms::insert_equal
0467 ( this->tree_type::header_ptr()
0468 , hint.pointed_node()
0469 , to_insert
0470 , this->key_node_comp(this->key_comp())
0471 , this->prio_node_prio_comp(this->priv_pcomp()))
0472 , this->priv_value_traits_ptr());
0473 this->tree_type::sz_traits().increment();
0474 return ret;
0475 }
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492 template<class Iterator>
0493 void insert_equal(Iterator b, Iterator e)
0494 {
0495 iterator iend(this->end());
0496 for (; b != e; ++b)
0497 this->insert_equal(iend, *b);
0498 }
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513 std::pair<iterator, bool> insert_unique(reference value)
0514 {
0515 insert_commit_data commit_data;
0516 std::pair<iterator, bool> ret = this->insert_unique_check(key_of_value()(value), priority_of_value()(value), commit_data);
0517 if(!ret.second)
0518 return ret;
0519 return std::pair<iterator, bool> (this->insert_unique_commit(value, commit_data), true);
0520 }
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537 iterator insert_unique(const_iterator hint, reference value)
0538 {
0539 insert_commit_data commit_data;
0540 std::pair<iterator, bool> ret = this->insert_unique_check(hint, key_of_value()(value), priority_of_value()(value), commit_data);
0541 if(!ret.second)
0542 return ret.first;
0543 return this->insert_unique_commit(value, commit_data);
0544 }
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560 template<class Iterator>
0561 void insert_unique(Iterator b, Iterator e)
0562 {
0563 if(this->empty()){
0564 iterator iend(this->end());
0565 for (; b != e; ++b)
0566 this->insert_unique(iend, *b);
0567 }
0568 else{
0569 for (; b != e; ++b)
0570 this->insert_unique(*b);
0571 }
0572 }
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600 std::pair<iterator, bool> insert_unique_check
0601 ( const key_type &key, const priority_type &prio, insert_commit_data &commit_data)
0602 { return this->insert_unique_check(key, this->key_comp(), prio, this->priv_pcomp(), commit_data); }
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632 std::pair<iterator, bool> insert_unique_check
0633 ( const_iterator hint, const key_type &key, const priority_type &prio, insert_commit_data &commit_data)
0634 { return this->insert_unique_check(hint, key, this->key_comp(), prio, this->priv_pcomp(), commit_data); }
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644
0645
0646
0647
0648
0649
0650
0651
0652
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662
0663
0664
0665
0666
0667
0668
0669 template<class KeyType, class KeyTypeKeyCompare, class PrioType, class PrioValuePrioCompare>
0670 BOOST_INTRUSIVE_DOC1ST(std::pair<iterator BOOST_INTRUSIVE_I bool>
0671 , typename detail::disable_if_convertible
0672 <KeyType BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I
0673 std::pair<iterator BOOST_INTRUSIVE_I bool> >::type)
0674 insert_unique_check
0675 ( const KeyType &key, KeyTypeKeyCompare comp
0676 , const PrioType &prio, PrioValuePrioCompare prio_value_pcomp, insert_commit_data &commit_data)
0677 {
0678 std::pair<node_ptr, bool> const ret =
0679 (node_algorithms::insert_unique_check
0680 ( this->tree_type::header_ptr()
0681 , key, this->key_node_comp(comp)
0682 , prio, this->prio_node_prio_comp(prio_value_pcomp)
0683 , commit_data));
0684 return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second);
0685 }
0686
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696
0697
0698
0699
0700
0701
0702
0703
0704
0705
0706
0707
0708
0709
0710
0711
0712
0713
0714
0715
0716
0717
0718
0719
0720
0721
0722 template<class KeyType, class KeyTypeKeyCompare, class PrioType, class PrioValuePrioCompare>
0723 std::pair<iterator, bool> insert_unique_check
0724 ( const_iterator hint
0725 , const KeyType &key
0726 , KeyTypeKeyCompare comp
0727 , const PrioType &prio
0728 , PrioValuePrioCompare prio_value_pcomp
0729 , insert_commit_data &commit_data)
0730 {
0731 std::pair<node_ptr, bool> const ret =
0732 (node_algorithms::insert_unique_check
0733 ( this->tree_type::header_ptr(), hint.pointed_node()
0734 , key, this->key_node_comp(comp)
0735 , prio, this->prio_node_prio_comp(prio_value_pcomp)
0736 , commit_data));
0737 return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second);
0738 }
0739
0740
0741
0742
0743
0744
0745
0746
0747
0748
0749
0750
0751
0752
0753
0754
0755
0756
0757 iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) BOOST_NOEXCEPT
0758 {
0759 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
0760 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
0761 node_algorithms::insert_unique_commit(this->tree_type::header_ptr(), to_insert, commit_data);
0762 this->tree_type::sz_traits().increment();
0763 return iterator(to_insert, this->priv_value_traits_ptr());
0764 }
0765
0766
0767
0768
0769
0770
0771
0772
0773
0774
0775
0776
0777
0778
0779
0780 iterator insert_before(const_iterator pos, reference value) BOOST_NOEXCEPT
0781 {
0782 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
0783 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
0784 iterator ret
0785 ( node_algorithms::insert_before
0786 ( this->tree_type::header_ptr()
0787 , pos.pointed_node()
0788 , to_insert
0789 , this->prio_node_prio_comp(this->priv_pcomp())
0790 )
0791 , this->priv_value_traits_ptr());
0792 this->tree_type::sz_traits().increment();
0793 return ret;
0794 }
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810 void push_back(reference value) BOOST_NOEXCEPT
0811 {
0812 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
0813 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
0814 node_algorithms::push_back
0815 (this->tree_type::header_ptr(), to_insert, this->prio_node_prio_comp(this->priv_pcomp()));
0816 this->tree_type::sz_traits().increment();
0817 }
0818
0819
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830
0831
0832
0833 void push_front(reference value) BOOST_NOEXCEPT
0834 {
0835 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
0836 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(to_insert));
0837 node_algorithms::push_front
0838 (this->tree_type::header_ptr(), to_insert, this->prio_node_prio_comp(this->priv_pcomp()));
0839 this->tree_type::sz_traits().increment();
0840 }
0841
0842
0843
0844
0845
0846
0847
0848
0849
0850 iterator erase(const_iterator i) BOOST_NOEXCEPT
0851 {
0852 const_iterator ret(i);
0853 ++ret;
0854 node_ptr to_erase(i.pointed_node());
0855 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || !node_algorithms::unique(to_erase));
0856 node_algorithms::erase
0857 (this->tree_type::header_ptr(), to_erase, this->prio_node_prio_comp(this->priv_pcomp()));
0858 this->tree_type::sz_traits().decrement();
0859 BOOST_IF_CONSTEXPR(safemode_or_autounlink)
0860 node_algorithms::init(to_erase);
0861 return ret.unconst();
0862 }
0863
0864
0865
0866
0867
0868
0869
0870
0871
0872
0873 iterator erase(const_iterator b, const_iterator e) BOOST_NOEXCEPT
0874 { size_type n; return private_erase(b, e, n); }
0875
0876
0877
0878
0879
0880
0881
0882
0883
0884
0885
0886 size_type erase(const key_type &key)
0887 { return this->erase(key, this->key_comp()); }
0888
0889
0890
0891
0892
0893
0894
0895
0896
0897
0898
0899
0900
0901 template<class KeyType, class KeyTypeKeyCompare>
0902 BOOST_INTRUSIVE_DOC1ST(size_type
0903 , typename detail::disable_if_convertible<KeyTypeKeyCompare BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I size_type>::type)
0904 erase(const KeyType& key, KeyTypeKeyCompare comp)
0905 {
0906 std::pair<iterator,iterator> p = this->equal_range(key, comp);
0907 size_type n;
0908 private_erase(p.first, p.second, n);
0909 return n;
0910 }
0911
0912
0913
0914
0915
0916
0917
0918
0919
0920
0921
0922
0923 template<class Disposer>
0924 iterator erase_and_dispose(const_iterator i, Disposer disposer) BOOST_NOEXCEPT
0925 {
0926 node_ptr to_erase(i.pointed_node());
0927 iterator ret(this->erase(i));
0928 disposer(this->get_value_traits().to_value_ptr(to_erase));
0929 return ret;
0930 }
0931
0932 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
0933 template<class Disposer>
0934 iterator erase_and_dispose(iterator i, Disposer disposer) BOOST_NOEXCEPT
0935 { return this->erase_and_dispose(const_iterator(i), disposer); }
0936 #endif
0937
0938
0939
0940
0941
0942
0943
0944
0945
0946
0947
0948
0949
0950 template<class Disposer>
0951 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) BOOST_NOEXCEPT
0952 { size_type n; return private_erase(b, e, n, disposer); }
0953
0954
0955
0956
0957
0958
0959
0960
0961
0962
0963
0964
0965
0966
0967
0968 template<class Disposer>
0969 size_type erase_and_dispose(const key_type &key, Disposer disposer)
0970 {
0971 std::pair<iterator,iterator> p = this->equal_range(key);
0972 size_type n;
0973 private_erase(p.first, p.second, n, disposer);
0974 return n;
0975 }
0976
0977
0978
0979
0980
0981
0982
0983
0984
0985
0986
0987
0988
0989
0990
0991
0992 template<class KeyType, class KeyTypeKeyCompare, class Disposer>
0993 BOOST_INTRUSIVE_DOC1ST(size_type
0994 , typename detail::disable_if_convertible<KeyTypeKeyCompare BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I size_type>::type)
0995 erase_and_dispose(const KeyType& key, KeyTypeKeyCompare comp, Disposer disposer)
0996 {
0997 std::pair<iterator,iterator> p = this->equal_range(key, comp);
0998 size_type n;
0999 private_erase(p.first, p.second, n, disposer);
1000 return n;
1001 }
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012 void clear() BOOST_NOEXCEPT
1013 { tree_type::clear(); }
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024 template<class Disposer>
1025 void clear_and_dispose(Disposer disposer) BOOST_NOEXCEPT
1026 {
1027 node_algorithms::clear_and_dispose(this->tree_type::header_ptr()
1028 , detail::node_disposer<Disposer, value_traits, TreapAlgorithms>(disposer, &this->get_value_traits()));
1029 node_algorithms::init_header(this->tree_type::header_ptr());
1030 this->tree_type::sz_traits().set_size(0);
1031 }
1032
1033 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1034
1035 template<class T, class ...Options2> void merge_unique(sgtree<T, Options2...> &);
1036 #else
1037 template<class Compare2>
1038 void merge_unique(treap_impl
1039 <ValueTraits, VoidOrKeyOfValue, Compare2, VoidOrPrioOfValue, VoidOrPrioComp, SizeType, ConstantTimeSize, HeaderHolder> &source)
1040 #endif
1041 {
1042 node_ptr it (node_algorithms::begin_node(source.header_ptr()))
1043 , itend(node_algorithms::end_node (source.header_ptr()));
1044
1045 while(it != itend){
1046 node_ptr const p(it);
1047 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || !node_algorithms::unique(p));
1048 it = node_algorithms::next_node(it);
1049
1050 if( node_algorithms::transfer_unique
1051 ( this->header_ptr(), this->key_node_comp(this->key_comp())
1052 , this->prio_node_prio_comp(this->priv_pcomp()), source.header_ptr(), p) ){
1053 this->sz_traits().increment();
1054 source.sz_traits().decrement();
1055 }
1056 }
1057 }
1058
1059 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1060
1061 template<class T, class ...Options2> void merge_equal(sgtree<T, Options2...> &);
1062 #else
1063 template<class Compare2>
1064 void merge_equal(treap_impl
1065 <ValueTraits, VoidOrKeyOfValue, Compare2, VoidOrPrioOfValue, VoidOrPrioComp, SizeType, ConstantTimeSize, HeaderHolder> &source)
1066 #endif
1067 {
1068 node_ptr it (node_algorithms::begin_node(source.header_ptr()))
1069 , itend(node_algorithms::end_node (source.header_ptr()));
1070
1071 while(it != itend){
1072 node_ptr const p(it);
1073 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || !node_algorithms::unique(p));
1074 it = node_algorithms::next_node(it);
1075 node_algorithms::transfer_equal
1076 ( this->header_ptr(), this->key_node_comp(this->key_comp())
1077 , this->prio_node_prio_comp(this->priv_pcomp()), source.header_ptr(), p);
1078 this->sz_traits().increment();
1079 source.sz_traits().decrement();
1080 }
1081 }
1082
1083
1084 template <class ExtraChecker>
1085 void check(ExtraChecker extra_checker) const
1086 {
1087 typedef detail::key_nodeptr_comp<priority_compare, value_traits, priority_of_value> nodeptr_prio_comp_t;
1088 tree_type::check(detail::treap_node_extra_checker
1089 <ValueTraits, nodeptr_prio_comp_t, ExtraChecker>
1090 (this->prio_node_prio_comp(this->priv_pcomp()), extra_checker));
1091 }
1092
1093
1094 void check() const
1095 { check(detail::empty_node_checker<ValueTraits>()); }
1096
1097 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1098
1099 size_type count(const key_type &key) const;
1100
1101
1102 template<class KeyType, class KeyTypeKeyCompare>
1103 size_type count(const KeyType& key, KeyTypeKeyCompare comp) const;
1104
1105
1106 iterator lower_bound(const key_type &key);
1107
1108
1109 template<class KeyType, class KeyTypeKeyCompare>
1110 iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp);
1111
1112
1113 const_iterator lower_bound(const key_type &key) const;
1114
1115
1116 template<class KeyType, class KeyTypeKeyCompare>
1117 const_iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
1118
1119
1120 iterator upper_bound(const key_type &key);
1121
1122
1123 template<class KeyType, class KeyTypeKeyCompare>
1124 iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp);
1125
1126
1127 const_iterator upper_bound(const key_type &key) const;
1128
1129
1130 template<class KeyType, class KeyTypeKeyCompare>
1131 const_iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
1132
1133
1134 iterator find(const key_type &key);
1135
1136
1137 template<class KeyType, class KeyTypeKeyCompare>
1138 iterator find(const KeyType& key, KeyTypeKeyCompare comp);
1139
1140
1141 const_iterator find(const key_type &key) const;
1142
1143
1144 template<class KeyType, class KeyTypeKeyCompare>
1145 const_iterator find(const KeyType& key, KeyTypeKeyCompare comp) const;
1146
1147
1148 std::pair<iterator,iterator> equal_range(const key_type &key);
1149
1150
1151 template<class KeyType, class KeyTypeKeyCompare>
1152 std::pair<iterator,iterator> equal_range(const KeyType& key, KeyTypeKeyCompare comp);
1153
1154
1155 std::pair<const_iterator, const_iterator>
1156 equal_range(const key_type &key) const;
1157
1158
1159 template<class KeyType, class KeyTypeKeyCompare>
1160 std::pair<const_iterator, const_iterator>
1161 equal_range(const KeyType& key, KeyTypeKeyCompare comp) const;
1162
1163
1164 std::pair<iterator,iterator> bounded_range
1165 (const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed);
1166
1167
1168 template<class KeyType, class KeyTypeKeyCompare>
1169 std::pair<iterator,iterator> bounded_range
1170 (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed);
1171
1172
1173 std::pair<const_iterator, const_iterator>
1174 bounded_range(const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const;
1175
1176
1177 template<class KeyType, class KeyTypeKeyCompare>
1178 std::pair<const_iterator, const_iterator> bounded_range
1179 (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const;
1180
1181
1182 static iterator s_iterator_to(reference value) BOOST_NOEXCEPT;
1183
1184
1185 static const_iterator s_iterator_to(const_reference value) BOOST_NOEXCEPT;
1186
1187
1188 iterator iterator_to(reference value) BOOST_NOEXCEPT;
1189
1190
1191 const_iterator iterator_to(const_reference value) const BOOST_NOEXCEPT;
1192
1193
1194 static void init_node(reference value) BOOST_NOEXCEPT;
1195
1196
1197 pointer unlink_leftmost_without_rebalance() BOOST_NOEXCEPT;
1198
1199
1200 void replace_node(iterator replace_this, reference with_this) BOOST_NOEXCEPT;
1201
1202
1203 void remove_node(reference value) BOOST_NOEXCEPT;
1204
1205 friend bool operator< (const treap_impl &x, const treap_impl &y);
1206
1207 friend bool operator==(const treap_impl &x, const treap_impl &y);
1208
1209 friend bool operator!= (const treap_impl &x, const treap_impl &y);
1210
1211 friend bool operator>(const treap_impl &x, const treap_impl &y);
1212
1213 friend bool operator<=(const treap_impl &x, const treap_impl &y);
1214
1215 friend bool operator>=(const treap_impl &x, const treap_impl &y);
1216
1217 friend void swap(treap_impl &x, treap_impl &y);
1218
1219 #endif
1220
1221
1222 private:
1223 template<class Disposer>
1224 iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
1225 {
1226 for(n = 0; b != e; ++n)
1227 this->erase_and_dispose(b++, disposer);
1228 return b.unconst();
1229 }
1230
1231 iterator private_erase(const_iterator b, const_iterator e, size_type &n)
1232 {
1233 for(n = 0; b != e; ++n)
1234 this->erase(b++);
1235 return b.unconst();
1236 }
1237
1238 };
1239
1240
1241
1242
1243 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1244 template<class T, class ...Options>
1245 #else
1246 template<class T, class O1 = void, class O2 = void
1247 , class O3 = void, class O4 = void
1248 , class O5 = void, class O6 = void
1249 , class O7 = void>
1250 #endif
1251 struct make_treap
1252 {
1253 typedef typename pack_options
1254 < treap_defaults,
1255 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1256 O1, O2, O3, O4, O5, O6, O7
1257 #else
1258 Options...
1259 #endif
1260 >::type packed_options;
1261
1262 typedef typename detail::get_value_traits
1263 <T, typename packed_options::proto_value_traits>::type value_traits;
1264
1265 typedef treap_impl
1266 < value_traits
1267 , typename packed_options::key_of_value
1268 , typename packed_options::compare
1269 , typename packed_options::priority_of_value
1270 , typename packed_options::priority
1271 , typename packed_options::size_type
1272 , packed_options::constant_time_size
1273 , typename packed_options::header_holder_type
1274 > implementation_defined;
1275
1276 typedef implementation_defined type;
1277 };
1278
1279 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1280
1281 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1282 template<class T, class O1, class O2, class O3, class O4, class O5, class O6, class O7>
1283 #else
1284 template<class T, class ...Options>
1285 #endif
1286 class treap
1287 : public make_treap<T,
1288 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1289 O1, O2, O3, O4, O5, O6, O7
1290 #else
1291 Options...
1292 #endif
1293 >::type
1294 {
1295 typedef typename make_treap
1296 <T,
1297 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1298 O1, O2, O3, O4, O5, O6, O7
1299 #else
1300 Options...
1301 #endif
1302 >::type Base;
1303 BOOST_MOVABLE_BUT_NOT_COPYABLE(treap)
1304
1305 public:
1306 typedef typename Base::key_compare key_compare;
1307 typedef typename Base::priority_compare priority_compare;
1308 typedef typename Base::value_traits value_traits;
1309 typedef typename Base::iterator iterator;
1310 typedef typename Base::const_iterator const_iterator;
1311 typedef typename Base::reverse_iterator reverse_iterator;
1312 typedef typename Base::const_reverse_iterator const_reverse_iterator;
1313
1314
1315 BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
1316
1317 inline treap()
1318 : Base()
1319 {}
1320
1321 inline explicit treap( const key_compare &cmp
1322 , const priority_compare &pcmp = priority_compare()
1323 , const value_traits &v_traits = value_traits())
1324 : Base(cmp, pcmp, v_traits)
1325 {}
1326
1327 template<class Iterator>
1328 inline treap( bool unique, Iterator b, Iterator e
1329 , const key_compare &cmp = key_compare()
1330 , const priority_compare &pcmp = priority_compare()
1331 , const value_traits &v_traits = value_traits())
1332 : Base(unique, b, e, cmp, pcmp, v_traits)
1333 {}
1334
1335 inline treap(BOOST_RV_REF(treap) x)
1336 : Base(BOOST_MOVE_BASE(Base, x))
1337 {}
1338
1339 inline treap& operator=(BOOST_RV_REF(treap) x)
1340 { return static_cast<treap&>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
1341
1342 template <class Cloner, class Disposer>
1343 inline void clone_from(const treap &src, Cloner cloner, Disposer disposer)
1344 { Base::clone_from(src, cloner, disposer); }
1345
1346 template <class Cloner, class Disposer>
1347 inline void clone_from(BOOST_RV_REF(treap) src, Cloner cloner, Disposer disposer)
1348 { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
1349
1350 inline static treap &container_from_end_iterator(iterator end_iterator) BOOST_NOEXCEPT
1351 { return static_cast<treap &>(Base::container_from_end_iterator(end_iterator)); }
1352
1353 inline static const treap &container_from_end_iterator(const_iterator end_iterator) BOOST_NOEXCEPT
1354 { return static_cast<const treap &>(Base::container_from_end_iterator(end_iterator)); }
1355
1356 inline static treap &container_from_iterator(iterator it) BOOST_NOEXCEPT
1357 { return static_cast<treap &>(Base::container_from_iterator(it)); }
1358
1359 inline static const treap &container_from_iterator(const_iterator it) BOOST_NOEXCEPT
1360 { return static_cast<const treap &>(Base::container_from_iterator(it)); }
1361 };
1362
1363 #endif
1364
1365 }
1366 }
1367
1368 #include <boost/intrusive/detail/config_end.hpp>
1369
1370 #endif