1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125 |
- #ifndef BOOST_INTRUSIVE_BSTREE_HPP
- #define BOOST_INTRUSIVE_BSTREE_HPP
- #include <boost/intrusive/detail/config_begin.hpp>
- #include <boost/intrusive/intrusive_fwd.hpp>
- #include <boost/intrusive/detail/assert.hpp>
- #include <boost/static_assert.hpp>
- #include <boost/intrusive/intrusive_fwd.hpp>
- #include <boost/intrusive/bs_set_hook.hpp>
- #include <boost/intrusive/detail/tree_node.hpp>
- #include <boost/intrusive/detail/tree_iterator.hpp>
- #include <boost/intrusive/detail/ebo_functor_holder.hpp>
- #include <boost/intrusive/detail/mpl.hpp>
- #include <boost/intrusive/pointer_traits.hpp>
- #include <boost/intrusive/detail/is_stateful_value_traits.hpp>
- #include <boost/intrusive/detail/empty_node_checker.hpp>
- #include <boost/intrusive/detail/default_header_holder.hpp>
- #include <boost/intrusive/detail/reverse_iterator.hpp>
- #include <boost/intrusive/detail/exception_disposer.hpp>
- #include <boost/intrusive/detail/node_cloner_disposer.hpp>
- #include <boost/intrusive/detail/key_nodeptr_comp.hpp>
- #include <boost/intrusive/detail/simple_disposers.hpp>
- #include <boost/intrusive/detail/size_holder.hpp>
- #include <boost/intrusive/detail/algo_type.hpp>
- #include <boost/intrusive/detail/algorithm.hpp>
- #include <boost/intrusive/detail/tree_value_compare.hpp>
- #include <boost/intrusive/detail/get_value_traits.hpp>
- #include <boost/intrusive/bstree_algorithms.hpp>
- #include <boost/intrusive/link_mode.hpp>
- #include <boost/intrusive/parent_from_member.hpp>
- #include <boost/move/utility_core.hpp>
- #include <boost/move/adl_move_swap.hpp>
- #include <boost/intrusive/detail/minimal_pair_header.hpp>
- #include <cstddef> //size_t...
- #include <boost/intrusive/detail/minimal_less_equal_header.hpp>//less, equal_to
- #if defined(BOOST_HAS_PRAGMA_ONCE)
- # pragma once
- #endif
- namespace boost {
- namespace intrusive {
- struct default_bstree_hook_applier
- { template <class T> struct apply{ typedef typename T::default_bstree_hook type; }; };
- template<>
- struct is_default_hook_tag<default_bstree_hook_applier>
- { static const bool value = true; };
- struct bstree_defaults
- {
- typedef default_bstree_hook_applier proto_value_traits;
- static const bool constant_time_size = true;
- typedef std::size_t size_type;
- typedef void compare;
- typedef void key_of_value;
- static const bool floating_point = true;
- typedef void priority;
- typedef void header_holder_type;
- };
- template<class ValueTraits, algo_types AlgoType, typename HeaderHolder>
- struct bstbase3
- {
- typedef ValueTraits value_traits;
- typedef typename value_traits::node_traits node_traits;
- typedef typename node_traits::node node_type;
- typedef typename get_algo<AlgoType, node_traits>::type node_algorithms;
- typedef typename node_traits::node_ptr node_ptr;
- typedef typename node_traits::const_node_ptr const_node_ptr;
- typedef tree_iterator<value_traits, false> iterator;
- typedef tree_iterator<value_traits, true> const_iterator;
- typedef boost::intrusive::reverse_iterator<iterator> reverse_iterator;
- typedef boost::intrusive::reverse_iterator<const_iterator> const_reverse_iterator;
- typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::pointer) pointer;
- typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::const_pointer) const_pointer;
- typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::element_type) value_type;
- typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference;
- typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference;
- typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type;
- typedef typename detail::get_header_holder_type
- < value_traits,HeaderHolder >::type header_holder_type;
- static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
- static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value;
- static const bool has_container_from_iterator =
- detail::is_same< header_holder_type, detail::default_header_holder< node_traits > >::value;
- struct holder_t : public ValueTraits
- {
- explicit holder_t(const ValueTraits &vtraits)
- : ValueTraits(vtraits)
- {}
- header_holder_type root;
- } holder;
- static bstbase3 &get_tree_base_from_end_iterator(const const_iterator &end_iterator)
- {
- BOOST_STATIC_ASSERT(has_container_from_iterator);
- node_ptr p = end_iterator.pointed_node();
- header_holder_type* h = header_holder_type::get_holder(p);
- holder_t *holder = get_parent_from_member<holder_t, header_holder_type>(h, &holder_t::root);
- bstbase3 *base = get_parent_from_member<bstbase3, holder_t> (holder, &bstbase3::holder);
- return *base;
- }
- bstbase3(const ValueTraits &vtraits)
- : holder(vtraits)
- {
- node_algorithms::init_header(this->header_ptr());
- }
- node_ptr header_ptr()
- { return holder.root.get_node(); }
- const_node_ptr header_ptr() const
- { return holder.root.get_node(); }
- const value_traits &get_value_traits() const
- { return this->holder; }
- value_traits &get_value_traits()
- { return this->holder; }
- typedef typename boost::intrusive::value_traits_pointers
- <ValueTraits>::const_value_traits_ptr const_value_traits_ptr;
- const_value_traits_ptr priv_value_traits_ptr() const
- { return pointer_traits<const_value_traits_ptr>::pointer_to(this->get_value_traits()); }
- iterator begin()
- { return iterator(node_algorithms::begin_node(this->header_ptr()), this->priv_value_traits_ptr()); }
- const_iterator begin() const
- { return cbegin(); }
- const_iterator cbegin() const
- { return const_iterator(node_algorithms::begin_node(this->header_ptr()), this->priv_value_traits_ptr()); }
- iterator end()
- { return iterator(node_algorithms::end_node(this->header_ptr()), this->priv_value_traits_ptr()); }
- const_iterator end() const
- { return cend(); }
- const_iterator cend() const
- { return const_iterator(node_algorithms::end_node(this->header_ptr()), this->priv_value_traits_ptr()); }
- iterator root()
- { return iterator(node_algorithms::root_node(this->header_ptr()), this->priv_value_traits_ptr()); }
- const_iterator root() const
- { return croot(); }
- const_iterator croot() const
- { return const_iterator(node_algorithms::root_node(this->header_ptr()), this->priv_value_traits_ptr()); }
- reverse_iterator rbegin()
- { return reverse_iterator(end()); }
- const_reverse_iterator rbegin() const
- { return const_reverse_iterator(end()); }
- const_reverse_iterator crbegin() const
- { return const_reverse_iterator(end()); }
- reverse_iterator rend()
- { return reverse_iterator(begin()); }
- const_reverse_iterator rend() const
- { return const_reverse_iterator(begin()); }
- const_reverse_iterator crend() const
- { return const_reverse_iterator(begin()); }
- void replace_node(iterator replace_this, reference with_this)
- {
- node_algorithms::replace_node( get_value_traits().to_node_ptr(*replace_this)
- , this->header_ptr()
- , get_value_traits().to_node_ptr(with_this));
- if(safemode_or_autounlink)
- node_algorithms::init(replace_this.pointed_node());
- }
- void rebalance()
- { node_algorithms::rebalance(this->header_ptr()); }
- iterator rebalance_subtree(iterator root)
- { return iterator(node_algorithms::rebalance_subtree(root.pointed_node()), this->priv_value_traits_ptr()); }
- static iterator s_iterator_to(reference value)
- {
- BOOST_STATIC_ASSERT((!stateful_value_traits));
- return iterator (value_traits::to_node_ptr(value), const_value_traits_ptr());
- }
- static const_iterator s_iterator_to(const_reference value)
- {
- BOOST_STATIC_ASSERT((!stateful_value_traits));
- return const_iterator (value_traits::to_node_ptr(*pointer_traits<pointer>::const_cast_from(pointer_traits<const_pointer>::pointer_to(value))), const_value_traits_ptr());
- }
- iterator iterator_to(reference value)
- { return iterator (this->get_value_traits().to_node_ptr(value), this->priv_value_traits_ptr()); }
- const_iterator iterator_to(const_reference value) const
- { return const_iterator (this->get_value_traits().to_node_ptr(*pointer_traits<pointer>::const_cast_from(pointer_traits<const_pointer>::pointer_to(value))), this->priv_value_traits_ptr()); }
- static void init_node(reference value)
- { node_algorithms::init(value_traits::to_node_ptr(value)); }
- };
- template<class Less, class T>
- struct get_compare
- {
- typedef Less type;
- };
- template<class T>
- struct get_compare<void, T>
- {
- typedef ::std::less<T> type;
- };
- template<class KeyOfValue, class T>
- struct get_key_of_value
- {
- typedef KeyOfValue type;
- };
- template<class T>
- struct get_key_of_value<void, T>
- {
- typedef ::boost::intrusive::detail::identity<T> type;
- };
- template<class T, class VoidOrKeyOfValue, class VoidOrKeyComp>
- struct bst_key_types
- {
- typedef typename get_key_of_value
- < VoidOrKeyOfValue, T>::type key_of_value;
- typedef typename key_of_value::type key_type;
- typedef typename get_compare< VoidOrKeyComp
- , key_type
- >::type key_compare;
- typedef tree_value_compare
- <key_type, T, key_compare, key_of_value> value_compare;
- };
- template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, algo_types AlgoType, typename HeaderHolder>
- struct bstbase2
-
-
- : public detail::ebo_functor_holder
- < typename bst_key_types
- < typename ValueTraits::value_type
- , VoidOrKeyOfValue
- , VoidOrKeyComp
- >::value_compare
- >
- , public bstbase3<ValueTraits, AlgoType, HeaderHolder>
- {
- typedef bstbase3<ValueTraits, AlgoType, HeaderHolder> treeheader_t;
- typedef bst_key_types< typename ValueTraits::value_type
- , VoidOrKeyOfValue
- , VoidOrKeyComp> key_types;
- typedef typename treeheader_t::value_traits value_traits;
- typedef typename treeheader_t::node_algorithms node_algorithms;
- typedef typename ValueTraits::value_type value_type;
- typedef typename key_types::key_type key_type;
- typedef typename key_types::key_of_value key_of_value;
- typedef typename key_types::key_compare key_compare;
- typedef typename key_types::value_compare value_compare;
- typedef typename treeheader_t::iterator iterator;
- typedef typename treeheader_t::const_iterator const_iterator;
- typedef typename treeheader_t::node_ptr node_ptr;
- typedef typename treeheader_t::const_node_ptr const_node_ptr;
- bstbase2(const key_compare &comp, const ValueTraits &vtraits)
- : detail::ebo_functor_holder<value_compare>(value_compare(comp)), treeheader_t(vtraits)
- {}
- const value_compare &comp() const
- { return this->get(); }
- value_compare &comp()
- { return this->get(); }
- typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::pointer) pointer;
- typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::const_pointer) const_pointer;
- typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference;
- typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference;
- typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type;
- typedef typename node_algorithms::insert_commit_data insert_commit_data;
- value_compare value_comp() const
- { return this->comp(); }
- key_compare key_comp() const
- { return this->comp().key_comp(); }
-
- iterator lower_bound(const key_type &key)
- { return this->lower_bound(key, this->key_comp()); }
- const_iterator lower_bound(const key_type &key) const
- { return this->lower_bound(key, this->key_comp()); }
- template<class KeyType, class KeyTypeKeyCompare>
- iterator lower_bound(const KeyType &key, KeyTypeKeyCompare comp)
- {
- return iterator(node_algorithms::lower_bound
- (this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
- }
- template<class KeyType, class KeyTypeKeyCompare>
- const_iterator lower_bound(const KeyType &key, KeyTypeKeyCompare comp) const
- {
- return const_iterator(node_algorithms::lower_bound
- (this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
- }
-
- iterator upper_bound(const key_type &key)
- { return this->upper_bound(key, this->key_comp()); }
- template<class KeyType, class KeyTypeKeyCompare>
- iterator upper_bound(const KeyType &key, KeyTypeKeyCompare comp)
- {
- return iterator(node_algorithms::upper_bound
- (this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
- }
- const_iterator upper_bound(const key_type &key) const
- { return this->upper_bound(key, this->key_comp()); }
- template<class KeyType, class KeyTypeKeyCompare>
- const_iterator upper_bound(const KeyType &key, KeyTypeKeyCompare comp) const
- {
- return const_iterator(node_algorithms::upper_bound
- (this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
- }
- template<class KeyTypeKeyCompare>
- struct key_node_comp_ret
- { typedef detail::key_nodeptr_comp<KeyTypeKeyCompare, value_traits, key_of_value> type; };
- template<class KeyTypeKeyCompare>
- typename key_node_comp_ret<KeyTypeKeyCompare>::type key_node_comp(KeyTypeKeyCompare comp) const
- {
- return detail::key_nodeptr_comp<KeyTypeKeyCompare, value_traits, key_of_value>(comp, &this->get_value_traits());
- }
-
- iterator find(const key_type &key)
- { return this->find(key, this->key_comp()); }
- template<class KeyType, class KeyTypeKeyCompare>
- iterator find(const KeyType &key, KeyTypeKeyCompare comp)
- {
- return iterator
- (node_algorithms::find(this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
- }
- const_iterator find(const key_type &key) const
- { return this->find(key, this->key_comp()); }
- template<class KeyType, class KeyTypeKeyCompare>
- const_iterator find(const KeyType &key, KeyTypeKeyCompare comp) const
- {
- return const_iterator
- (node_algorithms::find(this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
- }
-
- std::pair<iterator,iterator> equal_range(const key_type &key)
- { return this->equal_range(key, this->key_comp()); }
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<iterator,iterator> equal_range(const KeyType &key, KeyTypeKeyCompare comp)
- {
- std::pair<node_ptr, node_ptr> ret
- (node_algorithms::equal_range(this->header_ptr(), key, this->key_node_comp(comp)));
- return std::pair<iterator, iterator>( iterator(ret.first, this->priv_value_traits_ptr())
- , iterator(ret.second, this->priv_value_traits_ptr()));
- }
- std::pair<const_iterator, const_iterator>
- equal_range(const key_type &key) const
- { return this->equal_range(key, this->key_comp()); }
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<const_iterator, const_iterator>
- equal_range(const KeyType &key, KeyTypeKeyCompare comp) const
- {
- std::pair<node_ptr, node_ptr> ret
- (node_algorithms::equal_range(this->header_ptr(), key, this->key_node_comp(comp)));
- return std::pair<const_iterator, const_iterator>( const_iterator(ret.first, this->priv_value_traits_ptr())
- , const_iterator(ret.second, this->priv_value_traits_ptr()));
- }
-
- std::pair<iterator,iterator> lower_bound_range(const key_type &key)
- { return this->lower_bound_range(key, this->key_comp()); }
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<iterator,iterator> lower_bound_range(const KeyType &key, KeyTypeKeyCompare comp)
- {
- std::pair<node_ptr, node_ptr> ret
- (node_algorithms::lower_bound_range(this->header_ptr(), key, this->key_node_comp(comp)));
- return std::pair<iterator, iterator>( iterator(ret.first, this->priv_value_traits_ptr())
- , iterator(ret.second, this->priv_value_traits_ptr()));
- }
- std::pair<const_iterator, const_iterator>
- lower_bound_range(const key_type &key) const
- { return this->lower_bound_range(key, this->key_comp()); }
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<const_iterator, const_iterator>
- lower_bound_range(const KeyType &key, KeyTypeKeyCompare comp) const
- {
- std::pair<node_ptr, node_ptr> ret
- (node_algorithms::lower_bound_range(this->header_ptr(), key, this->key_node_comp(comp)));
- return std::pair<const_iterator, const_iterator>( const_iterator(ret.first, this->priv_value_traits_ptr())
- , const_iterator(ret.second, this->priv_value_traits_ptr()));
- }
-
- std::pair<iterator,iterator> bounded_range
- (const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed)
- { return this->bounded_range(lower_key, upper_key, this->key_comp(), left_closed, right_closed); }
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<iterator,iterator> bounded_range
- (const KeyType &lower_key, const KeyType &upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed)
- {
- std::pair<node_ptr, node_ptr> ret
- (node_algorithms::bounded_range
- (this->header_ptr(), lower_key, upper_key, this->key_node_comp(comp), left_closed, right_closed));
- return std::pair<iterator, iterator>( iterator(ret.first, this->priv_value_traits_ptr())
- , iterator(ret.second, this->priv_value_traits_ptr()));
- }
- std::pair<const_iterator,const_iterator> bounded_range
- (const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const
- { return this->bounded_range(lower_key, upper_key, this->key_comp(), left_closed, right_closed); }
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<const_iterator,const_iterator> bounded_range
- (const KeyType &lower_key, const KeyType &upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const
- {
- std::pair<node_ptr, node_ptr> ret
- (node_algorithms::bounded_range
- (this->header_ptr(), lower_key, upper_key, this->key_node_comp(comp), left_closed, right_closed));
- return std::pair<const_iterator, const_iterator>( const_iterator(ret.first, this->priv_value_traits_ptr())
- , const_iterator(ret.second, this->priv_value_traits_ptr()));
- }
-
- std::pair<iterator, bool> insert_unique_check
- (const key_type &key, insert_commit_data &commit_data)
- { return this->insert_unique_check(key, this->key_comp(), commit_data); }
- std::pair<iterator, bool> insert_unique_check
- (const_iterator hint, const key_type &key, insert_commit_data &commit_data)
- { return this->insert_unique_check(hint, key, this->key_comp(), commit_data); }
- template<class KeyType, class KeyTypeKeyCompare>
- BOOST_INTRUSIVE_DOC1ST(std::pair<iterator BOOST_INTRUSIVE_I bool>
- , typename detail::disable_if_convertible
- <KeyType BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I
- std::pair<iterator BOOST_INTRUSIVE_I bool> >::type)
- insert_unique_check
- (const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data)
- {
- std::pair<node_ptr, bool> ret =
- (node_algorithms::insert_unique_check
- (this->header_ptr(), key, this->key_node_comp(comp), commit_data));
- return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second);
- }
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<iterator, bool> insert_unique_check
- (const_iterator hint, const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data)
- {
- std::pair<node_ptr, bool> ret =
- (node_algorithms::insert_unique_check
- (this->header_ptr(), hint.pointed_node(), key, this->key_node_comp(comp), commit_data));
- return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second);
- }
- };
- template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, bool ConstantTimeSize, class SizeType, algo_types AlgoType, typename HeaderHolder>
- struct bstbase_hack
- : public detail::size_holder<ConstantTimeSize, SizeType>
- , public bstbase2 < ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, AlgoType, HeaderHolder>
- {
- typedef bstbase2< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, AlgoType, HeaderHolder> base_type;
- typedef typename base_type::key_compare key_compare;
- typedef typename base_type::value_compare value_compare;
- typedef SizeType size_type;
- typedef typename base_type::node_traits node_traits;
- typedef typename get_algo
- <AlgoType, node_traits>::type algo_type;
- bstbase_hack(const key_compare & comp, const ValueTraits &vtraits)
- : base_type(comp, vtraits)
- {
- this->sz_traits().set_size(size_type(0));
- }
- typedef detail::size_holder<ConstantTimeSize, SizeType> size_traits;
- size_traits &sz_traits()
- { return static_cast<size_traits &>(*this); }
- const size_traits &sz_traits() const
- { return static_cast<const size_traits &>(*this); }
- };
- template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, class SizeType, algo_types AlgoType, typename HeaderHolder>
- struct bstbase_hack<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, false, SizeType, AlgoType, HeaderHolder>
- : public bstbase2 < ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, AlgoType, HeaderHolder>
- {
- typedef bstbase2< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, AlgoType, HeaderHolder> base_type;
- typedef typename base_type::value_compare value_compare;
- typedef typename base_type::key_compare key_compare;
- bstbase_hack(const key_compare & comp, const ValueTraits &vtraits)
- : base_type(comp, vtraits)
- {}
- typedef detail::size_holder<false, SizeType> size_traits;
- size_traits &sz_traits()
- { return s_size_traits; }
- const size_traits &sz_traits() const
- { return s_size_traits; }
- static size_traits s_size_traits;
- };
- template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, class SizeType, algo_types AlgoType, typename HeaderHolder>
- detail::size_holder<false, SizeType> bstbase_hack<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, false, SizeType, AlgoType, HeaderHolder>::s_size_traits;
- template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, bool ConstantTimeSize, class SizeType, algo_types AlgoType, typename HeaderHolder>
- struct bstbase
- : public bstbase_hack< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder>
- {
- typedef bstbase_hack< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder> base_type;
- typedef ValueTraits value_traits;
- typedef typename base_type::value_compare value_compare;
- typedef typename base_type::key_compare key_compare;
- typedef typename base_type::const_reference const_reference;
- typedef typename base_type::reference reference;
- typedef typename base_type::iterator iterator;
- typedef typename base_type::const_iterator const_iterator;
- typedef typename base_type::node_traits node_traits;
- typedef typename get_algo
- <AlgoType, node_traits>::type node_algorithms;
- typedef SizeType size_type;
- bstbase(const key_compare & comp, const ValueTraits &vtraits)
- : base_type(comp, vtraits)
- {}
-
-
- ~bstbase()
- {
- if(is_safe_autounlink<value_traits::link_mode>::value){
- node_algorithms::clear_and_dispose
- ( this->header_ptr()
- , detail::node_disposer<detail::null_disposer, value_traits, AlgoType>
- (detail::null_disposer(), &this->get_value_traits()));
- node_algorithms::init(this->header_ptr());
- }
- }
- };
- #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
- template<class T, class ...Options>
- #else
- template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType, typename HeaderHolder>
- #endif
- class bstree_impl
- : public bstbase<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder>
- {
- public:
-
- typedef bstbase<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder> data_type;
- typedef tree_iterator<ValueTraits, false> iterator_type;
- typedef tree_iterator<ValueTraits, true> const_iterator_type;
-
- typedef BOOST_INTRUSIVE_IMPDEF(ValueTraits) value_traits;
- typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::pointer) pointer;
- typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::const_pointer) const_pointer;
- typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::element_type) value_type;
- typedef BOOST_INTRUSIVE_IMPDEF(typename data_type::key_type) key_type;
- typedef BOOST_INTRUSIVE_IMPDEF(typename data_type::key_of_value) key_of_value;
- typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference;
- typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference;
- typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type;
- typedef BOOST_INTRUSIVE_IMPDEF(SizeType) size_type;
- typedef BOOST_INTRUSIVE_IMPDEF(typename data_type::value_compare) value_compare;
- typedef BOOST_INTRUSIVE_IMPDEF(typename data_type::key_compare) key_compare;
- typedef BOOST_INTRUSIVE_IMPDEF(iterator_type) iterator;
- typedef BOOST_INTRUSIVE_IMPDEF(const_iterator_type) const_iterator;
- typedef BOOST_INTRUSIVE_IMPDEF(boost::intrusive::reverse_iterator<iterator>) reverse_iterator;
- typedef BOOST_INTRUSIVE_IMPDEF(boost::intrusive::reverse_iterator<const_iterator>) const_reverse_iterator;
- typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::node_traits) node_traits;
- typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::node) node;
- typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::node_ptr) node_ptr;
- typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::const_node_ptr) const_node_ptr;
-
- typedef typename get_algo<AlgoType, node_traits>::type algo_type;
-
- typedef BOOST_INTRUSIVE_IMPDEF(algo_type) node_algorithms;
- static const bool constant_time_size = ConstantTimeSize;
- static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value;
-
- private:
-
- BOOST_MOVABLE_BUT_NOT_COPYABLE(bstree_impl)
- static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
-
- BOOST_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink)));
- protected:
-
- public:
- typedef typename node_algorithms::insert_commit_data insert_commit_data;
-
-
-
-
-
-
-
- bstree_impl()
- : data_type(key_compare(), value_traits())
- {}
-
-
-
-
-
-
-
- explicit bstree_impl( const key_compare &cmp, const value_traits &v_traits = value_traits())
- : data_type(cmp, v_traits)
- {}
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Iterator>
- bstree_impl( bool unique, Iterator b, Iterator e
- , const key_compare &cmp = key_compare()
- , const value_traits &v_traits = value_traits())
- : data_type(cmp, v_traits)
- {
-
- if(unique)
- this->insert_unique(b, e);
- else
- this->insert_equal(b, e);
- }
-
-
- bstree_impl(BOOST_RV_REF(bstree_impl) x)
- : data_type(::boost::move(x.comp()), ::boost::move(x.get_value_traits()))
- {
- this->swap(x);
- }
-
-
- bstree_impl& operator=(BOOST_RV_REF(bstree_impl) x)
- { this->swap(x); return *this; }
- #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
-
-
-
-
-
-
-
- ~bstree_impl()
- {}
-
-
-
-
-
- iterator begin();
-
-
-
-
-
- const_iterator begin() const;
-
-
-
-
-
- const_iterator cbegin() const;
-
-
-
-
-
- iterator end();
-
-
-
-
-
- const_iterator end() const;
-
-
-
-
-
- const_iterator cend() const;
-
-
-
-
-
-
- reverse_iterator rbegin();
-
-
-
-
-
-
- const_reverse_iterator rbegin() const;
-
-
-
-
-
-
- const_reverse_iterator crbegin() const;
-
-
-
-
-
-
- reverse_iterator rend();
-
-
-
-
-
-
- const_reverse_iterator rend() const;
-
-
-
-
-
-
- const_reverse_iterator crend() const;
- #endif
-
-
-
-
-
-
-
-
- static bstree_impl &container_from_end_iterator(iterator end_iterator)
- {
- return static_cast<bstree_impl&>
- (data_type::get_tree_base_from_end_iterator(end_iterator));
- }
-
-
-
-
-
-
-
-
- static const bstree_impl &container_from_end_iterator(const_iterator end_iterator)
- {
- return static_cast<bstree_impl&>
- (data_type::get_tree_base_from_end_iterator(end_iterator));
- }
-
-
-
-
-
-
-
-
- static bstree_impl &container_from_iterator(iterator it)
- { return container_from_end_iterator(it.end_iterator_from_it()); }
-
-
-
-
-
-
-
-
- static const bstree_impl &container_from_iterator(const_iterator it)
- { return container_from_end_iterator(it.end_iterator_from_it()); }
- #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
-
-
-
-
-
- key_compare key_comp() const;
-
-
-
-
-
- value_compare value_comp() const;
- #endif
-
-
-
-
-
- bool empty() const
- {
- if(ConstantTimeSize){
- return !this->data_type::sz_traits().get_size();
- }
- else{
- return algo_type::unique(this->header_ptr());
- }
- }
-
-
-
-
-
-
- size_type size() const
- {
- if(constant_time_size)
- return this->sz_traits().get_size();
- else{
- return (size_type)node_algorithms::size(this->header_ptr());
- }
- }
-
-
-
-
-
- void swap(bstree_impl& other)
- {
-
- ::boost::adl_move_swap(this->comp(), this->comp());
-
- node_algorithms::swap_tree(this->header_ptr(), node_ptr(other.header_ptr()));
- if(constant_time_size){
- size_type backup = this->sz_traits().get_size();
- this->sz_traits().set_size(other.sz_traits().get_size());
- other.sz_traits().set_size(backup);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <class Cloner, class Disposer>
- void clone_from(const bstree_impl &src, Cloner cloner, Disposer disposer)
- {
- this->clear_and_dispose(disposer);
- if(!src.empty()){
- detail::exception_disposer<bstree_impl, Disposer>
- rollback(*this, disposer);
- node_algorithms::clone
- (src.header_ptr()
- ,this->header_ptr()
- ,detail::node_cloner <Cloner, value_traits, AlgoType>(cloner, &this->get_value_traits())
- ,detail::node_disposer<Disposer, value_traits, AlgoType>(disposer, &this->get_value_traits()));
- this->sz_traits().set_size(src.sz_traits().get_size());
- this->comp() = src.comp();
- rollback.release();
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <class Cloner, class Disposer>
- void clone_from(BOOST_RV_REF(bstree_impl) src, Cloner cloner, Disposer disposer)
- {
- this->clear_and_dispose(disposer);
- if(!src.empty()){
- detail::exception_disposer<bstree_impl, Disposer>
- rollback(*this, disposer);
- node_algorithms::clone
- (src.header_ptr()
- ,this->header_ptr()
- ,detail::node_cloner <Cloner, value_traits, AlgoType, false>(cloner, &this->get_value_traits())
- ,detail::node_disposer<Disposer, value_traits, AlgoType>(disposer, &this->get_value_traits()));
- this->sz_traits().set_size(src.sz_traits().get_size());
- this->comp() = src.comp();
- rollback.release();
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- iterator insert_equal(reference value)
- {
- node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
- if(safemode_or_autounlink)
- BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
- iterator ret(node_algorithms::insert_equal_upper_bound
- (this->header_ptr(), to_insert, this->key_node_comp(this->key_comp())), this->priv_value_traits_ptr());
- this->sz_traits().increment();
- return ret;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- iterator insert_equal(const_iterator hint, reference value)
- {
- node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
- if(safemode_or_autounlink)
- BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
- iterator ret(node_algorithms::insert_equal
- (this->header_ptr(), hint.pointed_node(), to_insert, this->key_node_comp(this->key_comp())), this->priv_value_traits_ptr());
- this->sz_traits().increment();
- return ret;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Iterator>
- void insert_equal(Iterator b, Iterator e)
- {
- iterator iend(this->end());
- for (; b != e; ++b)
- this->insert_equal(iend, *b);
- }
-
-
-
-
-
-
-
-
-
-
-
-
- std::pair<iterator, bool> insert_unique(reference value)
- {
- insert_commit_data commit_data;
- std::pair<node_ptr, bool> ret =
- (node_algorithms::insert_unique_check
- (this->header_ptr(), key_of_value()(value), this->key_node_comp(this->key_comp()), commit_data));
- return std::pair<iterator, bool>
- ( ret.second ? this->insert_unique_commit(value, commit_data)
- : iterator(ret.first, this->priv_value_traits_ptr())
- , ret.second);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- iterator insert_unique(const_iterator hint, reference value)
- {
- insert_commit_data commit_data;
- std::pair<node_ptr, bool> ret =
- (node_algorithms::insert_unique_check
- (this->header_ptr(), hint.pointed_node(), key_of_value()(value), this->key_node_comp(this->key_comp()), commit_data));
- return ret.second ? this->insert_unique_commit(value, commit_data)
- : iterator(ret.first, this->priv_value_traits_ptr());
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Iterator>
- void insert_unique(Iterator b, Iterator e)
- {
- if(this->empty()){
- iterator iend(this->end());
- for (; b != e; ++b)
- this->insert_unique(iend, *b);
- }
- else{
- for (; b != e; ++b)
- this->insert_unique(*b);
- }
- }
- #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<iterator, bool> insert_unique_check
- (const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<iterator, bool> insert_unique_check
- (const_iterator hint, const KeyType &key
- ,KeyTypeKeyCompare comp, insert_commit_data &commit_data);
- #endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- iterator insert_unique_commit(reference value, const insert_commit_data &commit_data)
- {
- node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
- if(safemode_or_autounlink)
- BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
- #if !(defined(BOOST_DISABLE_ASSERTS) || ( defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && defined(NDEBUG) ))
-
- iterator p(commit_data.node, this->priv_value_traits_ptr());
- if(!commit_data.link_left){
- ++p;
- }
-
-
- BOOST_ASSERT(( p == this->end() || !this->comp()(*p, value) ));
- BOOST_ASSERT(( p == this->begin() || !this->comp()(value, *--p) ));
- #endif
- node_algorithms::insert_unique_commit
- (this->header_ptr(), to_insert, commit_data);
- this->sz_traits().increment();
- return iterator(to_insert, this->priv_value_traits_ptr());
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- iterator insert_before(const_iterator pos, reference value)
- {
- node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
- if(safemode_or_autounlink)
- BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
- this->sz_traits().increment();
- return iterator(node_algorithms::insert_before
- (this->header_ptr(), pos.pointed_node(), to_insert), this->priv_value_traits_ptr());
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- void push_back(reference value)
- {
- node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
- if(safemode_or_autounlink)
- BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
- this->sz_traits().increment();
- node_algorithms::push_back(this->header_ptr(), to_insert);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- void push_front(reference value)
- {
- node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
- if(safemode_or_autounlink)
- BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
- this->sz_traits().increment();
- node_algorithms::push_front(this->header_ptr(), to_insert);
- }
-
-
-
-
-
-
-
-
- iterator erase(const_iterator i)
- {
- const_iterator ret(i);
- ++ret;
- node_ptr to_erase(i.pointed_node());
- if(safemode_or_autounlink)
- BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase));
- node_algorithms::erase(this->header_ptr(), to_erase);
- this->sz_traits().decrement();
- if(safemode_or_autounlink)
- node_algorithms::init(to_erase);
- return ret.unconst();
- }
-
-
-
-
-
-
-
-
-
- iterator erase(const_iterator b, const_iterator e)
- { size_type n; return this->private_erase(b, e, n); }
-
-
-
-
-
-
-
-
-
-
- size_type erase(const key_type &key)
- { return this->erase(key, this->key_comp()); }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class KeyType, class KeyTypeKeyCompare>
- BOOST_INTRUSIVE_DOC1ST(size_type
- , typename detail::disable_if_convertible<KeyTypeKeyCompare BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I size_type>::type)
- erase(const KeyType& key, KeyTypeKeyCompare comp)
- {
- std::pair<iterator,iterator> p = this->equal_range(key, comp);
- size_type n;
- this->private_erase(p.first, p.second, n);
- return n;
- }
-
-
-
-
-
-
-
-
-
-
-
- template<class Disposer>
- iterator erase_and_dispose(const_iterator i, Disposer disposer)
- {
- node_ptr to_erase(i.pointed_node());
- iterator ret(this->erase(i));
- disposer(this->get_value_traits().to_value_ptr(to_erase));
- return ret;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Disposer>
- size_type erase_and_dispose(const key_type &key, Disposer disposer)
- {
- std::pair<iterator,iterator> p = this->equal_range(key);
- size_type n;
- this->private_erase(p.first, p.second, n, disposer);
- return n;
- }
-
-
-
-
-
-
-
-
-
-
-
-
- template<class Disposer>
- iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
- { size_type n; return this->private_erase(b, e, n, disposer); }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class KeyType, class KeyTypeKeyCompare, class Disposer>
- BOOST_INTRUSIVE_DOC1ST(size_type
- , typename detail::disable_if_convertible<KeyTypeKeyCompare BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I size_type>::type)
- erase_and_dispose(const KeyType& key, KeyTypeKeyCompare comp, Disposer disposer)
- {
- std::pair<iterator,iterator> p = this->equal_range(key, comp);
- size_type n;
- this->private_erase(p.first, p.second, n, disposer);
- return n;
- }
-
-
-
-
-
-
-
-
-
- void clear()
- {
- if(safemode_or_autounlink){
- this->clear_and_dispose(detail::null_disposer());
- }
- else{
- node_algorithms::init_header(this->header_ptr());
- this->sz_traits().set_size(0);
- }
- }
-
-
-
-
-
-
-
-
-
- template<class Disposer>
- void clear_and_dispose(Disposer disposer)
- {
- node_algorithms::clear_and_dispose(this->header_ptr()
- , detail::node_disposer<Disposer, value_traits, AlgoType>(disposer, &this->get_value_traits()));
- node_algorithms::init_header(this->header_ptr());
- this->sz_traits().set_size(0);
- }
-
-
-
-
-
-
- size_type count(const key_type &key) const
- { return size_type(this->count(key, this->key_comp())); }
-
-
-
-
-
-
-
-
-
-
- template<class KeyType, class KeyTypeKeyCompare>
- size_type count(const KeyType &key, KeyTypeKeyCompare comp) const
- {
- std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp);
- size_type n = 0;
- for(; ret.first != ret.second; ++ret.first){ ++n; }
- return n;
- }
- #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
-
-
- size_type count(const key_type &key)
- { return size_type(this->count(key, this->key_comp())); }
- template<class KeyType, class KeyTypeKeyCompare>
- size_type count(const KeyType &key, KeyTypeKeyCompare comp)
- {
- std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp);
- size_type n = 0;
- for(; ret.first != ret.second; ++ret.first){ ++n; }
- return n;
- }
- #else
-
-
-
-
-
-
- iterator lower_bound(const key_type &key);
-
-
-
-
-
-
- const_iterator lower_bound(const key_type &key) const;
-
- template<class KeyType, class KeyTypeKeyCompare>
- iterator lower_bound(const KeyType &key, KeyTypeKeyCompare comp);
-
- template<class KeyType, class KeyTypeKeyCompare>
- const_iterator lower_bound(const KeyType &key, KeyTypeKeyCompare comp) const;
-
-
-
-
-
-
- iterator upper_bound(const key_type &key);
-
-
-
-
-
-
-
-
-
-
- template<class KeyType, class KeyTypeKeyCompare>
- iterator upper_bound(const KeyType &key, KeyTypeKeyCompare comp);
-
- const_iterator upper_bound(const key_type &key) const;
-
- template<class KeyType, class KeyTypeKeyCompare>
- const_iterator upper_bound(const KeyType &key, KeyTypeKeyCompare comp) const;
-
-
-
-
-
-
- iterator find(const key_type &key);
-
-
-
-
-
-
-
-
-
-
- template<class KeyType, class KeyTypeKeyCompare>
- iterator find(const KeyType &key, KeyTypeKeyCompare comp);
-
- const_iterator find(const key_type &key) const;
-
- template<class KeyType, class KeyTypeKeyCompare>
- const_iterator find(const KeyType &key, KeyTypeKeyCompare comp) const;
-
-
-
-
-
-
-
- std::pair<iterator,iterator> equal_range(const key_type &key);
-
-
-
-
-
-
-
-
-
-
-
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<iterator,iterator> equal_range(const KeyType &key, KeyTypeKeyCompare comp);
-
- std::pair<const_iterator, const_iterator> equal_range(const key_type &key) const;
-
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<const_iterator, const_iterator>
- equal_range(const KeyType &key, KeyTypeKeyCompare comp) const;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- std::pair<iterator,iterator> bounded_range
- (const key_type &lower_key, const key_type &upper_value, bool left_closed, bool right_closed);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<iterator,iterator> bounded_range
- (const KeyType &lower_key, const KeyType &upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed);
-
-
- std::pair<const_iterator,const_iterator> bounded_range
- (const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const;
-
- template<class KeyType, class KeyTypeKeyCompare>
- std::pair<const_iterator,const_iterator> bounded_range
- (const KeyType &lower_key, const KeyType &upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const;
-
-
-
-
-
-
-
-
-
-
-
-
- static iterator s_iterator_to(reference value);
-
-
-
-
-
-
-
-
-
-
-
-
- static const_iterator s_iterator_to(const_reference value);
-
-
-
-
-
-
-
-
-
- iterator iterator_to(reference value);
-
-
-
-
-
-
-
-
-
- const_iterator iterator_to(const_reference value) const;
-
-
-
-
-
-
-
-
-
-
-
- static void init_node(reference value);
- #endif
-
-
-
-
-
-
-
-
-
-
- pointer unlink_leftmost_without_rebalance()
- {
- node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance
- (this->header_ptr()));
- if(!to_be_disposed)
- return 0;
- this->sz_traits().decrement();
- if(safemode_or_autounlink)
- node_algorithms::init(to_be_disposed);
- return this->get_value_traits().to_value_ptr(to_be_disposed);
- }
- #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- void replace_node(iterator replace_this, reference with_this);
-
-
-
-
-
- void rebalance();
-
-
-
-
-
-
-
-
-
- iterator rebalance_subtree(iterator root);
- #endif
-
-
-
-
-
-
-
-
-
-
-
-
- static void remove_node(reference value)
- {
- BOOST_STATIC_ASSERT((!constant_time_size));
- node_ptr to_remove(value_traits::to_node_ptr(value));
- node_algorithms::unlink(to_remove);
- if(safemode_or_autounlink)
- node_algorithms::init(to_remove);
- }
-
-
-
-
-
-
- template <class ExtraChecker>
- void check(ExtraChecker extra_checker) const
- {
- typedef detail::key_nodeptr_comp<key_compare, value_traits, key_of_value> nodeptr_comp_t;
- nodeptr_comp_t nodeptr_comp(this->key_comp(), &this->get_value_traits());
- typedef typename get_node_checker<AlgoType, ValueTraits, nodeptr_comp_t, ExtraChecker>::type node_checker_t;
- typename node_checker_t::return_type checker_return;
- node_algorithms::check(this->header_ptr(), node_checker_t(nodeptr_comp, extra_checker), checker_return);
- if (constant_time_size)
- BOOST_INTRUSIVE_INVARIANT_ASSERT(this->sz_traits().get_size() == checker_return.node_count);
- }
-
-
-
-
-
-
- void check() const
- {
- check(detail::empty_node_checker<ValueTraits>());
- }
- friend bool operator==(const bstree_impl &x, const bstree_impl &y)
- {
- if(constant_time_size && x.size() != y.size()){
- return false;
- }
- return boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend());
- }
- friend bool operator!=(const bstree_impl &x, const bstree_impl &y)
- { return !(x == y); }
- friend bool operator<(const bstree_impl &x, const bstree_impl &y)
- { return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
- friend bool operator>(const bstree_impl &x, const bstree_impl &y)
- { return y < x; }
- friend bool operator<=(const bstree_impl &x, const bstree_impl &y)
- { return !(x > y); }
- friend bool operator>=(const bstree_impl &x, const bstree_impl &y)
- { return !(x < y); }
- friend void swap(bstree_impl &x, bstree_impl &y)
- { x.swap(y); }
-
- private:
- template<class Disposer>
- iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
- {
- for(n = 0; b != e; ++n)
- this->erase_and_dispose(b++, disposer);
- return b.unconst();
- }
- iterator private_erase(const_iterator b, const_iterator e, size_type &n)
- {
- for(n = 0; b != e; ++n)
- this->erase(b++);
- return b.unconst();
- }
-
- };
- #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
- template<class T, class ...Options>
- #else
- template<class T, class O1 = void, class O2 = void
- , class O3 = void, class O4 = void
- , class O5 = void, class O6 = void>
- #endif
- struct make_bstree
- {
-
- typedef typename pack_options
- < bstree_defaults,
- #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
- O1, O2, O3, O4, O5, O6
- #else
- Options...
- #endif
- >::type packed_options;
- typedef typename detail::get_value_traits
- <T, typename packed_options::proto_value_traits>::type value_traits;
- typedef bstree_impl
- < value_traits
- , typename packed_options::key_of_value
- , typename packed_options::compare
- , typename packed_options::size_type
- , packed_options::constant_time_size
- , BsTreeAlgorithms
- , typename packed_options::header_holder_type
- > implementation_defined;
-
- typedef implementation_defined type;
- };
- #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
- #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
- template<class T, class O1, class O2, class O3, class O4, class O5, class O6>
- #else
- template<class T, class ...Options>
- #endif
- class bstree
- : public make_bstree<T,
- #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
- O1, O2, O3, O4, O5, O6
- #else
- Options...
- #endif
- >::type
- {
- typedef typename make_bstree
- <T,
- #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
- O1, O2, O3, O4, O5, O6
- #else
- Options...
- #endif
- >::type Base;
- BOOST_MOVABLE_BUT_NOT_COPYABLE(bstree)
- public:
- typedef typename Base::key_compare key_compare;
- typedef typename Base::value_traits value_traits;
- typedef typename Base::iterator iterator;
- typedef typename Base::const_iterator const_iterator;
-
- BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
- bstree()
- : Base()
- {}
- explicit bstree( const key_compare &cmp, const value_traits &v_traits = value_traits())
- : Base(cmp, v_traits)
- {}
- template<class Iterator>
- bstree( bool unique, Iterator b, Iterator e
- , const key_compare &cmp = key_compare()
- , const value_traits &v_traits = value_traits())
- : Base(unique, b, e, cmp, v_traits)
- {}
- bstree(BOOST_RV_REF(bstree) x)
- : Base(BOOST_MOVE_BASE(Base, x))
- {}
- bstree& operator=(BOOST_RV_REF(bstree) x)
- { return static_cast<bstree &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
- template <class Cloner, class Disposer>
- void clone_from(const bstree &src, Cloner cloner, Disposer disposer)
- { Base::clone_from(src, cloner, disposer); }
- template <class Cloner, class Disposer>
- void clone_from(BOOST_RV_REF(bstree) src, Cloner cloner, Disposer disposer)
- { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
- static bstree &container_from_end_iterator(iterator end_iterator)
- { return static_cast<bstree &>(Base::container_from_end_iterator(end_iterator)); }
- static const bstree &container_from_end_iterator(const_iterator end_iterator)
- { return static_cast<const bstree &>(Base::container_from_end_iterator(end_iterator)); }
- static bstree &container_from_iterator(iterator it)
- { return static_cast<bstree &>(Base::container_from_iterator(it)); }
- static const bstree &container_from_iterator(const_iterator it)
- { return static_cast<const bstree &>(Base::container_from_iterator(it)); }
- };
- #endif
- }
- }
- #include <boost/intrusive/detail/config_end.hpp>
- #endif
|