Ticket #5787: optimize_multi_index.patch
File optimize_multi_index.patch, 16.7 KB (added by , 11 years ago) |
---|
-
boost_1_47_0/boost/multi_index/detail/bucket_array.hpp
diff -N -dur --strip-trailing-cr old/boost_1_47_0/boost/multi_index/detail/bucket_array.hpp new/boost_1_47_0/boost/multi_index/detail/bucket_array.hpp
old new 16 16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ 17 17 #include <algorithm> 18 18 #include <boost/multi_index/detail/auto_space.hpp> 19 #include <boost/multi_index/detail/hash_index_node.hpp> 19 //#include <boost/multi_index/detail/hash_index_node.hpp> 20 //#include <boost/multi_index/detail/hash_index_dbl_node.hpp> 20 21 #include <boost/multi_index/detail/prevent_eti.hpp> 21 22 #include <boost/noncopyable.hpp> 22 23 #include <cstddef> … … 82 83 } 83 84 }; 84 85 85 template<typename Allocator >86 template<typename Allocator, typename NodeImpl> 86 87 class bucket_array:public bucket_array_base 87 88 { 88 typedef typename prevent_eti< 89 Allocator, 90 hashed_index_node_impl< 91 typename boost::detail::allocator::rebind_to< 92 Allocator, 93 char 94 >::type 95 > 96 >::type node_impl_type; 89 typedef typename prevent_eti<Allocator,NodeImpl>::type 90 node_impl_type; 97 91 98 92 public: 99 93 typedef typename node_impl_type::pointer pointer; … … 164 158 #endif 165 159 }; 166 160 167 template<typename Allocator> 168 void swap(bucket_array<Allocator>& x,bucket_array<Allocator>& y) 161 template<typename Allocator, typename NodeImpl> 162 void swap(bucket_array<Allocator,NodeImpl>& x, 163 bucket_array<Allocator,NodeImpl>& y) 169 164 { 170 165 x.swap(y); 171 166 } … … 188 183 namespace detail{ 189 184 #endif 190 185 191 template<class Archive,typename Allocator >186 template<class Archive,typename Allocator,typename NodeImpl> 192 187 inline void load_construct_data( 193 Archive&,boost::multi_index::detail::bucket_array<Allocator >*,188 Archive&,boost::multi_index::detail::bucket_array<Allocator,NodeImpl>*, 194 189 const unsigned int) 195 190 { 196 191 throw_exception( -
boost_1_47_0/boost/multi_index/detail/hash_index_dbl_node.hpp
diff -N -dur --strip-trailing-cr old/boost_1_47_0/boost/multi_index/detail/hash_index_dbl_node.hpp new/boost_1_47_0/boost/multi_index/detail/hash_index_dbl_node.hpp
old new 1 /* Copyright 2003-2008 Joaquin M Lopez Munoz. 2 * Distributed under the Boost Software License, Version 1.0. 3 * (See accompanying file LICENSE_1_0.txt or copy at 4 * http://www.boost.org/LICENSE_1_0.txt) 5 * 6 * See http://www.boost.org/libs/multi_index for library home page. 7 */ 8 9 #ifndef BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_DBL_NODE_HPP 10 #define BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_DBL_NODE_HPP 11 12 #if defined(_MSC_VER)&&(_MSC_VER>=1200) 13 #pragma once 14 #endif 15 16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ 17 #include <boost/detail/allocator_utilities.hpp> 18 #include <boost/multi_index/detail/prevent_eti.hpp> 19 #include <functional> 20 21 namespace boost{ 22 23 namespace multi_index{ 24 25 namespace detail{ 26 27 /* double-linked node for use by hashed_index */ 28 29 template<typename Allocator> 30 struct hashed_index_dbl_node_impl 31 { 32 typedef typename prevent_eti< 33 Allocator, 34 typename boost::detail::allocator::rebind_to< 35 Allocator,hashed_index_dbl_node_impl 36 >::type 37 >::type::pointer pointer; 38 typedef typename prevent_eti< 39 Allocator, 40 typename boost::detail::allocator::rebind_to< 41 Allocator,hashed_index_dbl_node_impl 42 >::type 43 >::type::const_pointer const_pointer; 44 45 pointer& next(){return next_;} 46 pointer next()const{return next_;} 47 pointer& prev(){return prev_;} 48 pointer prev()const{return prev_;} 49 50 /* algorithmic stuff */ 51 52 static void increment(pointer& x,pointer bbegin,pointer bend) 53 { 54 std::less_equal<pointer> leq; 55 56 x=x->next(); 57 if(leq(bbegin,x)&&leq(x,bend)){ /* bucket node */ 58 do{ 59 ++x; 60 }while(x->next()==x); 61 x=x->next(); 62 } 63 } 64 65 static void link(pointer x,pointer pos) 66 { 67 x->next()=pos->next(); 68 pos->next()=x; 69 x->prev()=pos; 70 x->next()->prev()=x; 71 }; 72 73 static void unlink(pointer x) 74 { 75 x->prev()->next()=x->next(); 76 x->next()->prev()=x->prev(); 77 } 78 79 static pointer prev(pointer x) 80 { 81 return x->prev(); 82 } 83 84 static void unlink_next(pointer x) 85 { 86 x->next()=x->next()->next(); 87 x->next()->prev()=x; 88 } 89 90 private: 91 pointer next_; 92 pointer prev_; 93 }; 94 95 template<typename Super> 96 struct hashed_index_dbl_node_trampoline: 97 prevent_eti< 98 Super, 99 hashed_index_dbl_node_impl< 100 typename boost::detail::allocator::rebind_to< 101 typename Super::allocator_type, 102 char 103 >::type 104 > 105 >::type 106 { 107 typedef typename prevent_eti< 108 Super, 109 hashed_index_dbl_node_impl< 110 typename boost::detail::allocator::rebind_to< 111 typename Super::allocator_type, 112 char 113 >::type 114 > 115 >::type impl_type; 116 }; 117 118 template<typename Super> 119 struct hashed_index_dbl_node:Super,hashed_index_dbl_node_trampoline<Super> 120 { 121 private: 122 typedef hashed_index_dbl_node_trampoline<Super> trampoline; 123 124 public: 125 typedef typename trampoline::impl_type impl_type; 126 typedef typename trampoline::pointer impl_pointer; 127 typedef typename trampoline::const_pointer const_impl_pointer; 128 129 impl_pointer impl() 130 { 131 return static_cast<impl_pointer>( 132 static_cast<impl_type*>(static_cast<trampoline*>(this))); 133 } 134 135 const_impl_pointer impl()const 136 { 137 return static_cast<const_impl_pointer>( 138 static_cast<const impl_type*>(static_cast<const trampoline*>(this))); 139 } 140 141 static hashed_index_dbl_node* from_impl(impl_pointer x) 142 { 143 return static_cast<hashed_index_dbl_node*>( 144 static_cast<trampoline*>(&*x)); 145 } 146 147 static const hashed_index_dbl_node* from_impl(const_impl_pointer x) 148 { 149 return static_cast<const hashed_index_dbl_node*>( 150 static_cast<const trampoline*>(&*x)); 151 } 152 153 static void increment( 154 hashed_index_dbl_node*& x,impl_pointer bbegin,impl_pointer bend) 155 { 156 impl_pointer xi=x->impl(); 157 trampoline::increment(xi,bbegin,bend); 158 x=from_impl(xi); 159 } 160 }; 161 162 } /* namespace multi_index::detail */ 163 164 } /* namespace multi_index */ 165 166 } /* namespace boost */ 167 168 #endif -
boost_1_47_0/boost/multi_index/hashed_index.hpp
diff -N -dur --strip-trailing-cr old/boost_1_47_0/boost/multi_index/hashed_index.hpp new/boost_1_47_0/boost/multi_index/hashed_index.hpp
old new 1 /* Copyright 2003-201 1Joaquin M Lopez Munoz.1 /* Copyright 2003-2010 Joaquin M Lopez Munoz. 2 2 * Distributed under the Boost Software License, Version 1.0. 3 3 * (See accompanying file LICENSE_1_0.txt or copy at 4 4 * http://www.boost.org/LICENSE_1_0.txt) … … 26 26 #include <boost/multi_index/detail/bucket_array.hpp> 27 27 #include <boost/multi_index/detail/hash_index_iterator.hpp> 28 28 #include <boost/multi_index/detail/index_node_base.hpp> 29 #include <boost/multi_index/detail/hash_index_node.hpp> 30 #include <boost/multi_index/detail/hash_index_dbl_node.hpp> 29 31 #include <boost/multi_index/detail/modify_key_adaptor.hpp> 30 32 #include <boost/multi_index/detail/safe_ctr_proxy.hpp> 31 33 #include <boost/multi_index/detail/safe_mode.hpp> … … 67 69 68 70 template< 69 71 typename KeyFromValue,typename Hash,typename Pred, 70 typename SuperMeta,typename TagList,typename Category 72 typename SuperMeta,typename TagList,typename Category, 73 template <typename> class NodeType 71 74 > 72 75 class hashed_index: 73 76 BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS SuperMeta::type … … 76 79 #if BOOST_WORKAROUND(BOOST_MSVC,<1300) 77 80 ,public safe_ctr_proxy_impl< 78 81 hashed_index_iterator< 79 hashed_index_node<typename SuperMeta::type::node_type>, 80 bucket_array<typename SuperMeta::type::final_allocator_type> >, 81 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category> > 82 NodeType<typename SuperMeta::type::node_type>, 83 bucket_array< 84 typename SuperMeta::type::final_allocator_type, 85 typename NodeType<typename SuperMeta::type::node_type>::impl_type 86 > 87 >, 88 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category, 89 NodeType<typename SuperMeta::type::node_type> > > 82 90 #else 83 91 ,public safe_mode::safe_container< 84 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category> > 92 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category, 93 NodeType<typename SuperMeta::type::node_type> > > 85 94 #endif 86 95 #endif 87 96 … … 99 108 typedef typename SuperMeta::type super; 100 109 101 110 protected: 102 typedef hashed_index_node<103 typename super::node_type>node_type;111 typedef NodeType< 112 typename SuperMeta::type::node_type> node_type; 104 113 105 114 private: 106 115 typedef typename node_type::impl_type node_impl_type; 107 116 typedef typename node_impl_type::pointer node_impl_pointer; 108 117 typedef bucket_array< 109 typename super::final_allocator_type> bucket_array_type; 118 typename super::final_allocator_type, 119 typename NodeType<node_type>::impl_type 120 > bucket_array_type; 110 121 111 122 public: 112 123 /* types */ … … 196 207 * not supposed to be created on their own. No range ctor either. 197 208 */ 198 209 199 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category>& operator=( 200 const hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category>& x) 210 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category,NodeType>& 211 operator=(const hashed_index< 212 KeyFromValue,Hash,Pred,SuperMeta,TagList,Category,NodeType>& x) 201 213 { 202 214 this->final()=x.final(); 203 215 return *this; … … 405 417 this->final_clear_(); 406 418 } 407 419 408 void swap(hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category>& x) 420 void swap(hashed_index< 421 KeyFromValue,Hash,Pred,SuperMeta,TagList,Category,NodeType>& x) 409 422 { 410 423 BOOST_MULTI_INDEX_HASHED_INDEX_CHECK_INVARIANT; 411 424 this->final_swap_(x.final()); … … 605 618 hash(tuples::get<2>(args_list.get_head())), 606 619 eq(tuples::get<3>(args_list.get_head())), 607 620 buckets(al,header()->impl(),tuples::get<0>(args_list.get_head())), 608 mlf(1.0 f),621 mlf(1.0), 609 622 first_bucket(buckets.size()) 610 623 { 611 624 calculate_max_load(); 612 625 } 613 626 614 hashed_index( 615 const hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category>& x):627 hashed_index(const hashed_index< 628 KeyFromValue,Hash,Pred,SuperMeta,TagList,Category,NodeType>& x): 616 629 super(x), 617 630 618 631 #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) … … 663 676 #endif 664 677 665 678 void copy_( 666 const hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category>& x, 679 const hashed_index< 680 KeyFromValue,Hash,Pred,SuperMeta,TagList,Category,NodeType>& x, 667 681 const copy_map_type& map) 668 682 { 669 683 for(node_impl_pointer begin_org=x.buckets.begin(), … … 757 771 } 758 772 759 773 void swap_( 760 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category >& x)774 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category,NodeType>& x) 761 775 { 762 776 std::swap(key,x.key); 763 777 std::swap(hash,x.hash); … … 1094 1108 node_impl_pointer bend=buckets.end(); 1095 1109 node_impl_pointer pbuc=x->next(); 1096 1110 1097 while(!leq(bbegin,pbuc)||!leq(pbuc,bend))pbuc=pbuc->next(); 1111 /*while(!leq(bbegin,pbuc)||!leq(pbuc,bend))pbuc=pbuc->next();*/ 1112 if(!leq(bbegin,pbuc)||!leq(pbuc,bend)) 1113 pbuc = buckets.at(buckets.position( 1114 hash(key(node_type::from_impl(pbuc)->value())))); 1098 1115 if(buc!=static_cast<std::size_t>(pbuc-bbegin))return false; 1099 1116 1100 1117 node_impl_pointer y=x; … … 1115 1132 node_impl_pointer bend=buckets.end(); 1116 1133 node_impl_pointer pbuc=x->next(); 1117 1134 1118 while(!leq(bbegin,pbuc)||!leq(pbuc,bend))pbuc=pbuc->next(); 1135 /*while(!leq(bbegin,pbuc)||!leq(pbuc,bend))pbuc=pbuc->next();*/ 1136 if(!leq(bbegin,pbuc)||!leq(pbuc,bend)) 1137 pbuc = buckets.at(buckets.position( 1138 hash(key(node_type::from_impl(pbuc)->value())))); 1119 1139 if(buc!=static_cast<std::size_t>(pbuc-bbegin))return false; 1120 1140 1121 1141 node_impl_pointer y=x->next(); 1122 1142 if(y!=pbuc){ 1123 1143 if(eq(k,key(node_type::from_impl(y)->value()))){ … … 1173 1193 1174 1194 template< 1175 1195 typename KeyFromValue,typename Hash,typename Pred, 1176 typename SuperMeta,typename TagList,typename Category 1196 typename SuperMeta,typename TagList,typename Category, 1197 template <class> class NodeType 1177 1198 > 1178 1199 void swap( 1179 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category >& x,1180 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category >& y)1200 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category,NodeType>& x, 1201 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category,NodeType>& y) 1181 1202 { 1182 1203 x.swap(y); 1183 1204 } … … 1207 1228 { 1208 1229 typedef detail::hashed_index< 1209 1230 key_from_value_type,hash_type,pred_type, 1210 SuperMeta,tag_list_type,detail::hashed_unique_tag> type; 1231 SuperMeta,tag_list_type,detail::hashed_unique_tag, 1232 detail::hashed_index_node> type; 1211 1233 }; 1212 1234 }; 1213 1235 … … 1232 1254 { 1233 1255 typedef detail::hashed_index< 1234 1256 key_from_value_type,hash_type,pred_type, 1235 SuperMeta,tag_list_type,detail::hashed_non_unique_tag> type; 1257 SuperMeta,tag_list_type,detail::hashed_non_unique_tag, 1258 detail::hashed_index_node> type; 1259 }; 1260 }; 1261 1262 template<typename Arg1,typename Arg2,typename Arg3,typename Arg4> 1263 struct hashed_dbl_unique 1264 { 1265 typedef typename detail::hashed_index_args< 1266 Arg1,Arg2,Arg3,Arg4> index_args; 1267 typedef typename index_args::tag_list_type::type tag_list_type; 1268 typedef typename index_args::key_from_value_type key_from_value_type; 1269 typedef typename index_args::hash_type hash_type; 1270 typedef typename index_args::pred_type pred_type; 1271 1272 template<typename Super> 1273 struct node_class 1274 { 1275 typedef detail::hashed_index_dbl_node<Super> type; 1276 }; 1277 1278 template<typename SuperMeta> 1279 struct index_class 1280 { 1281 typedef detail::hashed_index< 1282 key_from_value_type,hash_type,pred_type, 1283 SuperMeta,tag_list_type,detail::hashed_unique_tag, 1284 detail::hashed_index_dbl_node> type; 1285 }; 1286 }; 1287 1288 template<typename Arg1,typename Arg2,typename Arg3,typename Arg4> 1289 struct hashed_dbl_non_unique 1290 { 1291 typedef typename detail::hashed_index_args< 1292 Arg1,Arg2,Arg3,Arg4> index_args; 1293 typedef typename index_args::tag_list_type::type tag_list_type; 1294 typedef typename index_args::key_from_value_type key_from_value_type; 1295 typedef typename index_args::hash_type hash_type; 1296 typedef typename index_args::pred_type pred_type; 1297 1298 template<typename Super> 1299 struct node_class 1300 { 1301 typedef detail::hashed_index_dbl_node<Super> type; 1302 }; 1303 1304 template<typename SuperMeta> 1305 struct index_class 1306 { 1307 typedef detail::hashed_index< 1308 key_from_value_type,hash_type,pred_type, 1309 SuperMeta,tag_list_type,detail::hashed_non_unique_tag, 1310 detail::hashed_index_dbl_node> type; 1236 1311 }; 1237 1312 }; 1238 1313 -
boost_1_47_0/boost/multi_index/hashed_index_fwd.hpp
diff -N -dur --strip-trailing-cr old/boost_1_47_0/boost/multi_index/hashed_index_fwd.hpp new/boost_1_47_0/boost/multi_index/hashed_index_fwd.hpp
old new 23 23 24 24 template< 25 25 typename KeyFromValue,typename Hash,typename Pred, 26 typename SuperMeta,typename TagList,typename Category 26 typename SuperMeta,typename TagList,typename Category, 27 template <class> class NodeType 27 28 > 28 29 class hashed_index; 29 30 30 31 template< 31 32 typename KeyFromValue,typename Hash,typename Pred, 32 typename SuperMeta,typename TagList,typename Category 33 typename SuperMeta,typename TagList,typename Category, 34 template <class> class NodeType 33 35 > 34 36 void swap( 35 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category >& x,36 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category >& y);37 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category,NodeType>& x, 38 hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category,NodeType>& y); 37 39 38 40 } /* namespace multi_index::detail */ 39 41 … … 51 53 > 52 54 struct hashed_non_unique; 53 55 56 template< 57 typename Arg1,typename Arg2=mpl::na, 58 typename Arg3=mpl::na,typename Arg4=mpl::na 59 > 60 struct hashed_dbl_unique; 61 62 template< 63 typename Arg1,typename Arg2=mpl::na, 64 typename Arg3=mpl::na,typename Arg4=mpl::na 65 > 66 struct hashed_dbl_non_unique; 67 54 68 } /* namespace multi_index */ 55 69 56 70 } /* namespace boost */