1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2006-2015
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/intrusive for documentation.
11 /////////////////////////////////////////////////////////////////////////////
12 #ifndef BOOST_INTRUSIVE_HASHTABLE_HPP
13 #define BOOST_INTRUSIVE_HASHTABLE_HPP
15 #include <boost/intrusive/detail/config_begin.hpp>
16 #include <boost/intrusive/intrusive_fwd.hpp>
18 //General intrusive utilities
19 #include <boost/intrusive/detail/hashtable_node.hpp>
20 #include <boost/intrusive/detail/transform_iterator.hpp>
21 #include <boost/intrusive/link_mode.hpp>
22 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
23 #include <boost/intrusive/detail/is_stateful_value_traits.hpp>
24 #include <boost/intrusive/detail/node_to_value.hpp>
25 #include <boost/intrusive/detail/exception_disposer.hpp>
26 #include <boost/intrusive/detail/node_cloner_disposer.hpp>
27 #include <boost/intrusive/detail/simple_disposers.hpp>
28 #include <boost/intrusive/detail/size_holder.hpp>
29 #include <boost/intrusive/detail/iterator.hpp>
31 //Implementation utilities
32 #include <boost/intrusive/unordered_set_hook.hpp>
33 #include <boost/intrusive/slist.hpp>
34 #include <boost/intrusive/pointer_traits.hpp>
35 #include <boost/intrusive/detail/mpl.hpp>
38 #include <boost/functional/hash.hpp>
39 #include <boost/intrusive/detail/assert.hpp>
40 #include <boost/static_assert.hpp>
41 #include <boost/move/utility_core.hpp>
42 #include <boost/move/adl_move_swap.hpp>
45 #include <boost/intrusive/detail/minimal_less_equal_header.hpp> //std::equal_to
46 #include <boost/intrusive/detail/minimal_pair_header.hpp> //std::pair
47 #include <algorithm> //std::lower_bound, std::upper_bound
48 #include <cstddef> //std::size_t
50 #if defined(BOOST_HAS_PRAGMA_ONCE)
59 template<class InputIt, class T>
60 InputIt priv_algo_find(InputIt first, InputIt last, const T& value)
62 for (; first != last; ++first) {
63 if (*first == value) {
70 template<class InputIt, class T>
71 typename boost::intrusive::iterator_traits<InputIt>::difference_type
72 priv_algo_count(InputIt first, InputIt last, const T& value)
74 typename boost::intrusive::iterator_traits<InputIt>::difference_type ret = 0;
75 for (; first != last; ++first) {
76 if (*first == value) {
83 template <class ForwardIterator1, class ForwardIterator2>
84 bool priv_algo_is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2)
87 boost::intrusive::iterator_traits<ForwardIterator2>::difference_type
89 //Efficiently compare identical prefixes: O(N) if sequences
90 //have the same elements in the same order.
91 for ( ; first1 != last1; ++first1, ++first2){
92 if (! (*first1 == *first2))
99 //Establish last2 assuming equal ranges by iterating over the
101 ForwardIterator2 last2 = first2;
102 boost::intrusive::iterator_advance(last2, boost::intrusive::iterator_distance(first1, last1));
103 for(ForwardIterator1 scan = first1; scan != last1; ++scan){
104 if (scan != (priv_algo_find)(first1, scan, *scan)){
105 continue; //We've seen this one before.
107 distance_type matches = (priv_algo_count)(first2, last2, *scan);
108 if (0 == matches || (priv_algo_count)(scan, last1, *scan != matches)){
115 template<int Dummy = 0>
116 struct prime_list_holder
120 template <class SizeType> // sizeof(SizeType) < sizeof(std::size_t)
121 static BOOST_INTRUSIVE_FORCEINLINE SizeType truncate_size_type(std::size_t n, detail::true_)
123 return n < std::size_t(SizeType(-1)) ? static_cast<SizeType>(n) : SizeType(-1);
126 template <class SizeType> // sizeof(SizeType) == sizeof(std::size_t)
127 static BOOST_INTRUSIVE_FORCEINLINE SizeType truncate_size_type(std::size_t n, detail::false_)
129 return static_cast<SizeType>(n);
132 template <class SizeType> //sizeof(SizeType) > sizeof(std::size_t)
133 static BOOST_INTRUSIVE_FORCEINLINE SizeType suggested_upper_bucket_count_dispatch(SizeType n, detail::true_)
135 std::size_t const c = n > std::size_t(-1)
137 : suggested_upper_bucket_count_impl(static_cast<std::size_t>(n));
138 return static_cast<SizeType>(c);
141 template <class SizeType> //sizeof(SizeType) > sizeof(std::size_t)
142 static BOOST_INTRUSIVE_FORCEINLINE SizeType suggested_lower_bucket_count_dispatch(SizeType n, detail::true_)
144 std::size_t const c = n > std::size_t(-1)
146 : suggested_lower_bucket_count_impl(static_cast<std::size_t>(n));
147 return static_cast<SizeType>(c);
150 template <class SizeType>
151 static BOOST_INTRUSIVE_FORCEINLINE SizeType suggested_upper_bucket_count_dispatch(SizeType n, detail::false_)
153 std::size_t const c = suggested_upper_bucket_count_impl(static_cast<std::size_t>(n));
154 return truncate_size_type<SizeType>(c, detail::bool_<(sizeof(SizeType) < sizeof(std::size_t))>());
158 template <class SizeType>
159 static BOOST_INTRUSIVE_FORCEINLINE SizeType suggested_lower_bucket_count_dispatch(SizeType n, detail::false_)
161 std::size_t const c = suggested_lower_bucket_count_impl(static_cast<std::size_t>(n));
162 return truncate_size_type<SizeType>(c, detail::bool_<(sizeof(SizeType) < sizeof(std::size_t))>());
165 static const std::size_t prime_list[];
166 static const std::size_t prime_list_size;
168 static std::size_t suggested_lower_bucket_count_impl(std::size_t n)
170 const std::size_t *primes = &prime_list_holder<0>::prime_list[0];
171 const std::size_t *primes_end = primes + prime_list_holder<0>::prime_list_size;
172 std::size_t const* bound = std::lower_bound(primes, primes_end, n);
173 //Tables have upper SIZE_MAX, so we must always found an entry
174 BOOST_INTRUSIVE_INVARIANT_ASSERT(bound != primes_end);
175 bound -= std::size_t(bound != primes);
179 static std::size_t suggested_upper_bucket_count_impl(std::size_t n)
181 const std::size_t *primes = &prime_list_holder<0>::prime_list[0];
182 const std::size_t *primes_end = primes + prime_list_holder<0>::prime_list_size;
183 std::size_t const* bound = std::upper_bound(primes, primes_end, n);
184 bound -= std::size_t(bound == primes_end);
190 template <class SizeType>
191 static BOOST_INTRUSIVE_FORCEINLINE SizeType suggested_upper_bucket_count(SizeType n)
193 return (suggested_upper_bucket_count_dispatch)(n, detail::bool_<(sizeof(SizeType) > sizeof(std::size_t))>());
196 template <class SizeType>
197 static BOOST_INTRUSIVE_FORCEINLINE SizeType suggested_lower_bucket_count(SizeType n)
199 return (suggested_lower_bucket_count_dispatch)(n, detail::bool_<(sizeof(SizeType) > sizeof(std::size_t))>());
203 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
205 //We only support LLP64(Win64) or LP64(most Unix) data models
206 #ifdef _WIN64 //In 64 bit windows sizeof(size_t) == sizeof(unsigned long long)
207 #define BOOST_INTRUSIVE_PRIME_C(NUMBER) NUMBER##ULL
208 #define BOOST_INTRUSIVE_64_BIT_SIZE_T 1
209 #else //In 32 bit windows and 32/64 bit unixes sizeof(size_t) == sizeof(unsigned long)
210 #define BOOST_INTRUSIVE_PRIME_C(NUMBER) NUMBER##UL
211 #define BOOST_INTRUSIVE_64_BIT_SIZE_T (((((ULONG_MAX>>16)>>16)>>16)>>15) != 0)
215 const std::size_t prime_list_holder<Dummy>::prime_list[] = {
216 BOOST_INTRUSIVE_PRIME_C(3), BOOST_INTRUSIVE_PRIME_C(7),
217 BOOST_INTRUSIVE_PRIME_C(11), BOOST_INTRUSIVE_PRIME_C(17),
218 BOOST_INTRUSIVE_PRIME_C(29), BOOST_INTRUSIVE_PRIME_C(53),
219 BOOST_INTRUSIVE_PRIME_C(97), BOOST_INTRUSIVE_PRIME_C(193),
220 BOOST_INTRUSIVE_PRIME_C(389), BOOST_INTRUSIVE_PRIME_C(769),
221 BOOST_INTRUSIVE_PRIME_C(1543), BOOST_INTRUSIVE_PRIME_C(3079),
222 BOOST_INTRUSIVE_PRIME_C(6151), BOOST_INTRUSIVE_PRIME_C(12289),
223 BOOST_INTRUSIVE_PRIME_C(24593), BOOST_INTRUSIVE_PRIME_C(49157),
224 BOOST_INTRUSIVE_PRIME_C(98317), BOOST_INTRUSIVE_PRIME_C(196613),
225 BOOST_INTRUSIVE_PRIME_C(393241), BOOST_INTRUSIVE_PRIME_C(786433),
226 BOOST_INTRUSIVE_PRIME_C(1572869), BOOST_INTRUSIVE_PRIME_C(3145739),
227 BOOST_INTRUSIVE_PRIME_C(6291469), BOOST_INTRUSIVE_PRIME_C(12582917),
228 BOOST_INTRUSIVE_PRIME_C(25165843), BOOST_INTRUSIVE_PRIME_C(50331653),
229 BOOST_INTRUSIVE_PRIME_C(100663319), BOOST_INTRUSIVE_PRIME_C(201326611),
230 BOOST_INTRUSIVE_PRIME_C(402653189), BOOST_INTRUSIVE_PRIME_C(805306457),
231 BOOST_INTRUSIVE_PRIME_C(1610612741), BOOST_INTRUSIVE_PRIME_C(3221225473),
232 #if BOOST_INTRUSIVE_64_BIT_SIZE_T
233 //Taken from Boost.MultiIndex code, thanks to Joaquin M Lopez Munoz.
234 BOOST_INTRUSIVE_PRIME_C(6442450939), BOOST_INTRUSIVE_PRIME_C(12884901893),
235 BOOST_INTRUSIVE_PRIME_C(25769803751), BOOST_INTRUSIVE_PRIME_C(51539607551),
236 BOOST_INTRUSIVE_PRIME_C(103079215111), BOOST_INTRUSIVE_PRIME_C(206158430209),
237 BOOST_INTRUSIVE_PRIME_C(412316860441), BOOST_INTRUSIVE_PRIME_C(824633720831),
238 BOOST_INTRUSIVE_PRIME_C(1649267441651), BOOST_INTRUSIVE_PRIME_C(3298534883309),
239 BOOST_INTRUSIVE_PRIME_C(6597069766657), BOOST_INTRUSIVE_PRIME_C(13194139533299),
240 BOOST_INTRUSIVE_PRIME_C(26388279066623), BOOST_INTRUSIVE_PRIME_C(52776558133303),
241 BOOST_INTRUSIVE_PRIME_C(105553116266489), BOOST_INTRUSIVE_PRIME_C(211106232532969),
242 BOOST_INTRUSIVE_PRIME_C(422212465066001), BOOST_INTRUSIVE_PRIME_C(844424930131963),
243 BOOST_INTRUSIVE_PRIME_C(1688849860263953), BOOST_INTRUSIVE_PRIME_C(3377699720527861),
244 BOOST_INTRUSIVE_PRIME_C(6755399441055731), BOOST_INTRUSIVE_PRIME_C(13510798882111483),
245 BOOST_INTRUSIVE_PRIME_C(27021597764222939), BOOST_INTRUSIVE_PRIME_C(54043195528445957),
246 BOOST_INTRUSIVE_PRIME_C(108086391056891903), BOOST_INTRUSIVE_PRIME_C(216172782113783843),
247 BOOST_INTRUSIVE_PRIME_C(432345564227567621), BOOST_INTRUSIVE_PRIME_C(864691128455135207),
248 BOOST_INTRUSIVE_PRIME_C(1729382256910270481), BOOST_INTRUSIVE_PRIME_C(3458764513820540933),
249 BOOST_INTRUSIVE_PRIME_C(6917529027641081903), BOOST_INTRUSIVE_PRIME_C(13835058055282163729),
250 BOOST_INTRUSIVE_PRIME_C(18446744073709551557), BOOST_INTRUSIVE_PRIME_C(18446744073709551615) //Upper limit, just in case
252 BOOST_INTRUSIVE_PRIME_C(4294967291), BOOST_INTRUSIVE_PRIME_C(4294967295) //Upper limit, just in case
256 #undef BOOST_INTRUSIVE_PRIME_C
257 #undef BOOST_INTRUSIVE_64_BIT_SIZE_T
259 #endif //#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
262 const std::size_t prime_list_holder<Dummy>::prime_list_size
263 = sizeof(prime_list)/sizeof(std::size_t);
265 struct hash_bool_flags
267 static const std::size_t unique_keys_pos = 1u;
268 static const std::size_t constant_time_size_pos = 2u;
269 static const std::size_t power_2_buckets_pos = 4u;
270 static const std::size_t cache_begin_pos = 8u;
271 static const std::size_t compare_hash_pos = 16u;
272 static const std::size_t incremental_pos = 32u;
277 template<class SupposedValueTraits>
278 struct get_slist_impl_from_supposed_value_traits
280 typedef SupposedValueTraits value_traits;
281 typedef typename detail::get_node_traits
282 <value_traits>::type node_traits;
283 typedef typename get_slist_impl
284 <typename reduced_slist_node_traits
289 template<class SupposedValueTraits>
290 struct unordered_bucket_impl
293 get_slist_impl_from_supposed_value_traits
294 <SupposedValueTraits>::type slist_impl;
295 typedef bucket_impl<slist_impl> implementation_defined;
296 typedef implementation_defined type;
299 template<class SupposedValueTraits>
300 struct unordered_bucket_ptr_impl
302 typedef typename detail::get_node_traits
303 <SupposedValueTraits>::type::node_ptr node_ptr;
304 typedef typename unordered_bucket_impl
305 <SupposedValueTraits>::type bucket_type;
307 typedef typename pointer_traits
308 <node_ptr>::template rebind_pointer
309 < bucket_type >::type implementation_defined;
310 typedef implementation_defined type;
314 struct store_hash_is_true
317 struct two_or_three {yes_type _[2 + Add];};
318 template <class U> static yes_type test(...);
319 template <class U> static two_or_three<U::store_hash> test (int);
320 static const bool value = sizeof(test<T>(0)) > sizeof(yes_type)*2;
324 struct optimize_multikey_is_true
327 struct two_or_three {yes_type _[2 + Add];};
328 template <class U> static yes_type test(...);
329 template <class U> static two_or_three<U::optimize_multikey> test (int);
330 static const bool value = sizeof(test<T>(0)) > sizeof(yes_type)*2;
333 struct insert_commit_data_impl
338 template<class Node, class SlistNodePtr>
339 BOOST_INTRUSIVE_FORCEINLINE typename pointer_traits<SlistNodePtr>::template rebind_pointer<Node>::type
340 dcast_bucket_ptr(const SlistNodePtr &p)
342 typedef typename pointer_traits<SlistNodePtr>::template rebind_pointer<Node>::type node_ptr;
343 return pointer_traits<node_ptr>::pointer_to(static_cast<Node&>(*p));
346 template<class NodeTraits>
347 struct group_functions
349 // A group is reverse-linked
351 // A is "first in group"
352 // C is "last in group"
353 // __________________
355 // | | | | | | <- Group links
358 // A|_| B|_| C|_| D|_|
360 // ^ | ^ | ^ | ^ V <- Bucket links
361 // _ _____| |_____| |______| |____| |
363 // ^________________________________|
366 typedef NodeTraits node_traits;
367 typedef unordered_group_adapter<node_traits> group_traits;
368 typedef typename node_traits::node_ptr node_ptr;
369 typedef typename node_traits::node node;
370 typedef typename reduced_slist_node_traits
371 <node_traits>::type reduced_node_traits;
372 typedef typename reduced_node_traits::node_ptr slist_node_ptr;
373 typedef typename reduced_node_traits::node slist_node;
374 typedef circular_slist_algorithms<group_traits> group_algorithms;
375 typedef circular_slist_algorithms<node_traits> node_algorithms;
377 static slist_node_ptr get_bucket_before_begin
378 (slist_node_ptr bucket_beg, slist_node_ptr bucket_end, node_ptr p)
380 //First find the last node of p's group.
381 //This requires checking the first node of the next group or
383 node_ptr prev_node = p;
384 node_ptr nxt(node_traits::get_next(p));
385 while(!(bucket_beg <= nxt && nxt <= bucket_end) &&
386 (group_traits::get_next(nxt) == prev_node)){
388 nxt = node_traits::get_next(nxt);
391 //If we've reached the bucket node just return it.
392 if(bucket_beg <= nxt && nxt <= bucket_end){
396 //Otherwise, iterate using group links until the bucket node
397 node_ptr first_node_of_group = nxt;
398 node_ptr last_node_group = group_traits::get_next(first_node_of_group);
399 slist_node_ptr possible_end = node_traits::get_next(last_node_group);
401 while(!(bucket_beg <= possible_end && possible_end <= bucket_end)){
402 first_node_of_group = detail::dcast_bucket_ptr<node>(possible_end);
403 last_node_group = group_traits::get_next(first_node_of_group);
404 possible_end = node_traits::get_next(last_node_group);
409 static node_ptr get_prev_to_first_in_group(slist_node_ptr bucket_node, node_ptr first_in_group)
411 node_ptr nb = detail::dcast_bucket_ptr<node>(bucket_node);
413 while((n = node_traits::get_next(nb)) != first_in_group){
414 nb = group_traits::get_next(n); //go to last in group
419 static void erase_from_group(slist_node_ptr end_ptr, node_ptr to_erase_ptr, detail::true_)
421 node_ptr const nxt_ptr(node_traits::get_next(to_erase_ptr));
422 //Check if the next node is in the group (not end node) and reverse linked to
423 //'to_erase_ptr'. Erase if that's the case.
424 if(nxt_ptr != end_ptr && to_erase_ptr == group_traits::get_next(nxt_ptr)){
425 group_algorithms::unlink_after(nxt_ptr);
429 BOOST_INTRUSIVE_FORCEINLINE static void erase_from_group(const slist_node_ptr&, const node_ptr&, detail::false_)
432 BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_last_in_group(node_ptr first_in_group, detail::true_)
433 { return group_traits::get_next(first_in_group); }
435 BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_last_in_group(node_ptr n, detail::false_)
438 static node_ptr get_first_in_group(node_ptr n, detail::true_)
441 while(n == node_traits::get_next((ng = group_traits::get_next(n)))){
447 BOOST_INTRUSIVE_FORCEINLINE static node_ptr next_group_if_first_in_group(node_ptr ptr)
449 return node_traits::get_next(group_traits::get_next(ptr));
452 BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_first_in_group(node_ptr n, detail::false_)
455 BOOST_INTRUSIVE_FORCEINLINE static void insert_in_group(node_ptr first_in_group, node_ptr n, true_)
456 { group_algorithms::link_after(first_in_group, n); }
458 static void insert_in_group(const node_ptr&, const node_ptr&, false_)
461 BOOST_INTRUSIVE_FORCEINLINE static node_ptr split_group(node_ptr const new_first_in_group)
463 node_ptr const first((get_first_in_group)(new_first_in_group, detail::true_()));
464 if(first != new_first_in_group){
465 node_ptr const last = group_traits::get_next(first);
466 group_traits::set_next(first, group_traits::get_next(new_first_in_group));
467 group_traits::set_next(new_first_in_group, last);
473 template<class BucketType, class SplitTraits>
474 class incremental_rehash_rollback
477 typedef BucketType bucket_type;
478 typedef SplitTraits split_traits;
480 incremental_rehash_rollback();
481 incremental_rehash_rollback & operator=(const incremental_rehash_rollback &);
482 incremental_rehash_rollback (const incremental_rehash_rollback &);
485 incremental_rehash_rollback
486 (bucket_type &source_bucket, bucket_type &destiny_bucket, split_traits &split_traits)
487 : source_bucket_(source_bucket), destiny_bucket_(destiny_bucket)
488 , split_traits_(split_traits), released_(false)
491 BOOST_INTRUSIVE_FORCEINLINE void release()
492 { released_ = true; }
494 ~incremental_rehash_rollback()
497 //If an exception is thrown, just put all moved nodes back in the old bucket
498 //and move back the split mark.
499 destiny_bucket_.splice_after(destiny_bucket_.before_begin(), source_bucket_);
500 split_traits_.decrement();
505 bucket_type &source_bucket_;
506 bucket_type &destiny_bucket_;
507 split_traits &split_traits_;
511 template<class NodeTraits>
512 struct node_functions
514 BOOST_INTRUSIVE_FORCEINLINE static void store_hash(typename NodeTraits::node_ptr p, std::size_t h, true_)
515 { return NodeTraits::set_hash(p, h); }
517 BOOST_INTRUSIVE_FORCEINLINE static void store_hash(typename NodeTraits::node_ptr, std::size_t, false_)
521 BOOST_INTRUSIVE_FORCEINLINE std::size_t hash_to_bucket(std::size_t hash_value, std::size_t bucket_cnt, detail::false_)
522 { return hash_value % bucket_cnt; }
524 BOOST_INTRUSIVE_FORCEINLINE std::size_t hash_to_bucket(std::size_t hash_value, std::size_t bucket_cnt, detail::true_)
525 { return hash_value & (bucket_cnt - 1); }
527 template<bool Power2Buckets, bool Incremental>
528 BOOST_INTRUSIVE_FORCEINLINE std::size_t hash_to_bucket_split(std::size_t hash_value, std::size_t bucket_cnt, std::size_t split)
530 std::size_t bucket_number = detail::hash_to_bucket(hash_value, bucket_cnt, detail::bool_<Power2Buckets>());
532 bucket_number -= static_cast<std::size_t>(bucket_number >= split)*(bucket_cnt/2);
533 return bucket_number;
536 } //namespace detail {
538 //!This metafunction will obtain the type of a bucket
539 //!from the value_traits or hook option to be used with
541 template<class ValueTraitsOrHookOption>
542 struct unordered_bucket
543 : public detail::unordered_bucket_impl
544 <typename ValueTraitsOrHookOption::
545 template pack<empty>::proto_value_traits
549 //!This metafunction will obtain the type of a bucket pointer
550 //!from the value_traits or hook option to be used with
552 template<class ValueTraitsOrHookOption>
553 struct unordered_bucket_ptr
554 : public detail::unordered_bucket_ptr_impl
555 <typename ValueTraitsOrHookOption::
556 template pack<empty>::proto_value_traits
560 //!This metafunction will obtain the type of the default bucket traits
561 //!(when the user does not specify the bucket_traits<> option) from the
562 //!value_traits or hook option to be used with
564 template<class ValueTraitsOrHookOption>
565 struct unordered_default_bucket_traits
567 typedef typename ValueTraitsOrHookOption::
568 template pack<empty>::proto_value_traits supposed_value_traits;
569 typedef typename detail::
570 get_slist_impl_from_supposed_value_traits
571 <supposed_value_traits>::type slist_impl;
572 typedef bucket_traits_impl
573 <slist_impl> implementation_defined;
574 typedef implementation_defined type;
577 struct default_bucket_traits;
579 //hashtable default hook traits
580 struct default_hashtable_hook_applier
581 { template <class T> struct apply{ typedef typename T::default_hashtable_hook type; }; };
584 struct is_default_hook_tag<default_hashtable_hook_applier>
585 { static const bool value = true; };
587 struct hashtable_defaults
589 typedef default_hashtable_hook_applier proto_value_traits;
590 typedef std::size_t size_type;
591 typedef void key_of_value;
594 typedef default_bucket_traits bucket_traits;
595 static const bool constant_time_size = true;
596 static const bool power_2_buckets = false;
597 static const bool cache_begin = false;
598 static const bool compare_hash = false;
599 static const bool incremental = false;
602 template<class ValueTraits, bool IsConst>
603 struct downcast_node_to_value_t
604 : public detail::node_to_value<ValueTraits, IsConst>
606 typedef detail::node_to_value<ValueTraits, IsConst> base_t;
607 typedef typename base_t::result_type result_type;
608 typedef ValueTraits value_traits;
609 typedef typename get_slist_impl
610 <typename reduced_slist_node_traits
611 <typename value_traits::node_traits>::type
613 typedef typename detail::add_const_if_c
614 <typename slist_impl::node, IsConst>::type & first_argument_type;
615 typedef typename detail::add_const_if_c
616 < typename ValueTraits::node_traits::node
617 , IsConst>::type & intermediate_argument_type;
618 typedef typename pointer_traits
619 <typename ValueTraits::pointer>::
620 template rebind_pointer
621 <const ValueTraits>::type const_value_traits_ptr;
623 BOOST_INTRUSIVE_FORCEINLINE downcast_node_to_value_t(const const_value_traits_ptr &ptr)
627 BOOST_INTRUSIVE_FORCEINLINE result_type operator()(first_argument_type arg) const
628 { return this->base_t::operator()(static_cast<intermediate_argument_type>(arg)); }
631 template<class F, class SlistNodePtr, class NodePtr>
632 struct node_cast_adaptor
633 //Use public inheritance to avoid MSVC bugs with closures
634 : public detail::ebo_functor_holder<F>
636 typedef detail::ebo_functor_holder<F> base_t;
638 typedef typename pointer_traits<SlistNodePtr>::element_type slist_node;
639 typedef typename pointer_traits<NodePtr>::element_type node;
641 template<class ConvertibleToF, class RealValuTraits>
642 BOOST_INTRUSIVE_FORCEINLINE node_cast_adaptor(const ConvertibleToF &c2f, const RealValuTraits *traits)
643 : base_t(base_t(c2f, traits))
646 BOOST_INTRUSIVE_FORCEINLINE typename base_t::node_ptr operator()(const slist_node &to_clone)
647 { return base_t::operator()(static_cast<const node &>(to_clone)); }
649 BOOST_INTRUSIVE_FORCEINLINE void operator()(SlistNodePtr to_clone)
651 base_t::operator()(pointer_traits<NodePtr>::pointer_to(static_cast<node &>(*to_clone)));
655 //bucket_plus_vtraits stores ValueTraits + BucketTraits
656 //this data is needed by iterators to obtain the
657 //value from the iterator and detect the bucket
658 template<class ValueTraits, class BucketTraits>
659 struct bucket_plus_vtraits
661 typedef BucketTraits bucket_traits;
662 typedef ValueTraits value_traits;
664 static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
667 detail::get_slist_impl_from_supposed_value_traits
668 <value_traits>::type slist_impl;
669 typedef typename value_traits::node_traits node_traits;
670 typedef unordered_group_adapter<node_traits> group_traits;
671 typedef typename slist_impl::iterator siterator;
672 typedef bucket_impl<slist_impl> bucket_type;
673 typedef detail::group_functions<node_traits> group_functions_t;
674 typedef typename slist_impl::node_algorithms node_algorithms;
675 typedef typename slist_impl::node_ptr slist_node_ptr;
676 typedef typename node_traits::node_ptr node_ptr;
677 typedef typename node_traits::node node;
678 typedef typename value_traits::value_type value_type;
679 typedef typename value_traits::pointer pointer;
680 typedef typename value_traits::const_pointer const_pointer;
681 typedef typename pointer_traits<pointer>::reference reference;
682 typedef typename pointer_traits
683 <const_pointer>::reference const_reference;
684 typedef circular_slist_algorithms<group_traits> group_algorithms;
685 typedef typename pointer_traits
686 <typename value_traits::pointer>::
687 template rebind_pointer
688 <const value_traits>::type const_value_traits_ptr;
689 typedef typename pointer_traits
690 <typename value_traits::pointer>::
691 template rebind_pointer
692 <const bucket_plus_vtraits>::type const_bucket_value_traits_ptr;
693 typedef typename detail::unordered_bucket_ptr_impl
694 <value_traits>::type bucket_ptr;
696 template<class BucketTraitsType>
697 BOOST_INTRUSIVE_FORCEINLINE bucket_plus_vtraits(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits)
698 : data(val_traits, ::boost::forward<BucketTraitsType>(b_traits))
701 BOOST_INTRUSIVE_FORCEINLINE bucket_plus_vtraits & operator =(const bucket_plus_vtraits &x)
702 { data.bucket_traits_ = x.data.bucket_traits_; return *this; }
704 BOOST_INTRUSIVE_FORCEINLINE const_value_traits_ptr priv_value_traits_ptr() const
705 { return pointer_traits<const_value_traits_ptr>::pointer_to(this->priv_value_traits()); }
707 //bucket_value_traits
709 BOOST_INTRUSIVE_FORCEINLINE const bucket_plus_vtraits &get_bucket_value_traits() const
712 BOOST_INTRUSIVE_FORCEINLINE bucket_plus_vtraits &get_bucket_value_traits()
715 BOOST_INTRUSIVE_FORCEINLINE const_bucket_value_traits_ptr bucket_value_traits_ptr() const
716 { return pointer_traits<const_bucket_value_traits_ptr>::pointer_to(this->get_bucket_value_traits()); }
720 BOOST_INTRUSIVE_FORCEINLINE const value_traits &priv_value_traits() const
721 { return this->data; }
723 BOOST_INTRUSIVE_FORCEINLINE value_traits &priv_value_traits()
724 { return this->data; }
728 BOOST_INTRUSIVE_FORCEINLINE const bucket_traits &priv_bucket_traits() const
729 { return this->data.bucket_traits_; }
731 BOOST_INTRUSIVE_FORCEINLINE bucket_traits &priv_bucket_traits()
732 { return this->data.bucket_traits_; }
735 BOOST_INTRUSIVE_FORCEINLINE bucket_ptr priv_bucket_pointer() const
736 { return this->priv_bucket_traits().bucket_begin(); }
738 std::size_t priv_bucket_count() const
739 { return this->priv_bucket_traits().bucket_count(); }
741 BOOST_INTRUSIVE_FORCEINLINE bucket_ptr priv_invalid_bucket() const
743 const bucket_traits &rbt = this->priv_bucket_traits();
744 return rbt.bucket_begin() + rbt.bucket_count();
747 BOOST_INTRUSIVE_FORCEINLINE siterator priv_invalid_local_it() const
748 { return this->priv_bucket_traits().bucket_begin()->before_begin(); }
750 template<class NodeDisposer>
751 static std::size_t priv_erase_from_single_bucket(bucket_type &b, siterator sbefore_first, siterator slast, NodeDisposer node_disposer, detail::true_) //optimize multikey
754 siterator const sfirst(++siterator(sbefore_first));
756 node_ptr const nf = detail::dcast_bucket_ptr<node>(sfirst.pointed_node());
757 node_ptr const nl = detail::dcast_bucket_ptr<node>(slast.pointed_node());
758 node_ptr const ne = detail::dcast_bucket_ptr<node>(b.end().pointed_node());
760 if(group_functions_t::next_group_if_first_in_group(nf) != nf) {
761 // The node is at the beginning of a group.
763 group_functions_t::split_group(nl);
767 node_ptr const group1 = group_functions_t::split_group(nf);
769 node_ptr const group2 = group_functions_t::split_group(ne);
770 if(nf == group2) { //Both first and last in the same group
771 //so join group1 and group2
772 node_ptr const end1 = group_traits::get_next(group1);
773 node_ptr const end2 = group_traits::get_next(group2);
774 group_traits::set_next(group1, end2);
775 group_traits::set_next(group2, end1);
780 siterator it(++siterator(sbefore_first));
782 node_disposer((it++).pointed_node());
785 b.erase_after(sbefore_first, slast);
790 template<class NodeDisposer>
791 static std::size_t priv_erase_from_single_bucket(bucket_type &b, siterator sbefore_first, siterator slast, NodeDisposer node_disposer, detail::false_) //optimize multikey
794 siterator it(++siterator(sbefore_first));
796 node_disposer((it++).pointed_node());
799 b.erase_after(sbefore_first, slast);
803 template<class NodeDisposer>
804 static void priv_erase_node(bucket_type &b, siterator i, NodeDisposer node_disposer, detail::true_) //optimize multikey
806 node_ptr const ne(detail::dcast_bucket_ptr<node>(b.end().pointed_node()));
807 node_ptr n(detail::dcast_bucket_ptr<node>(i.pointed_node()));
808 node_ptr pos = node_traits::get_next(group_traits::get_next(n));
810 node_ptr nn(node_traits::get_next(n));
813 //Node is the first of the group
814 bn = group_functions_t::get_prev_to_first_in_group(ne, n);
816 //Unlink the rest of the group if it's not the last node of its group
817 if(nn != ne && group_traits::get_next(nn) == n){
818 group_algorithms::unlink_after(nn);
821 else if(nn != ne && group_traits::get_next(nn) == n){
822 //Node is not the end of the group
823 bn = group_traits::get_next(n);
824 group_algorithms::unlink_after(nn);
827 //Node is the end of the group
828 bn = group_traits::get_next(n);
829 node_ptr const x(group_algorithms::get_previous_node(n));
830 group_algorithms::unlink_after(x);
832 b.erase_after_and_dispose(bucket_type::s_iterator_to(*bn), node_disposer);
835 template<class NodeDisposer>
836 BOOST_INTRUSIVE_FORCEINLINE static void priv_erase_node(bucket_type &b, siterator i, NodeDisposer node_disposer, detail::false_) //optimize multikey
837 { b.erase_after_and_dispose(b.previous(i), node_disposer); }
839 template<class NodeDisposer, bool OptimizeMultikey>
840 std::size_t priv_erase_node_range( siterator const &before_first_it, std::size_t const first_bucket
841 , siterator const &last_it, std::size_t const last_bucket
842 , NodeDisposer node_disposer, detail::bool_<OptimizeMultikey> optimize_multikey_tag)
844 std::size_t num_erased(0);
845 siterator last_step_before_it;
846 if(first_bucket != last_bucket){
847 bucket_type *b = (&this->priv_bucket_pointer()[0]);
848 num_erased += this->priv_erase_from_single_bucket
849 (b[first_bucket], before_first_it, b[first_bucket].end(), node_disposer, optimize_multikey_tag);
850 for(std::size_t i = 0, n = (last_bucket - first_bucket - 1); i != n; ++i){
851 num_erased += this->priv_erase_whole_bucket(b[first_bucket+i+1], node_disposer);
853 last_step_before_it = b[last_bucket].before_begin();
856 last_step_before_it = before_first_it;
858 num_erased += this->priv_erase_from_single_bucket
859 (this->priv_bucket_pointer()[last_bucket], last_step_before_it, last_it, node_disposer, optimize_multikey_tag);
863 static siterator priv_get_last(bucket_type &b, detail::true_) //optimize multikey
865 //First find the last node of p's group.
866 //This requires checking the first node of the next group or
868 slist_node_ptr end_ptr(b.end().pointed_node());
869 node_ptr possible_end(node_traits::get_next( detail::dcast_bucket_ptr<node>(end_ptr)));
870 node_ptr last_node_group(possible_end);
872 while(end_ptr != possible_end){
873 last_node_group = group_traits::get_next(detail::dcast_bucket_ptr<node>(possible_end));
874 possible_end = node_traits::get_next(last_node_group);
876 return bucket_type::s_iterator_to(*last_node_group);
879 template<class NodeDisposer>
880 std::size_t priv_erase_whole_bucket(bucket_type &b, NodeDisposer node_disposer)
882 std::size_t num_erased = 0;
883 siterator b_begin(b.before_begin());
884 siterator nxt(b_begin);
886 siterator const end_sit(b.end());
887 while(nxt != end_sit){
888 //No need to init group links as we'll delete all bucket nodes
889 nxt = bucket_type::s_erase_after_and_dispose(b_begin, node_disposer);
895 BOOST_INTRUSIVE_FORCEINLINE static siterator priv_get_last(bucket_type &b, detail::false_) //NOT optimize multikey
896 { return b.previous(b.end()); }
898 static siterator priv_get_previous(bucket_type &b, siterator i, detail::true_) //optimize multikey
900 node_ptr const elem(detail::dcast_bucket_ptr<node>(i.pointed_node()));
901 node_ptr const prev_in_group(group_traits::get_next(elem));
902 bool const first_in_group = node_traits::get_next(prev_in_group) != elem;
903 typename bucket_type::node &n = first_in_group
904 ? *group_functions_t::get_prev_to_first_in_group(b.end().pointed_node(), elem)
905 : *group_traits::get_next(elem)
907 return bucket_type::s_iterator_to(n);
910 BOOST_INTRUSIVE_FORCEINLINE static siterator priv_get_previous(bucket_type &b, siterator i, detail::false_) //NOT optimize multikey
911 { return b.previous(i); }
913 std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::true_) //optimize multikey
915 const bucket_ptr f(this->priv_bucket_pointer()), l(f + this->priv_bucket_count() - 1);
916 slist_node_ptr bb = group_functions_t::get_bucket_before_begin
917 ( f->end().pointed_node()
918 , l->end().pointed_node()
919 , detail::dcast_bucket_ptr<node>(it.pointed_node()));
920 //Now get the bucket_impl from the iterator
921 const bucket_type &b = static_cast<const bucket_type&>
922 (bucket_type::slist_type::container_from_end_iterator(bucket_type::s_iterator_to(*bb)));
923 //Now just calculate the index b has in the bucket array
924 return static_cast<std::size_t>(&b - &*f);
927 std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::false_) //NO optimize multikey
929 bucket_ptr f(this->priv_bucket_pointer()), l(f + this->priv_bucket_count() - 1);
930 slist_node_ptr first_ptr(f->cend().pointed_node())
931 , last_ptr(l->cend().pointed_node());
933 //The end node is embedded in the singly linked list:
934 //iterate until we reach it.
935 while(!(first_ptr <= it.pointed_node() && it.pointed_node() <= last_ptr)){
938 //Now get the bucket_impl from the iterator
939 const bucket_type &b = static_cast<const bucket_type&>
940 (bucket_type::container_from_end_iterator(it));
942 //Now just calculate the index b has in the bucket array
943 return static_cast<std::size_t>(&b - &*f);
946 BOOST_INTRUSIVE_FORCEINLINE static std::size_t priv_stored_hash(slist_node_ptr n, detail::true_) //store_hash
947 { return node_traits::get_hash(detail::dcast_bucket_ptr<node>(n)); }
949 BOOST_INTRUSIVE_FORCEINLINE static std::size_t priv_stored_hash(slist_node_ptr, detail::false_) //NO store_hash
950 { return std::size_t(-1); }
952 BOOST_INTRUSIVE_FORCEINLINE node &priv_value_to_node(reference v)
953 { return *this->priv_value_traits().to_node_ptr(v); }
955 BOOST_INTRUSIVE_FORCEINLINE const node &priv_value_to_node(const_reference v) const
956 { return *this->priv_value_traits().to_node_ptr(v); }
958 BOOST_INTRUSIVE_FORCEINLINE reference priv_value_from_slist_node(slist_node_ptr n)
959 { return *this->priv_value_traits().to_value_ptr(detail::dcast_bucket_ptr<node>(n)); }
961 BOOST_INTRUSIVE_FORCEINLINE const_reference priv_value_from_slist_node(slist_node_ptr n) const
962 { return *this->priv_value_traits().to_value_ptr(detail::dcast_bucket_ptr<node>(n)); }
964 void priv_clear_buckets(const bucket_ptr buckets_ptr, const std::size_t bucket_cnt)
966 bucket_ptr buckets_it = buckets_ptr;
967 for(std::size_t bucket_i = 0; bucket_i != bucket_cnt; ++buckets_it, ++bucket_i){
968 if(safemode_or_autounlink){
969 buckets_it->clear_and_dispose(detail::init_disposer<node_algorithms>());
977 BOOST_INTRUSIVE_FORCEINLINE std::size_t priv_stored_or_compute_hash(const value_type &v, detail::true_) const //For store_hash == true
978 { return node_traits::get_hash(this->priv_value_traits().to_node_ptr(v)); }
980 typedef hashtable_iterator<bucket_plus_vtraits, false> iterator;
981 typedef hashtable_iterator<bucket_plus_vtraits, true> const_iterator;
983 BOOST_INTRUSIVE_FORCEINLINE iterator end()
984 { return iterator(this->priv_invalid_local_it(), 0); }
986 BOOST_INTRUSIVE_FORCEINLINE const_iterator end() const
987 { return this->cend(); }
989 BOOST_INTRUSIVE_FORCEINLINE const_iterator cend() const
990 { return const_iterator(this->priv_invalid_local_it(), 0); }
993 struct data_type : public ValueTraits
995 template<class BucketTraitsType>
996 BOOST_INTRUSIVE_FORCEINLINE data_type(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits)
997 : ValueTraits(val_traits), bucket_traits_(::boost::forward<BucketTraitsType>(b_traits))
1000 bucket_traits bucket_traits_;
1004 template<class Hash, class>
1011 struct get_hash<void, T>
1013 typedef ::boost::hash<T> type;
1016 template<class EqualTo, class>
1019 typedef EqualTo type;
1023 struct get_equal_to<void, T>
1025 typedef std::equal_to<T> type;
1028 template<class KeyOfValue, class T>
1029 struct get_hash_key_of_value
1031 typedef KeyOfValue type;
1035 struct get_hash_key_of_value<void, T>
1037 typedef ::boost::intrusive::detail::identity<T> type;
1040 template<class T, class VoidOrKeyOfValue>
1041 struct hash_key_types_base
1043 typedef typename get_hash_key_of_value
1044 < VoidOrKeyOfValue, T>::type key_of_value;
1045 typedef typename key_of_value::type key_type;
1048 template<class T, class VoidOrKeyOfValue, class VoidOrKeyHash>
1049 struct hash_key_hash
1052 , typename hash_key_types_base<T, VoidOrKeyOfValue>::key_type
1056 template<class T, class VoidOrKeyOfValue, class VoidOrKeyEqual>
1057 struct hash_key_equal
1060 , typename hash_key_types_base<T, VoidOrKeyOfValue>::key_type
1066 //Stores bucket_plus_vtraits plust the hash function
1067 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class BucketTraits>
1068 struct bucket_hash_t
1069 //Use public inheritance to avoid MSVC bugs with closures
1070 : public detail::ebo_functor_holder
1071 <typename hash_key_hash < typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits::value_type
1076 , bucket_plus_vtraits<ValueTraits, BucketTraits> //4
1078 typedef typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits value_traits;
1079 typedef typename value_traits::value_type value_type;
1080 typedef typename value_traits::node_traits node_traits;
1081 typedef hash_key_hash
1082 < value_type, VoidOrKeyOfValue, VoidOrKeyHash> hash_key_hash_t;
1083 typedef typename hash_key_hash_t::type hasher;
1084 typedef typename hash_key_types_base<value_type, VoidOrKeyOfValue>::key_of_value key_of_value;
1086 typedef BucketTraits bucket_traits;
1087 typedef bucket_plus_vtraits<ValueTraits, BucketTraits> bucket_plus_vtraits_t;
1088 typedef detail::ebo_functor_holder<hasher> base_t;
1090 template<class BucketTraitsType>
1091 BOOST_INTRUSIVE_FORCEINLINE bucket_hash_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h)
1092 : detail::ebo_functor_holder<hasher>(h), bucket_plus_vtraits_t(val_traits, ::boost::forward<BucketTraitsType>(b_traits))
1095 BOOST_INTRUSIVE_FORCEINLINE const hasher &priv_hasher() const
1096 { return this->base_t::get(); }
1098 hasher &priv_hasher()
1099 { return this->base_t::get(); }
1101 using bucket_plus_vtraits_t::priv_stored_or_compute_hash; //For store_hash == true
1103 BOOST_INTRUSIVE_FORCEINLINE std::size_t priv_stored_or_compute_hash(const value_type &v, detail::false_) const //For store_hash == false
1104 { return this->priv_hasher()(key_of_value()(v)); }
1107 template<class ValueTraits, class BucketTraits, class VoidOrKeyOfValue, class VoidOrKeyEqual>
1108 struct hashtable_equal_holder
1110 typedef detail::ebo_functor_holder
1111 < typename hash_key_equal < typename bucket_plus_vtraits<ValueTraits, BucketTraits>::value_traits::value_type
1119 //bucket_hash_equal_t
1120 //Stores bucket_hash_t and the equality function when the first
1121 //non-empty bucket shall not be cached.
1122 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class VoidOrKeyEqual, class BucketTraits, bool>
1123 struct bucket_hash_equal_t
1124 //Use public inheritance to avoid MSVC bugs with closures
1125 : public bucket_hash_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, BucketTraits> //3
1126 , public hashtable_equal_holder<ValueTraits, BucketTraits, VoidOrKeyOfValue, VoidOrKeyEqual>::type //equal
1128 typedef typename hashtable_equal_holder
1129 <ValueTraits, BucketTraits, VoidOrKeyOfValue, VoidOrKeyEqual>::type equal_holder_t;
1130 typedef bucket_hash_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, BucketTraits> bucket_hash_type;
1131 typedef bucket_plus_vtraits<ValueTraits,BucketTraits> bucket_plus_vtraits_t;
1132 typedef ValueTraits value_traits;
1133 typedef typename equal_holder_t::functor_type key_equal;
1134 typedef typename bucket_hash_type::hasher hasher;
1135 typedef BucketTraits bucket_traits;
1136 typedef typename bucket_plus_vtraits_t::slist_impl slist_impl;
1137 typedef typename slist_impl::iterator siterator;
1138 typedef bucket_impl<slist_impl> bucket_type;
1139 typedef typename detail::unordered_bucket_ptr_impl<value_traits>::type bucket_ptr;
1141 template<class BucketTraitsType>
1142 bucket_hash_equal_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h, const key_equal &e)
1143 : bucket_hash_type(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h)
1147 BOOST_INTRUSIVE_FORCEINLINE bucket_ptr priv_get_cache()
1148 { return this->bucket_hash_type::priv_bucket_pointer(); }
1150 BOOST_INTRUSIVE_FORCEINLINE void priv_set_cache(const bucket_ptr &)
1153 BOOST_INTRUSIVE_FORCEINLINE std::size_t priv_get_cache_bucket_num()
1156 BOOST_INTRUSIVE_FORCEINLINE void priv_initialize_cache()
1159 BOOST_INTRUSIVE_FORCEINLINE void priv_swap_cache(bucket_hash_equal_t &)
1162 siterator priv_begin() const
1165 std::size_t bucket_cnt = this->bucket_hash_type::priv_bucket_count();
1166 for (n = 0; n < bucket_cnt; ++n){
1167 bucket_type &b = this->bucket_hash_type::priv_bucket_pointer()[n];
1172 return this->bucket_hash_type::priv_invalid_local_it();
1175 BOOST_INTRUSIVE_FORCEINLINE void priv_insertion_update_cache(std::size_t)
1178 BOOST_INTRUSIVE_FORCEINLINE void priv_erasure_update_cache_range(std::size_t, std::size_t)
1181 BOOST_INTRUSIVE_FORCEINLINE void priv_erasure_update_cache()
1184 BOOST_INTRUSIVE_FORCEINLINE const key_equal &priv_equal() const
1185 { return this->equal_holder_t::get(); }
1187 BOOST_INTRUSIVE_FORCEINLINE key_equal &priv_equal()
1188 { return this->equal_holder_t::get(); }
1191 //bucket_hash_equal_t
1192 //Stores bucket_hash_t and the equality function when the first
1193 //non-empty bucket shall be cached.
1194 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class VoidOrKeyEqual, class BucketTraits> //cache_begin == true version
1195 struct bucket_hash_equal_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual, BucketTraits, true>
1196 //Use public inheritance to avoid MSVC bugs with closures
1197 : bucket_hash_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, BucketTraits> //2
1198 , hashtable_equal_holder<ValueTraits, BucketTraits, VoidOrKeyOfValue, VoidOrKeyEqual>::type
1200 typedef typename hashtable_equal_holder
1201 <ValueTraits, BucketTraits, VoidOrKeyOfValue, VoidOrKeyEqual>::type equal_holder_t;
1203 typedef bucket_plus_vtraits<ValueTraits,BucketTraits> bucket_plus_vtraits_t;
1204 typedef ValueTraits value_traits;
1205 typedef typename equal_holder_t::functor_type key_equal;
1206 typedef bucket_hash_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, BucketTraits> bucket_hash_type;
1207 typedef typename bucket_hash_type::hasher hasher;
1208 typedef BucketTraits bucket_traits;
1209 typedef typename bucket_plus_vtraits_t::slist_impl::iterator siterator;
1211 template<class BucketTraitsType>
1212 bucket_hash_equal_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h, const key_equal &e)
1213 : bucket_hash_type(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h)
1217 typedef typename detail::unordered_bucket_ptr_impl
1218 <typename bucket_hash_type::value_traits>::type bucket_ptr;
1220 BOOST_INTRUSIVE_FORCEINLINE bucket_ptr &priv_get_cache()
1221 { return cached_begin_; }
1223 BOOST_INTRUSIVE_FORCEINLINE const bucket_ptr &priv_get_cache() const
1224 { return cached_begin_; }
1226 BOOST_INTRUSIVE_FORCEINLINE void priv_set_cache(const bucket_ptr &p)
1227 { cached_begin_ = p; }
1229 BOOST_INTRUSIVE_FORCEINLINE std::size_t priv_get_cache_bucket_num()
1230 { return this->cached_begin_ - this->bucket_hash_type::priv_bucket_pointer(); }
1232 BOOST_INTRUSIVE_FORCEINLINE void priv_initialize_cache()
1233 { this->cached_begin_ = this->bucket_hash_type::priv_invalid_bucket(); }
1235 BOOST_INTRUSIVE_FORCEINLINE void priv_swap_cache(bucket_hash_equal_t &other)
1237 ::boost::adl_move_swap(this->cached_begin_, other.cached_begin_);
1240 siterator priv_begin() const
1242 if(this->cached_begin_ == this->bucket_hash_type::priv_invalid_bucket()){
1243 return this->bucket_hash_type::priv_invalid_local_it();
1246 return this->cached_begin_->begin();
1250 void priv_insertion_update_cache(std::size_t insertion_bucket)
1252 bucket_ptr p = this->bucket_hash_type::priv_bucket_pointer() + insertion_bucket;
1253 if(p < this->cached_begin_){
1254 this->cached_begin_ = p;
1258 BOOST_INTRUSIVE_FORCEINLINE const key_equal &priv_equal() const
1259 { return this->equal_holder_t::get(); }
1261 BOOST_INTRUSIVE_FORCEINLINE key_equal &priv_equal()
1262 { return this->equal_holder_t::get(); }
1264 void priv_erasure_update_cache_range(std::size_t first_bucket_num, std::size_t last_bucket_num)
1266 //If the last bucket is the end, the cache must be updated
1267 //to the last position if all
1268 if(this->priv_get_cache_bucket_num() == first_bucket_num &&
1269 this->bucket_hash_type::priv_bucket_pointer()[first_bucket_num].empty() ){
1270 this->priv_set_cache(this->bucket_hash_type::priv_bucket_pointer() + last_bucket_num);
1271 this->priv_erasure_update_cache();
1275 void priv_erasure_update_cache()
1277 if(this->cached_begin_ != this->bucket_hash_type::priv_invalid_bucket()){
1278 std::size_t current_n = this->priv_get_cache() - this->bucket_hash_type::priv_bucket_pointer();
1279 for( const std::size_t num_buckets = this->bucket_hash_type::priv_bucket_count()
1280 ; current_n < num_buckets
1281 ; ++current_n, ++this->priv_get_cache()){
1282 if(!this->priv_get_cache()->empty()){
1286 this->priv_initialize_cache();
1290 bucket_ptr cached_begin_;
1293 //This wrapper around size_traits is used
1294 //to maintain minimal container size with compilers like MSVC
1295 //that have problems with EBO and multiple empty base classes
1296 template<class DeriveFrom, class SizeType, bool>
1297 struct hashtable_size_traits_wrapper
1300 template<class Base, class Arg0, class Arg1, class Arg2>
1301 hashtable_size_traits_wrapper( BOOST_FWD_REF(Base) base, BOOST_FWD_REF(Arg0) arg0
1302 , BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2)
1303 : DeriveFrom(::boost::forward<Base>(base)
1304 , ::boost::forward<Arg0>(arg0)
1305 , ::boost::forward<Arg1>(arg1)
1306 , ::boost::forward<Arg2>(arg2))
1308 typedef detail::size_holder < true, SizeType> size_traits;//size_traits
1310 size_traits size_traits_;
1312 typedef const size_traits & size_traits_const_t;
1313 typedef size_traits & size_traits_t;
1315 BOOST_INTRUSIVE_FORCEINLINE size_traits_const_t priv_size_traits() const
1316 { return size_traits_; }
1318 BOOST_INTRUSIVE_FORCEINLINE size_traits_t priv_size_traits()
1319 { return size_traits_; }
1322 template<class DeriveFrom, class SizeType>
1323 struct hashtable_size_traits_wrapper<DeriveFrom, SizeType, false>
1326 template<class Base, class Arg0, class Arg1, class Arg2>
1327 hashtable_size_traits_wrapper( BOOST_FWD_REF(Base) base, BOOST_FWD_REF(Arg0) arg0
1328 , BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2)
1329 : DeriveFrom(::boost::forward<Base>(base)
1330 , ::boost::forward<Arg0>(arg0)
1331 , ::boost::forward<Arg1>(arg1)
1332 , ::boost::forward<Arg2>(arg2))
1335 typedef detail::size_holder< false, SizeType> size_traits;
1337 typedef size_traits size_traits_const_t;
1338 typedef size_traits size_traits_t;
1340 BOOST_INTRUSIVE_FORCEINLINE size_traits priv_size_traits() const
1341 { return size_traits(); }
1345 //Stores bucket_hash_equal_t and split_traits
1346 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class VoidOrKeyEqual, class BucketTraits, class SizeType, std::size_t BoolFlags>
1347 struct hashdata_internal
1348 : public hashtable_size_traits_wrapper
1349 < bucket_hash_equal_t
1350 < ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual
1352 , 0 != (BoolFlags & hash_bool_flags::cache_begin_pos)
1355 , (BoolFlags & hash_bool_flags::incremental_pos) != 0
1358 typedef hashtable_size_traits_wrapper
1359 < bucket_hash_equal_t
1360 < ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual
1362 , 0 != (BoolFlags & hash_bool_flags::cache_begin_pos)
1365 , (BoolFlags & hash_bool_flags::incremental_pos) != 0
1367 typedef typename internal_type::key_equal key_equal;
1368 typedef typename internal_type::hasher hasher;
1369 typedef bucket_plus_vtraits<ValueTraits,BucketTraits> bucket_plus_vtraits_t;
1370 typedef SizeType size_type;
1371 typedef typename internal_type::size_traits split_traits;
1372 typedef typename bucket_plus_vtraits_t::bucket_ptr bucket_ptr;
1373 typedef typename bucket_plus_vtraits_t::const_value_traits_ptr const_value_traits_ptr;
1374 typedef typename bucket_plus_vtraits_t::siterator siterator;
1375 typedef typename bucket_plus_vtraits_t::bucket_traits bucket_traits;
1376 typedef typename bucket_plus_vtraits_t::value_traits value_traits;
1377 typedef typename bucket_plus_vtraits_t::bucket_type bucket_type;
1378 typedef typename value_traits::value_type value_type;
1379 typedef typename value_traits::pointer pointer;
1380 typedef typename value_traits::const_pointer const_pointer;
1381 typedef typename pointer_traits<pointer>::reference reference;
1382 typedef typename pointer_traits
1383 <const_pointer>::reference const_reference;
1384 typedef typename value_traits::node_traits node_traits;
1385 typedef typename node_traits::node node;
1386 typedef typename node_traits::node_ptr node_ptr;
1387 typedef typename node_traits::const_node_ptr const_node_ptr;
1388 typedef detail::node_functions<node_traits> node_functions_t;
1389 typedef typename get_slist_impl
1390 <typename reduced_slist_node_traits
1391 <typename value_traits::node_traits>::type
1393 typedef typename slist_impl::node_algorithms node_algorithms;
1394 typedef typename slist_impl::node_ptr slist_node_ptr;
1396 typedef hash_key_types_base
1397 < typename ValueTraits::value_type
1400 typedef typename hash_types_base::key_of_value key_of_value;
1402 static const bool store_hash = detail::store_hash_is_true<node_traits>::value;
1403 static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
1404 static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value;
1406 typedef detail::bool_<store_hash> store_hash_t;
1408 typedef detail::transform_iterator
1409 < typename slist_impl::iterator
1410 , downcast_node_to_value_t
1412 , false> > local_iterator;
1414 typedef detail::transform_iterator
1415 < typename slist_impl::iterator
1416 , downcast_node_to_value_t
1418 , true> > const_local_iterator;
1421 template<class BucketTraitsType>
1422 hashdata_internal( const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits
1423 , const hasher & h, const key_equal &e)
1424 : internal_type(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h, e)
1427 BOOST_INTRUSIVE_FORCEINLINE typename internal_type::size_traits_t priv_split_traits()
1428 { return this->priv_size_traits(); }
1430 BOOST_INTRUSIVE_FORCEINLINE typename internal_type::size_traits_const_t priv_split_traits() const
1431 { return this->priv_size_traits(); }
1433 ~hashdata_internal()
1434 { this->priv_clear_buckets(); }
1436 void priv_clear_buckets()
1438 this->internal_type::priv_clear_buckets
1439 ( this->priv_get_cache()
1440 , this->internal_type::priv_bucket_count()
1441 - (this->priv_get_cache()
1442 - this->internal_type::priv_bucket_pointer()));
1445 void priv_clear_buckets_and_cache()
1447 this->priv_clear_buckets();
1448 this->priv_initialize_cache();
1451 void priv_initialize_buckets_and_cache()
1453 this->internal_type::priv_clear_buckets
1454 ( this->internal_type::priv_bucket_pointer()
1455 , this->internal_type::priv_bucket_count());
1456 this->priv_initialize_cache();
1459 typedef hashtable_iterator<bucket_plus_vtraits_t, false> iterator;
1460 typedef hashtable_iterator<bucket_plus_vtraits_t, true> const_iterator;
1462 static std::size_t priv_stored_hash(slist_node_ptr n, detail::true_ true_value)
1463 { return bucket_plus_vtraits<ValueTraits, BucketTraits>::priv_stored_hash(n, true_value); }
1465 static std::size_t priv_stored_hash(slist_node_ptr n, detail::false_ false_value)
1466 { return bucket_plus_vtraits<ValueTraits, BucketTraits>::priv_stored_hash(n, false_value); }
1469 BOOST_INTRUSIVE_FORCEINLINE SizeType split_count() const
1471 return this->priv_split_traits().get_size();
1474 BOOST_INTRUSIVE_FORCEINLINE iterator iterator_to(reference value)
1476 return iterator(bucket_type::s_iterator_to
1477 (this->priv_value_to_node(value)), &this->get_bucket_value_traits());
1480 const_iterator iterator_to(const_reference value) const
1482 siterator const sit = bucket_type::s_iterator_to
1483 ( *pointer_traits<node_ptr>::const_cast_from
1484 (pointer_traits<const_node_ptr>::pointer_to(this->priv_value_to_node(value)))
1486 return const_iterator(sit, &this->get_bucket_value_traits());
1489 static local_iterator s_local_iterator_to(reference value)
1491 BOOST_STATIC_ASSERT((!stateful_value_traits));
1492 siterator sit = bucket_type::s_iterator_to(*value_traits::to_node_ptr(value));
1493 return local_iterator(sit, const_value_traits_ptr());
1496 static const_local_iterator s_local_iterator_to(const_reference value)
1498 BOOST_STATIC_ASSERT((!stateful_value_traits));
1499 siterator const sit = bucket_type::s_iterator_to
1500 ( *pointer_traits<node_ptr>::const_cast_from
1501 (value_traits::to_node_ptr(value))
1503 return const_local_iterator(sit, const_value_traits_ptr());
1506 local_iterator local_iterator_to(reference value)
1508 siterator sit = bucket_type::s_iterator_to(this->priv_value_to_node(value));
1509 return local_iterator(sit, this->priv_value_traits_ptr());
1512 const_local_iterator local_iterator_to(const_reference value) const
1514 siterator sit = bucket_type::s_iterator_to
1515 ( *pointer_traits<node_ptr>::const_cast_from
1516 (pointer_traits<const_node_ptr>::pointer_to(this->priv_value_to_node(value)))
1518 return const_local_iterator(sit, this->priv_value_traits_ptr());
1521 BOOST_INTRUSIVE_FORCEINLINE size_type bucket_count() const
1523 const std::size_t bc = this->priv_bucket_count();
1524 BOOST_INTRUSIVE_INVARIANT_ASSERT(sizeof(size_type) >= sizeof(std::size_t) || bc <= size_type(-1));
1525 return static_cast<size_type>(bc);
1528 BOOST_INTRUSIVE_FORCEINLINE size_type bucket_size(size_type n) const
1529 { return this->priv_bucket_pointer()[n].size(); }
1531 BOOST_INTRUSIVE_FORCEINLINE bucket_ptr bucket_pointer() const
1532 { return this->priv_bucket_pointer(); }
1534 BOOST_INTRUSIVE_FORCEINLINE local_iterator begin(size_type n)
1535 { return local_iterator(this->priv_bucket_pointer()[n].begin(), this->priv_value_traits_ptr()); }
1537 BOOST_INTRUSIVE_FORCEINLINE const_local_iterator begin(size_type n) const
1538 { return this->cbegin(n); }
1540 static BOOST_INTRUSIVE_FORCEINLINE size_type suggested_upper_bucket_count(size_type n)
1542 return prime_list_holder<0>::suggested_upper_bucket_count(n);
1545 static BOOST_INTRUSIVE_FORCEINLINE size_type suggested_lower_bucket_count(size_type n)
1547 return prime_list_holder<0>::suggested_lower_bucket_count(n);
1550 const_local_iterator cbegin(size_type n) const
1552 return const_local_iterator
1553 ( pointer_traits<bucket_ptr>::const_cast_from(this->priv_bucket_pointer())[n].begin()
1554 , this->priv_value_traits_ptr());
1557 using internal_type::end;
1558 using internal_type::cend;
1560 local_iterator end(size_type n)
1561 { return local_iterator(this->priv_bucket_pointer()[n].end(), this->priv_value_traits_ptr()); }
1563 BOOST_INTRUSIVE_FORCEINLINE const_local_iterator end(size_type n) const
1564 { return this->cend(n); }
1566 const_local_iterator cend(size_type n) const
1568 return const_local_iterator
1569 ( pointer_traits<bucket_ptr>::const_cast_from(this->priv_bucket_pointer())[n].end()
1570 , this->priv_value_traits_ptr());
1573 //Public functions for hashtable_impl
1575 BOOST_INTRUSIVE_FORCEINLINE iterator begin()
1576 { return iterator(this->priv_begin(), &this->get_bucket_value_traits()); }
1578 BOOST_INTRUSIVE_FORCEINLINE const_iterator begin() const
1579 { return this->cbegin(); }
1581 BOOST_INTRUSIVE_FORCEINLINE const_iterator cbegin() const
1582 { return const_iterator(this->priv_begin(), &this->get_bucket_value_traits()); }
1584 BOOST_INTRUSIVE_FORCEINLINE hasher hash_function() const
1585 { return this->priv_hasher(); }
1587 BOOST_INTRUSIVE_FORCEINLINE key_equal key_eq() const
1588 { return this->priv_equal(); }
1593 //! The class template hashtable is an intrusive hash table container, that
1594 //! is used to construct intrusive unordered_set and unordered_multiset containers. The
1595 //! no-throw guarantee holds only, if the VoidOrKeyEqual object and Hasher don't throw.
1597 //! hashtable is a semi-intrusive container: each object to be stored in the
1598 //! container must contain a proper hook, but the container also needs
1599 //! additional auxiliary memory to work: hashtable needs a pointer to an array
1600 //! of type `bucket_type` to be passed in the constructor. This bucket array must
1601 //! have at least the same lifetime as the container. This makes the use of
1602 //! hashtable more complicated than purely intrusive containers.
1603 //! `bucket_type` is default-constructible, copyable and assignable
1605 //! The template parameter \c T is the type to be managed by the container.
1606 //! The user can specify additional options and if no options are provided
1607 //! default options are used.
1609 //! The container supports the following options:
1610 //! \c base_hook<>/member_hook<>/value_traits<>,
1611 //! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<>
1612 //! \c bucket_traits<>, power_2_buckets<>, cache_begin<> and incremental<>.
1614 //! hashtable only provides forward iterators but it provides 4 iterator types:
1615 //! iterator and const_iterator to navigate through the whole container and
1616 //! local_iterator and const_local_iterator to navigate through the values
1617 //! stored in a single bucket. Local iterators are faster and smaller.
1619 //! It's not recommended to use non constant-time size hashtables because several
1620 //! key functions, like "empty()", become non-constant time functions. Non
1621 //! constant_time size hashtables are mainly provided to support auto-unlink hooks.
1623 //! hashtables, does not make automatic rehashings nor
1624 //! offers functions related to a load factor. Rehashing can be explicitly requested
1625 //! and the user must provide a new bucket array that will be used from that moment.
1627 //! Since no automatic rehashing is done, iterators are never invalidated when
1628 //! inserting or erasing elements. Iterators are only invalidated when rehashing.
1629 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1630 template<class T, class ...Options>
1632 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class VoidOrKeyEqual, class BucketTraits, class SizeType, std::size_t BoolFlags>
1634 class hashtable_impl
1635 : private hashtable_size_traits_wrapper
1638 , VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual
1639 , BucketTraits, SizeType
1640 , BoolFlags & (hash_bool_flags::incremental_pos | hash_bool_flags::cache_begin_pos) //1
1643 , (BoolFlags & hash_bool_flags::constant_time_size_pos) != 0
1646 typedef hashtable_size_traits_wrapper
1649 , VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual
1650 , BucketTraits, SizeType
1651 , BoolFlags & (hash_bool_flags::incremental_pos | hash_bool_flags::cache_begin_pos) //1
1654 , (BoolFlags & hash_bool_flags::constant_time_size_pos) != 0
1656 typedef typename internal_type::size_traits size_traits;
1657 typedef hash_key_types_base
1658 < typename ValueTraits::value_type
1662 typedef ValueTraits value_traits;
1665 typedef BucketTraits bucket_traits;
1667 typedef typename internal_type::slist_impl slist_impl;
1668 typedef bucket_plus_vtraits<ValueTraits, BucketTraits> bucket_plus_vtraits_t;
1669 typedef typename bucket_plus_vtraits_t::const_value_traits_ptr const_value_traits_ptr;
1671 using internal_type::begin;
1672 using internal_type::cbegin;
1673 using internal_type::end;
1674 using internal_type::cend;
1675 using internal_type::hash_function;
1676 using internal_type::key_eq;
1677 using internal_type::bucket_size;
1678 using internal_type::bucket_count;
1679 using internal_type::local_iterator_to;
1680 using internal_type::s_local_iterator_to;
1681 using internal_type::iterator_to;
1682 using internal_type::bucket_pointer;
1683 using internal_type::suggested_upper_bucket_count;
1684 using internal_type::suggested_lower_bucket_count;
1685 using internal_type::split_count;
1689 typedef typename value_traits::pointer pointer;
1690 typedef typename value_traits::const_pointer const_pointer;
1691 typedef typename value_traits::value_type value_type;
1692 typedef typename hash_types_base::key_type key_type;
1693 typedef typename hash_types_base::key_of_value key_of_value;
1694 typedef typename pointer_traits<pointer>::reference reference;
1695 typedef typename pointer_traits<const_pointer>::reference const_reference;
1696 typedef typename pointer_traits<pointer>::difference_type difference_type;
1697 typedef SizeType size_type;
1698 typedef typename internal_type::key_equal key_equal;
1699 typedef typename internal_type::hasher hasher;
1700 typedef bucket_impl<slist_impl> bucket_type;
1701 typedef typename internal_type::bucket_ptr bucket_ptr;
1702 typedef typename slist_impl::iterator siterator;
1703 typedef typename slist_impl::const_iterator const_siterator;
1704 typedef typename internal_type::iterator iterator;
1705 typedef typename internal_type::const_iterator const_iterator;
1706 typedef typename internal_type::local_iterator local_iterator;
1707 typedef typename internal_type::const_local_iterator const_local_iterator;
1708 typedef typename value_traits::node_traits node_traits;
1709 typedef typename node_traits::node node;
1710 typedef typename pointer_traits
1711 <pointer>::template rebind_pointer
1712 < node >::type node_ptr;
1713 typedef typename pointer_traits
1714 <pointer>::template rebind_pointer
1715 < const node >::type const_node_ptr;
1716 typedef typename pointer_traits
1717 <node_ptr>::reference node_reference;
1718 typedef typename pointer_traits
1719 <const_node_ptr>::reference const_node_reference;
1720 typedef typename slist_impl::node_algorithms node_algorithms;
1722 static const bool stateful_value_traits = internal_type::stateful_value_traits;
1723 static const bool store_hash = internal_type::store_hash;
1725 static const bool unique_keys = 0 != (BoolFlags & hash_bool_flags::unique_keys_pos);
1726 static const bool constant_time_size = 0 != (BoolFlags & hash_bool_flags::constant_time_size_pos);
1727 static const bool cache_begin = 0 != (BoolFlags & hash_bool_flags::cache_begin_pos);
1728 static const bool compare_hash = 0 != (BoolFlags & hash_bool_flags::compare_hash_pos);
1729 static const bool incremental = 0 != (BoolFlags & hash_bool_flags::incremental_pos);
1730 static const bool power_2_buckets = incremental || (0 != (BoolFlags & hash_bool_flags::power_2_buckets_pos));
1732 static const bool optimize_multikey
1733 = detail::optimize_multikey_is_true<node_traits>::value && !unique_keys;
1736 static const bool is_multikey = !unique_keys;
1739 //Configuration error: compare_hash<> can't be specified without store_hash<>
1740 //See documentation for more explanations
1741 BOOST_STATIC_ASSERT((!compare_hash || store_hash));
1743 typedef typename slist_impl::node_ptr slist_node_ptr;
1744 typedef typename pointer_traits
1745 <slist_node_ptr>::template rebind_pointer
1746 < void >::type void_pointer;
1747 //We'll define group traits, but these won't be instantiated if
1748 //optimize_multikey is not true
1749 typedef unordered_group_adapter<node_traits> group_traits;
1750 typedef circular_slist_algorithms<group_traits> group_algorithms;
1751 typedef typename internal_type::store_hash_t store_hash_t;
1752 typedef detail::bool_<optimize_multikey> optimize_multikey_t;
1753 typedef detail::bool_<cache_begin> cache_begin_t;
1754 typedef detail::bool_<power_2_buckets> power_2_buckets_t;
1755 typedef typename internal_type::split_traits split_traits;
1756 typedef detail::group_functions<node_traits> group_functions_t;
1757 typedef detail::node_functions<node_traits> node_functions_t;
1760 //noncopyable, movable
1761 BOOST_MOVABLE_BUT_NOT_COPYABLE(hashtable_impl)
1763 static const bool safemode_or_autounlink = internal_type::safemode_or_autounlink;
1765 //Constant-time size is incompatible with auto-unlink hooks!
1766 BOOST_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink)));
1767 //Cache begin is incompatible with auto-unlink hooks!
1768 BOOST_STATIC_ASSERT(!(cache_begin && ((int)value_traits::link_mode == (int)auto_unlink)));
1770 template<class Disposer>
1771 struct typeof_node_disposer
1773 typedef node_cast_adaptor
1774 < detail::node_disposer< Disposer, value_traits, CircularSListAlgorithms>
1775 , slist_node_ptr, node_ptr > type;
1778 template<class Disposer>
1779 typename typeof_node_disposer<Disposer>::type
1780 make_node_disposer(const Disposer &disposer) const
1782 typedef typename typeof_node_disposer<Disposer>::type return_t;
1783 return return_t(disposer, &this->priv_value_traits());
1789 typedef detail::insert_commit_data_impl insert_commit_data;
1794 //! <b>Requires</b>: buckets must not be being used by any other resource.
1796 //! <b>Effects</b>: Constructs an empty unordered_set, storing a reference
1797 //! to the bucket array and copies of the key_hasher and equal_func functors.
1799 //! <b>Complexity</b>: Constant.
1801 //! <b>Throws</b>: If value_traits::node_traits::node
1802 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1803 //! or the copy constructor or invocation of hash_func or equal_func throws.
1805 //! <b>Notes</b>: buckets array must be disposed only after
1806 //! *this is disposed.
1807 explicit hashtable_impl ( const bucket_traits &b_traits
1808 , const hasher & hash_func = hasher()
1809 , const key_equal &equal_func = key_equal()
1810 , const value_traits &v_traits = value_traits())
1811 : internal_type(v_traits, b_traits, hash_func, equal_func)
1813 this->priv_initialize_buckets_and_cache();
1814 this->priv_size_traits().set_size(size_type(0));
1815 size_type bucket_sz = this->bucket_count();
1816 BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_sz != 0);
1817 //Check power of two bucket array if the option is activated
1818 BOOST_INTRUSIVE_INVARIANT_ASSERT
1819 (!power_2_buckets || (0 == (bucket_sz & (bucket_sz-1))));
1820 this->priv_split_traits().set_size(bucket_sz>>1);
1823 //! <b>Requires</b>: buckets must not be being used by any other resource
1824 //! and dereferencing iterator must yield an lvalue of type value_type.
1826 //! <b>Effects</b>: Constructs an empty container and inserts elements from
1829 //! <b>Complexity</b>: If N is distance(b, e): Average case is O(N)
1830 //! (with a good hash function and with buckets_len >= N),worst case O(N^2).
1832 //! <b>Throws</b>: If value_traits::node_traits::node
1833 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1834 //! or the copy constructor or invocation of hasher or key_equal throws.
1836 //! <b>Notes</b>: buckets array must be disposed only after
1837 //! *this is disposed.
1838 template<class Iterator>
1839 hashtable_impl ( bool unique, Iterator b, Iterator e
1840 , const bucket_traits &b_traits
1841 , const hasher & hash_func = hasher()
1842 , const key_equal &equal_func = key_equal()
1843 , const value_traits &v_traits = value_traits())
1844 : internal_type(v_traits, b_traits, hash_func, equal_func)
1846 this->priv_initialize_buckets_and_cache();
1847 this->priv_size_traits().set_size(size_type(0));
1848 size_type bucket_sz = this->bucket_count();
1849 BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_sz != 0);
1850 //Check power of two bucket array if the option is activated
1851 BOOST_INTRUSIVE_INVARIANT_ASSERT
1852 (!power_2_buckets || (0 == (bucket_sz & (bucket_sz-1))));
1853 this->priv_split_traits().set_size(bucket_sz>>1);
1856 this->insert_unique(b, e);
1858 this->insert_equal(b, e);
1861 //! <b>Effects</b>: Constructs a container moving resources from another container.
1862 //! Internal value traits, bucket traits, hasher and comparison are move constructed and
1863 //! nodes belonging to x are linked to *this.
1865 //! <b>Complexity</b>: Constant.
1867 //! <b>Throws</b>: If value_traits::node_traits::node's
1868 //! move constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1869 //! or the move constructor of value traits, bucket traits, hasher or comparison throws.
1870 hashtable_impl(BOOST_RV_REF(hashtable_impl) x)
1871 : internal_type( ::boost::move(x.priv_value_traits())
1872 , ::boost::move(x.priv_bucket_traits())
1873 , ::boost::move(x.priv_hasher())
1874 , ::boost::move(x.priv_equal())
1877 this->priv_swap_cache(x);
1878 x.priv_initialize_cache();
1879 this->priv_size_traits().set_size(x.priv_size_traits().get_size());
1880 x.priv_size_traits().set_size(size_type(0));
1881 this->priv_split_traits().set_size(x.priv_split_traits().get_size());
1882 x.priv_split_traits().set_size(size_type(0));
1885 //! <b>Effects</b>: Equivalent to swap.
1887 hashtable_impl& operator=(BOOST_RV_REF(hashtable_impl) x)
1888 { this->swap(x); return *this; }
1890 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1891 //! <b>Effects</b>: Detaches all elements from this. The objects in the unordered_set
1892 //! are not deleted (i.e. no destructors are called).
1894 //! <b>Complexity</b>: Linear to the number of elements in the unordered_set, if
1895 //! it's a safe-mode or auto-unlink value. Otherwise constant.
1897 //! <b>Throws</b>: Nothing.
1900 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the unordered_set.
1902 //! <b>Complexity</b>: Amortized constant time.
1903 //! Worst case (empty unordered_set): O(this->bucket_count())
1905 //! <b>Throws</b>: Nothing.
1908 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
1909 //! of the unordered_set.
1911 //! <b>Complexity</b>: Amortized constant time.
1912 //! Worst case (empty unordered_set): O(this->bucket_count())
1914 //! <b>Throws</b>: Nothing.
1915 const_iterator begin() const;
1917 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
1918 //! of the unordered_set.
1920 //! <b>Complexity</b>: Amortized constant time.
1921 //! Worst case (empty unordered_set): O(this->bucket_count())
1923 //! <b>Throws</b>: Nothing.
1924 const_iterator cbegin() const;
1926 //! <b>Effects</b>: Returns an iterator pointing to the end of the unordered_set.
1928 //! <b>Complexity</b>: Constant.
1930 //! <b>Throws</b>: Nothing.
1933 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set.
1935 //! <b>Complexity</b>: Constant.
1937 //! <b>Throws</b>: Nothing.
1938 const_iterator end() const;
1940 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set.
1942 //! <b>Complexity</b>: Constant.
1944 //! <b>Throws</b>: Nothing.
1945 const_iterator cend() const;
1947 //! <b>Effects</b>: Returns the hasher object used by the unordered_set.
1949 //! <b>Complexity</b>: Constant.
1951 //! <b>Throws</b>: If hasher copy-constructor throws.
1952 hasher hash_function() const;
1954 //! <b>Effects</b>: Returns the key_equal object used by the unordered_set.
1956 //! <b>Complexity</b>: Constant.
1958 //! <b>Throws</b>: If key_equal copy-constructor throws.
1959 key_equal key_eq() const;
1963 //! <b>Effects</b>: Returns true if the container is empty.
1965 //! <b>Complexity</b>: if constant-time size and cache_begin options are disabled,
1966 //! average constant time (worst case, with empty() == true: O(this->bucket_count()).
1967 //! Otherwise constant.
1969 //! <b>Throws</b>: Nothing.
1972 if(constant_time_size){
1973 return !this->size();
1975 else if(cache_begin){
1976 return this->begin() == this->end();
1979 size_type bucket_cnt = this->bucket_count();
1980 const bucket_type *b = boost::movelib::to_raw_pointer(this->priv_bucket_pointer());
1981 for (size_type n = 0; n < bucket_cnt; ++n, ++b){
1990 //! <b>Effects</b>: Returns the number of elements stored in the unordered_set.
1992 //! <b>Complexity</b>: Linear to elements contained in *this if
1993 //! constant_time_size is false. Constant-time otherwise.
1995 //! <b>Throws</b>: Nothing.
1996 size_type size() const
1998 if(constant_time_size)
1999 return this->priv_size_traits().get_size();
2002 size_type bucket_cnt = this->bucket_count();
2003 const bucket_type *b = boost::movelib::to_raw_pointer(this->priv_bucket_pointer());
2004 for (size_type n = 0; n < bucket_cnt; ++n, ++b){
2011 //! <b>Requires</b>: the hasher and the equality function unqualified swap
2012 //! call should not throw.
2014 //! <b>Effects</b>: Swaps the contents of two unordered_sets.
2015 //! Swaps also the contained bucket array and equality and hasher functors.
2017 //! <b>Complexity</b>: Constant.
2019 //! <b>Throws</b>: If the swap() call for the comparison or hash functors
2020 //! found using ADL throw. Basic guarantee.
2021 void swap(hashtable_impl& other)
2024 ::boost::adl_move_swap(this->priv_equal(), other.priv_equal());
2025 ::boost::adl_move_swap(this->priv_hasher(), other.priv_hasher());
2027 ::boost::adl_move_swap(this->priv_bucket_traits(), other.priv_bucket_traits());
2028 ::boost::adl_move_swap(this->priv_value_traits(), other.priv_value_traits());
2029 this->priv_swap_cache(other);
2030 this->priv_size_traits().swap(other.priv_size_traits());
2031 this->priv_split_traits().swap(other.priv_split_traits());
2034 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw
2035 //! Cloner should yield to nodes that compare equal and produce the same
2036 //! hash than the original node.
2038 //! <b>Effects</b>: Erases all the elements from *this
2039 //! calling Disposer::operator()(pointer), clones all the
2040 //! elements from src calling Cloner::operator()(const_reference )
2041 //! and inserts them on *this. The hash function and the equality
2042 //! predicate are copied from the source.
2044 //! If store_hash option is true, this method does not use the hash function.
2046 //! If any operation throws, all cloned elements are unlinked and disposed
2047 //! calling Disposer::operator()(pointer).
2049 //! <b>Complexity</b>: Linear to erased plus inserted elements.
2051 //! <b>Throws</b>: If cloner or hasher throw or hash or equality predicate copying
2052 //! throws. Basic guarantee.
2053 template <class Cloner, class Disposer>
2054 BOOST_INTRUSIVE_FORCEINLINE void clone_from(const hashtable_impl &src, Cloner cloner, Disposer disposer)
2055 { this->priv_clone_from(src, cloner, disposer); }
2057 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw
2058 //! Cloner should yield to nodes that compare equal and produce the same
2059 //! hash than the original node.
2061 //! <b>Effects</b>: Erases all the elements from *this
2062 //! calling Disposer::operator()(pointer), clones all the
2063 //! elements from src calling Cloner::operator()(reference)
2064 //! and inserts them on *this. The hash function and the equality
2065 //! predicate are copied from the source.
2067 //! If store_hash option is true, this method does not use the hash function.
2069 //! If any operation throws, all cloned elements are unlinked and disposed
2070 //! calling Disposer::operator()(pointer).
2072 //! <b>Complexity</b>: Linear to erased plus inserted elements.
2074 //! <b>Throws</b>: If cloner or hasher throw or hash or equality predicate copying
2075 //! throws. Basic guarantee.
2076 template <class Cloner, class Disposer>
2077 BOOST_INTRUSIVE_FORCEINLINE void clone_from(BOOST_RV_REF(hashtable_impl) src, Cloner cloner, Disposer disposer)
2078 { this->priv_clone_from(static_cast<hashtable_impl&>(src), cloner, disposer); }
2080 //! <b>Requires</b>: value must be an lvalue
2082 //! <b>Effects</b>: Inserts the value into the unordered_set.
2084 //! <b>Returns</b>: An iterator to the inserted value.
2086 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2088 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Strong guarantee.
2090 //! <b>Note</b>: Does not affect the validity of iterators and references.
2091 //! No copy-constructors are called.
2092 iterator insert_equal(reference value)
2094 size_type bucket_num;
2095 std::size_t hash_value;
2097 siterator const it = this->priv_find
2098 (key_of_value()(value), this->priv_hasher(), this->priv_equal(), bucket_num, hash_value, prev);
2099 bool const next_is_in_group = optimize_multikey && it != this->priv_invalid_local_it();
2100 return this->priv_insert_equal_after_find(value, bucket_num, hash_value, prev, next_is_in_group);
2103 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
2104 //! of type value_type.
2106 //! <b>Effects</b>: Equivalent to this->insert_equal(t) for each element in [b, e).
2108 //! <b>Complexity</b>: Average case O(N), where N is distance(b, e).
2109 //! Worst case O(N*this->size()).
2111 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
2113 //! <b>Note</b>: Does not affect the validity of iterators and references.
2114 //! No copy-constructors are called.
2115 template<class Iterator>
2116 void insert_equal(Iterator b, Iterator e)
2119 this->insert_equal(*b);
2122 //! <b>Requires</b>: value must be an lvalue
2124 //! <b>Effects</b>: Tries to inserts value into the unordered_set.
2126 //! <b>Returns</b>: If the value
2127 //! is not already present inserts it and returns a pair containing the
2128 //! iterator to the new value and true. If there is an equivalent value
2129 //! returns a pair containing an iterator to the already present value
2132 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2134 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Strong guarantee.
2136 //! <b>Note</b>: Does not affect the validity of iterators and references.
2137 //! No copy-constructors are called.
2138 std::pair<iterator, bool> insert_unique(reference value)
2140 insert_commit_data commit_data;
2141 std::pair<iterator, bool> ret = this->insert_unique_check(key_of_value()(value), commit_data);
2143 ret.first = this->insert_unique_commit(value, commit_data);
2148 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
2149 //! of type value_type.
2151 //! <b>Effects</b>: Equivalent to this->insert_unique(t) for each element in [b, e).
2153 //! <b>Complexity</b>: Average case O(N), where N is distance(b, e).
2154 //! Worst case O(N*this->size()).
2156 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
2158 //! <b>Note</b>: Does not affect the validity of iterators and references.
2159 //! No copy-constructors are called.
2160 template<class Iterator>
2161 void insert_unique(Iterator b, Iterator e)
2164 this->insert_unique(*b);
2167 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2168 //! the same hash values as the stored hasher. The difference is that
2169 //! "hash_func" hashes the given key instead of the value_type.
2171 //! "equal_func" must be a equality function that induces
2172 //! the same equality as key_equal. The difference is that
2173 //! "equal_func" compares an arbitrary key with the contained values.
2175 //! <b>Effects</b>: Checks if a value can be inserted in the unordered_set, using
2176 //! a user provided key instead of the value itself.
2178 //! <b>Returns</b>: If there is an equivalent value
2179 //! returns a pair containing an iterator to the already present value
2180 //! and false. If the value can be inserted returns true in the returned
2181 //! pair boolean and fills "commit_data" that is meant to be used with
2182 //! the "insert_commit" function.
2184 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2186 //! <b>Throws</b>: If hash_func or equal_func throw. Strong guarantee.
2188 //! <b>Notes</b>: This function is used to improve performance when constructing
2189 //! a value_type is expensive: if there is an equivalent value
2190 //! the constructed object must be discarded. Many times, the part of the
2191 //! node that is used to impose the hash or the equality is much cheaper to
2192 //! construct than the value_type and this function offers the possibility to
2193 //! use that the part to check if the insertion will be successful.
2195 //! If the check is successful, the user can construct the value_type and use
2196 //! "insert_commit" to insert the object in constant-time.
2198 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
2199 //! objects are inserted or erased from the unordered_set.
2201 //! After a successful rehashing insert_commit_data remains valid.
2202 template<class KeyType, class KeyHasher, class KeyEqual>
2203 std::pair<iterator, bool> insert_unique_check
2204 ( const KeyType &key
2205 , KeyHasher hash_func
2206 , KeyEqual equal_func
2207 , insert_commit_data &commit_data)
2209 size_type bucket_num;
2211 siterator const pos = this->priv_find(key, hash_func, equal_func, bucket_num, commit_data.hash, prev);
2212 return std::pair<iterator, bool>
2213 ( iterator(pos, &this->get_bucket_value_traits())
2214 , pos == this->priv_invalid_local_it());
2217 //! <b>Effects</b>: Checks if a value can be inserted in the unordered_set, using
2218 //! a user provided key instead of the value itself.
2220 //! <b>Returns</b>: If there is an equivalent value
2221 //! returns a pair containing an iterator to the already present value
2222 //! and false. If the value can be inserted returns true in the returned
2223 //! pair boolean and fills "commit_data" that is meant to be used with
2224 //! the "insert_commit" function.
2226 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2228 //! <b>Throws</b>: If hasher or key_compare throw. Strong guarantee.
2230 //! <b>Notes</b>: This function is used to improve performance when constructing
2231 //! a value_type is expensive: if there is an equivalent value
2232 //! the constructed object must be discarded. Many times, the part of the
2233 //! node that is used to impose the hash or the equality is much cheaper to
2234 //! construct than the value_type and this function offers the possibility to
2235 //! use that the part to check if the insertion will be successful.
2237 //! If the check is successful, the user can construct the value_type and use
2238 //! "insert_commit" to insert the object in constant-time.
2240 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
2241 //! objects are inserted or erased from the unordered_set.
2243 //! After a successful rehashing insert_commit_data remains valid.
2244 BOOST_INTRUSIVE_FORCEINLINE std::pair<iterator, bool> insert_unique_check
2245 ( const key_type &key, insert_commit_data &commit_data)
2246 { return this->insert_unique_check(key, this->priv_hasher(), this->priv_equal(), commit_data); }
2248 //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
2249 //! must have been obtained from a previous call to "insert_check".
2250 //! No objects should have been inserted or erased from the unordered_set between
2251 //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
2253 //! <b>Effects</b>: Inserts the value in the unordered_set using the information obtained
2254 //! from the "commit_data" that a previous "insert_check" filled.
2256 //! <b>Returns</b>: An iterator to the newly inserted object.
2258 //! <b>Complexity</b>: Constant time.
2260 //! <b>Throws</b>: Nothing.
2262 //! <b>Notes</b>: This function has only sense if a "insert_check" has been
2263 //! previously executed to fill "commit_data". No value should be inserted or
2264 //! erased between the "insert_check" and "insert_commit" calls.
2266 //! After a successful rehashing insert_commit_data remains valid.
2267 iterator insert_unique_commit(reference value, const insert_commit_data &commit_data)
2269 size_type bucket_num = this->priv_hash_to_bucket(commit_data.hash);
2270 bucket_type &b = this->priv_bucket_pointer()[bucket_num];
2271 this->priv_size_traits().increment();
2272 node_ptr const n = pointer_traits<node_ptr>::pointer_to(this->priv_value_to_node(value));
2273 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(n));
2274 node_functions_t::store_hash(n, commit_data.hash, store_hash_t());
2275 this->priv_insertion_update_cache(bucket_num);
2276 group_functions_t::insert_in_group(n, n, optimize_multikey_t());
2277 return iterator(b.insert_after(b.before_begin(), *n), &this->get_bucket_value_traits());
2280 //! <b>Effects</b>: Erases the element pointed to by i.
2282 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2284 //! <b>Throws</b>: Nothing.
2286 //! <b>Note</b>: Invalidates the iterators (but not the references)
2287 //! to the erased element. No destructors are called.
2288 BOOST_INTRUSIVE_FORCEINLINE void erase(const_iterator i)
2289 { this->erase_and_dispose(i, detail::null_disposer()); }
2291 //! <b>Effects</b>: Erases the range pointed to by b end e.
2293 //! <b>Complexity</b>: Average case O(distance(b, e)),
2294 //! worst case O(this->size()).
2296 //! <b>Throws</b>: Nothing.
2298 //! <b>Note</b>: Invalidates the iterators (but not the references)
2299 //! to the erased elements. No destructors are called.
2300 BOOST_INTRUSIVE_FORCEINLINE void erase(const_iterator b, const_iterator e)
2301 { this->erase_and_dispose(b, e, detail::null_disposer()); }
2303 //! <b>Effects</b>: Erases all the elements with the given value.
2305 //! <b>Returns</b>: The number of erased elements.
2307 //! <b>Complexity</b>: Average case O(this->count(value)).
2308 //! Worst case O(this->size()).
2310 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2311 //! Basic guarantee.
2313 //! <b>Note</b>: Invalidates the iterators (but not the references)
2314 //! to the erased elements. No destructors are called.
2315 BOOST_INTRUSIVE_FORCEINLINE size_type erase(const key_type &key)
2316 { return this->erase(key, this->priv_hasher(), this->priv_equal()); }
2318 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2319 //! the same hash values as the stored hasher. The difference is that
2320 //! "hash_func" hashes the given key instead of the value_type.
2322 //! "equal_func" must be a equality function that induces
2323 //! the same equality as key_equal. The difference is that
2324 //! "equal_func" compares an arbitrary key with the contained values.
2326 //! <b>Effects</b>: Erases all the elements that have the same hash and
2327 //! compare equal with the given key.
2329 //! <b>Returns</b>: The number of erased elements.
2331 //! <b>Complexity</b>: Average case O(this->count(value)).
2332 //! Worst case O(this->size()).
2334 //! <b>Throws</b>: If hash_func or equal_func throw. Basic guarantee.
2336 //! <b>Note</b>: Invalidates the iterators (but not the references)
2337 //! to the erased elements. No destructors are called.
2338 template<class KeyType, class KeyHasher, class KeyEqual>
2339 BOOST_INTRUSIVE_FORCEINLINE size_type erase(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func)
2340 { return this->erase_and_dispose(key, hash_func, equal_func, detail::null_disposer()); }
2342 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
2344 //! <b>Effects</b>: Erases the element pointed to by i.
2345 //! Disposer::operator()(pointer) is called for the removed element.
2347 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2349 //! <b>Throws</b>: Nothing.
2351 //! <b>Note</b>: Invalidates the iterators
2352 //! to the erased elements.
2353 template<class Disposer>
2354 BOOST_INTRUSIVE_DOC1ST(void
2355 , typename detail::disable_if_convertible<Disposer BOOST_INTRUSIVE_I const_iterator>::type)
2356 erase_and_dispose(const_iterator i, Disposer disposer)
2358 //Get the bucket number and local iterator for both iterators
2359 siterator const first_local_it(i.slist_it());
2360 size_type const first_bucket_num = this->priv_get_bucket_num(first_local_it);
2361 this->priv_erase_node(this->priv_bucket_pointer()[first_bucket_num], first_local_it, make_node_disposer(disposer), optimize_multikey_t());
2362 this->priv_size_traits().decrement();
2363 this->priv_erasure_update_cache_range(first_bucket_num, first_bucket_num);
2366 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
2368 //! <b>Effects</b>: Erases the range pointed to by b end e.
2369 //! Disposer::operator()(pointer) is called for the removed elements.
2371 //! <b>Complexity</b>: Average case O(distance(b, e)),
2372 //! worst case O(this->size()).
2374 //! <b>Throws</b>: Nothing.
2376 //! <b>Note</b>: Invalidates the iterators
2377 //! to the erased elements.
2378 template<class Disposer>
2379 void erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
2382 //Get the bucket number and local iterator for both iterators
2383 siterator first_local_it(b.slist_it());
2384 size_type first_bucket_num = this->priv_get_bucket_num(first_local_it);
2386 const bucket_ptr buck_ptr = this->priv_bucket_pointer();
2387 siterator before_first_local_it
2388 = this->priv_get_previous(buck_ptr[first_bucket_num], first_local_it);
2389 size_type last_bucket_num;
2390 siterator last_local_it;
2392 //For the end iterator, we will assign the end iterator
2393 //of the last bucket
2394 if(e == this->end()){
2395 last_bucket_num = this->bucket_count() - 1;
2396 last_local_it = buck_ptr[last_bucket_num].end();
2399 last_local_it = e.slist_it();
2400 last_bucket_num = this->priv_get_bucket_num(last_local_it);
2402 size_type const num_erased = this->priv_erase_node_range
2403 ( before_first_local_it, first_bucket_num, last_local_it, last_bucket_num
2404 , make_node_disposer(disposer), optimize_multikey_t());
2405 this->priv_size_traits().set_size(this->priv_size_traits().get_size()-num_erased);
2406 this->priv_erasure_update_cache_range(first_bucket_num, last_bucket_num);
2410 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
2412 //! <b>Effects</b>: Erases all the elements with the given value.
2413 //! Disposer::operator()(pointer) is called for the removed elements.
2415 //! <b>Returns</b>: The number of erased elements.
2417 //! <b>Complexity</b>: Average case O(this->count(value)).
2418 //! Worst case O(this->size()).
2420 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2421 //! Basic guarantee.
2423 //! <b>Note</b>: Invalidates the iterators (but not the references)
2424 //! to the erased elements. No destructors are called.
2425 template<class Disposer>
2426 BOOST_INTRUSIVE_FORCEINLINE size_type erase_and_dispose(const key_type &key, Disposer disposer)
2427 { return this->erase_and_dispose(key, this->priv_hasher(), this->priv_equal(), disposer); }
2429 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
2431 //! <b>Effects</b>: Erases all the elements with the given key.
2432 //! according to the comparison functor "equal_func".
2433 //! Disposer::operator()(pointer) is called for the removed elements.
2435 //! <b>Returns</b>: The number of erased elements.
2437 //! <b>Complexity</b>: Average case O(this->count(value)).
2438 //! Worst case O(this->size()).
2440 //! <b>Throws</b>: If hash_func or equal_func throw. Basic guarantee.
2442 //! <b>Note</b>: Invalidates the iterators
2443 //! to the erased elements.
2444 template<class KeyType, class KeyHasher, class KeyEqual, class Disposer>
2445 size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func
2446 ,KeyEqual equal_func, Disposer disposer)
2448 size_type bucket_num;
2451 siterator it = this->priv_find(key, hash_func, equal_func, bucket_num, h, prev);
2452 bool const success = it != this->priv_invalid_local_it();
2456 if(optimize_multikey){
2457 cnt = this->priv_erase_from_single_bucket
2458 (this->priv_bucket_pointer()[bucket_num], prev, ++(priv_last_in_group)(it), make_node_disposer(disposer), optimize_multikey_t());
2461 bucket_type &b = this->priv_bucket_pointer()[bucket_num];
2462 siterator const end_sit = b.end();
2466 }while(it != end_sit &&
2467 this->priv_is_value_equal_to_key
2468 (this->priv_value_from_slist_node(it.pointed_node()), h, key, equal_func));
2469 bucket_type::s_erase_after_and_dispose(prev, it, make_node_disposer(disposer));
2471 this->priv_size_traits().set_size(this->priv_size_traits().get_size()-cnt);
2472 this->priv_erasure_update_cache();
2478 //! <b>Effects</b>: Erases all of the elements.
2480 //! <b>Complexity</b>: Linear to the number of elements on the container.
2481 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
2483 //! <b>Throws</b>: Nothing.
2485 //! <b>Note</b>: Invalidates the iterators (but not the references)
2486 //! to the erased elements. No destructors are called.
2489 this->priv_clear_buckets_and_cache();
2490 this->priv_size_traits().set_size(size_type(0));
2493 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
2495 //! <b>Effects</b>: Erases all of the elements.
2497 //! <b>Complexity</b>: Linear to the number of elements on the container.
2498 //! Disposer::operator()(pointer) is called for the removed elements.
2500 //! <b>Throws</b>: Nothing.
2502 //! <b>Note</b>: Invalidates the iterators (but not the references)
2503 //! to the erased elements. No destructors are called.
2504 template<class Disposer>
2505 void clear_and_dispose(Disposer disposer)
2507 if(!constant_time_size || !this->empty()){
2508 size_type num_buckets = this->bucket_count();
2509 bucket_ptr b = this->priv_bucket_pointer();
2510 typename typeof_node_disposer<Disposer>::type d(disposer, &this->priv_value_traits());
2511 for(; num_buckets--; ++b){
2512 b->clear_and_dispose(d);
2514 this->priv_size_traits().set_size(size_type(0));
2516 this->priv_initialize_cache();
2519 //! <b>Effects</b>: Returns the number of contained elements with the given value
2521 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2523 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2524 BOOST_INTRUSIVE_FORCEINLINE size_type count(const key_type &key) const
2525 { return this->count(key, this->priv_hasher(), this->priv_equal()); }
2527 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2528 //! the same hash values as the stored hasher. The difference is that
2529 //! "hash_func" hashes the given key instead of the value_type.
2531 //! "equal_func" must be a equality function that induces
2532 //! the same equality as key_equal. The difference is that
2533 //! "equal_func" compares an arbitrary key with the contained values.
2535 //! <b>Effects</b>: Returns the number of contained elements with the given key
2537 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2539 //! <b>Throws</b>: If hash_func or equal throw.
2540 template<class KeyType, class KeyHasher, class KeyEqual>
2541 size_type count(const KeyType &key, KeyHasher hash_func, KeyEqual equal_func) const
2545 this->priv_local_equal_range(key, hash_func, equal_func, n_bucket, cnt);
2549 //! <b>Effects</b>: Finds an iterator to the first element is equal to
2550 //! "value" or end() if that element does not exist.
2552 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2554 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2555 BOOST_INTRUSIVE_FORCEINLINE iterator find(const key_type &key)
2556 { return this->find(key, this->priv_hasher(), this->priv_equal()); }
2558 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2559 //! the same hash values as the stored hasher. The difference is that
2560 //! "hash_func" hashes the given key instead of the value_type.
2562 //! "equal_func" must be a equality function that induces
2563 //! the same equality as key_equal. The difference is that
2564 //! "equal_func" compares an arbitrary key with the contained values.
2566 //! <b>Effects</b>: Finds an iterator to the first element whose key is
2567 //! "key" according to the given hash and equality functor or end() if
2568 //! that element does not exist.
2570 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2572 //! <b>Throws</b>: If hash_func or equal_func throw.
2574 //! <b>Note</b>: This function is used when constructing a value_type
2575 //! is expensive and the value_type can be compared with a cheaper
2576 //! key type. Usually this key is part of the value_type.
2577 template<class KeyType, class KeyHasher, class KeyEqual>
2578 iterator find(const KeyType &key, KeyHasher hash_func, KeyEqual equal_func)
2583 return iterator( this->priv_find(key, hash_func, equal_func, bucket_n, hash, prev)
2584 , &this->get_bucket_value_traits());
2587 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
2588 //! "key" or end() if that element does not exist.
2590 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2592 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2593 BOOST_INTRUSIVE_FORCEINLINE const_iterator find(const key_type &key) const
2594 { return this->find(key, this->priv_hasher(), this->priv_equal()); }
2596 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2597 //! the same hash values as the stored hasher. The difference is that
2598 //! "hash_func" hashes the given key instead of the value_type.
2600 //! "equal_func" must be a equality function that induces
2601 //! the same equality as key_equal. The difference is that
2602 //! "equal_func" compares an arbitrary key with the contained values.
2604 //! <b>Effects</b>: Finds an iterator to the first element whose key is
2605 //! "key" according to the given hasher and equality functor or end() if
2606 //! that element does not exist.
2608 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2610 //! <b>Throws</b>: If hash_func or equal_func throw.
2612 //! <b>Note</b>: This function is used when constructing a value_type
2613 //! is expensive and the value_type can be compared with a cheaper
2614 //! key type. Usually this key is part of the value_type.
2615 template<class KeyType, class KeyHasher, class KeyEqual>
2617 (const KeyType &key, KeyHasher hash_func, KeyEqual equal_func) const
2620 std::size_t hash_value;
2622 return const_iterator( this->priv_find(key, hash_func, equal_func, bucket_n, hash_value, prev)
2623 , &this->get_bucket_value_traits());
2626 //! <b>Effects</b>: Returns a range containing all elements with values equivalent
2627 //! to value. Returns std::make_pair(this->end(), this->end()) if no such
2630 //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
2632 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2633 BOOST_INTRUSIVE_FORCEINLINE std::pair<iterator,iterator> equal_range(const key_type &key)
2634 { return this->equal_range(key, this->priv_hasher(), this->priv_equal()); }
2636 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2637 //! the same hash values as the stored hasher. The difference is that
2638 //! "hash_func" hashes the given key instead of the value_type.
2640 //! "equal_func" must be a equality function that induces
2641 //! the same equality as key_equal. The difference is that
2642 //! "equal_func" compares an arbitrary key with the contained values.
2644 //! <b>Effects</b>: Returns a range containing all elements with equivalent
2645 //! keys. Returns std::make_pair(this->end(), this->end()) if no such
2648 //! <b>Complexity</b>: Average case O(this->count(key, hash_func, equal_func)).
2649 //! Worst case O(this->size()).
2651 //! <b>Throws</b>: If hash_func or the equal_func throw.
2653 //! <b>Note</b>: This function is used when constructing a value_type
2654 //! is expensive and the value_type can be compared with a cheaper
2655 //! key type. Usually this key is part of the value_type.
2656 template<class KeyType, class KeyHasher, class KeyEqual>
2657 std::pair<iterator,iterator> equal_range
2658 (const KeyType &key, KeyHasher hash_func, KeyEqual equal_func)
2660 std::pair<siterator, siterator> ret =
2661 this->priv_equal_range(key, hash_func, equal_func);
2662 return std::pair<iterator, iterator>
2663 ( iterator(ret.first, &this->get_bucket_value_traits())
2664 , iterator(ret.second, &this->get_bucket_value_traits()));
2667 //! <b>Effects</b>: Returns a range containing all elements with values equivalent
2668 //! to value. Returns std::make_pair(this->end(), this->end()) if no such
2671 //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
2673 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2674 BOOST_INTRUSIVE_FORCEINLINE std::pair<const_iterator, const_iterator>
2675 equal_range(const key_type &key) const
2676 { return this->equal_range(key, this->priv_hasher(), this->priv_equal()); }
2678 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2679 //! the same hash values as the stored hasher. The difference is that
2680 //! "hash_func" hashes the given key instead of the value_type.
2682 //! "equal_func" must be a equality function that induces
2683 //! the same equality as key_equal. The difference is that
2684 //! "equal_func" compares an arbitrary key with the contained values.
2686 //! <b>Effects</b>: Returns a range containing all elements with equivalent
2687 //! keys. Returns std::make_pair(this->end(), this->end()) if no such
2690 //! <b>Complexity</b>: Average case O(this->count(key, hash_func, equal_func)).
2691 //! Worst case O(this->size()).
2693 //! <b>Throws</b>: If the hasher or equal_func throw.
2695 //! <b>Note</b>: This function is used when constructing a value_type
2696 //! is expensive and the value_type can be compared with a cheaper
2697 //! key type. Usually this key is part of the value_type.
2698 template<class KeyType, class KeyHasher, class KeyEqual>
2699 std::pair<const_iterator,const_iterator> equal_range
2700 (const KeyType &key, KeyHasher hash_func, KeyEqual equal_func) const
2702 std::pair<siterator, siterator> ret =
2703 this->priv_equal_range(key, hash_func, equal_func);
2704 return std::pair<const_iterator, const_iterator>
2705 ( const_iterator(ret.first, &this->get_bucket_value_traits())
2706 , const_iterator(ret.second, &this->get_bucket_value_traits()));
2709 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2711 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2712 //! appropriate type. Otherwise the behavior is undefined.
2714 //! <b>Effects</b>: Returns: a valid iterator belonging to the unordered_set
2715 //! that points to the value
2717 //! <b>Complexity</b>: Constant.
2719 //! <b>Throws</b>: If the internal hash function throws.
2720 iterator iterator_to(reference value);
2722 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2723 //! appropriate type. Otherwise the behavior is undefined.
2725 //! <b>Effects</b>: Returns: a valid const_iterator belonging to the
2726 //! unordered_set that points to the value
2728 //! <b>Complexity</b>: Constant.
2730 //! <b>Throws</b>: If the internal hash function throws.
2731 const_iterator iterator_to(const_reference value) const;
2733 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2734 //! appropriate type. Otherwise the behavior is undefined.
2736 //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_set
2737 //! that points to the value
2739 //! <b>Complexity</b>: Constant.
2741 //! <b>Throws</b>: Nothing.
2743 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2745 static local_iterator s_local_iterator_to(reference value);
2747 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2748 //! appropriate type. Otherwise the behavior is undefined.
2750 //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
2751 //! the unordered_set that points to the value
2753 //! <b>Complexity</b>: Constant.
2755 //! <b>Throws</b>: Nothing.
2757 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2759 static const_local_iterator s_local_iterator_to(const_reference value);
2761 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2762 //! appropriate type. Otherwise the behavior is undefined.
2764 //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_set
2765 //! that points to the value
2767 //! <b>Complexity</b>: Constant.
2769 //! <b>Throws</b>: Nothing.
2770 local_iterator local_iterator_to(reference value);
2772 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2773 //! appropriate type. Otherwise the behavior is undefined.
2775 //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
2776 //! the unordered_set that points to the value
2778 //! <b>Complexity</b>: Constant.
2780 //! <b>Throws</b>: Nothing.
2781 const_local_iterator local_iterator_to(const_reference value) const;
2783 //! <b>Effects</b>: Returns the number of buckets passed in the constructor
2784 //! or the last rehash function.
2786 //! <b>Complexity</b>: Constant.
2788 //! <b>Throws</b>: Nothing.
2789 size_type bucket_count() const;
2791 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2793 //! <b>Effects</b>: Returns the number of elements in the nth bucket.
2795 //! <b>Complexity</b>: Constant.
2797 //! <b>Throws</b>: Nothing.
2798 size_type bucket_size(size_type n) const;
2799 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2801 //! <b>Effects</b>: Returns the index of the bucket in which elements
2802 //! with keys equivalent to k would be found, if any such element existed.
2804 //! <b>Complexity</b>: Constant.
2806 //! <b>Throws</b>: If the hash functor throws.
2808 //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
2809 BOOST_INTRUSIVE_FORCEINLINE size_type bucket(const key_type& k) const
2810 { return this->bucket(k, this->priv_hasher()); }
2812 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2813 //! the same hash values as the stored hasher. The difference is that
2814 //! "hash_func" hashes the given key instead of the value_type.
2816 //! <b>Effects</b>: Returns the index of the bucket in which elements
2817 //! with keys equivalent to k would be found, if any such element existed.
2819 //! <b>Complexity</b>: Constant.
2821 //! <b>Throws</b>: If hash_func throws.
2823 //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
2824 template<class KeyType, class KeyHasher>
2825 BOOST_INTRUSIVE_FORCEINLINE size_type bucket(const KeyType& k, KeyHasher hash_func) const
2826 { return this->priv_hash_to_bucket(hash_func(k)); }
2828 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2829 //! <b>Effects</b>: Returns the bucket array pointer passed in the constructor
2830 //! or the last rehash function.
2832 //! <b>Complexity</b>: Constant.
2834 //! <b>Throws</b>: Nothing.
2835 bucket_ptr bucket_pointer() const;
2837 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2839 //! <b>Effects</b>: Returns a local_iterator pointing to the beginning
2840 //! of the sequence stored in the bucket n.
2842 //! <b>Complexity</b>: Constant.
2844 //! <b>Throws</b>: Nothing.
2846 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2847 //! containing all of the elements in the nth bucket.
2848 local_iterator begin(size_type n);
2850 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2852 //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
2853 //! of the sequence stored in the bucket n.
2855 //! <b>Complexity</b>: Constant.
2857 //! <b>Throws</b>: Nothing.
2859 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2860 //! containing all of the elements in the nth bucket.
2861 const_local_iterator begin(size_type n) const;
2863 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2865 //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
2866 //! of the sequence stored in the bucket n.
2868 //! <b>Complexity</b>: Constant.
2870 //! <b>Throws</b>: Nothing.
2872 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2873 //! containing all of the elements in the nth bucket.
2874 const_local_iterator cbegin(size_type n) const;
2876 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2878 //! <b>Effects</b>: Returns a local_iterator pointing to the end
2879 //! of the sequence stored in the bucket n.
2881 //! <b>Complexity</b>: Constant.
2883 //! <b>Throws</b>: Nothing.
2885 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2886 //! containing all of the elements in the nth bucket.
2887 local_iterator end(size_type n);
2889 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2891 //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
2892 //! of the sequence stored in the bucket n.
2894 //! <b>Complexity</b>: Constant.
2896 //! <b>Throws</b>: Nothing.
2898 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2899 //! containing all of the elements in the nth bucket.
2900 const_local_iterator end(size_type n) const;
2902 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2904 //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
2905 //! of the sequence stored in the bucket n.
2907 //! <b>Complexity</b>: Constant.
2909 //! <b>Throws</b>: Nothing.
2911 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2912 //! containing all of the elements in the nth bucket.
2913 const_local_iterator cend(size_type n) const;
2914 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2916 //! <b>Requires</b>: new_bucket_traits can hold a pointer to a new bucket array
2917 //! or the same as the old bucket array with a different length. new_size is the length of the
2918 //! the array pointed by new_buckets. If new_bucket_traits.bucket_begin() == this->bucket_pointer()
2919 //! new_bucket_traits.bucket_count() can be bigger or smaller than this->bucket_count().
2920 //! 'new_bucket_traits' copy constructor should not throw.
2923 //! If `new_bucket_traits.bucket_begin() == this->bucket_pointer()` is false,
2924 //! unlinks values from the old bucket and inserts then in the new one according
2925 //! to the hash value of values.
2927 //! If `new_bucket_traits.bucket_begin() == this->bucket_pointer()` is true,
2928 //! the implementations avoids moving values as much as possible.
2930 //! Bucket traits hold by *this is assigned from new_bucket_traits.
2931 //! If the container is configured as incremental<>, the split bucket is set
2932 //! to the new bucket_count().
2934 //! If store_hash option is true, this method does not use the hash function.
2935 //! If false, the implementation tries to minimize calls to the hash function
2936 //! (e.g. once for equivalent values if optimize_multikey<true> is true).
2938 //! If rehash is successful updates the internal bucket_traits with new_bucket_traits.
2940 //! <b>Complexity</b>: Average case linear in this->size(), worst case quadratic.
2942 //! <b>Throws</b>: If the hasher functor throws. Basic guarantee.
2943 BOOST_INTRUSIVE_FORCEINLINE void rehash(const bucket_traits &new_bucket_traits)
2944 { this->rehash_impl(new_bucket_traits, false); }
2946 //! <b>Note</b>: This function is used when keys from inserted elements are changed
2947 //! (e.g. a language change when key is a string) but uniqueness and hash properties are
2948 //! preserved so a fast full rehash recovers invariants for *this without extracting and
2949 //! reinserting all elements again.
2951 //! <b>Requires</b>: Calls produced to the hash function should not alter the value uniqueness
2952 //! properties of already inserted elements. If hasher(key1) == hasher(key2) was true when
2953 //! elements were inserted, it shall be true during calls produced in the execution of this function.
2955 //! key_equal is not called inside this function so it is assumed that key_equal(value1, value2)
2956 //! should produce the same results as before for inserted elements.
2958 //! <b>Effects</b>: Reprocesses all values hold by *this, recalculating their hash values
2959 //! and redistributing them though the buckets.
2961 //! If store_hash option is true, this method uses the hash function and updates the stored hash value.
2963 //! <b>Complexity</b>: Average case linear in this->size(), worst case quadratic.
2965 //! <b>Throws</b>: If the hasher functor throws. Basic guarantee.
2966 BOOST_INTRUSIVE_FORCEINLINE void full_rehash()
2967 { this->rehash_impl(this->priv_bucket_traits(), true); }
2969 //! <b>Requires</b>:
2973 //! <b>Complexity</b>:
2977 //! <b>Note</b>: this method is only available if incremental<true> option is activated.
2978 bool incremental_rehash(bool grow = true)
2980 //This function is only available for containers with incremental hashing
2981 BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
2982 const size_type split_idx = this->priv_split_traits().get_size();
2983 const size_type bucket_cnt = this->bucket_count();
2984 const bucket_ptr buck_ptr = this->priv_bucket_pointer();
2988 //Test if the split variable can be changed
2989 if((ret = split_idx < bucket_cnt)){
2990 const size_type bucket_to_rehash = split_idx - bucket_cnt/2;
2991 bucket_type &old_bucket = buck_ptr[bucket_to_rehash];
2992 this->priv_split_traits().increment();
2994 //Anti-exception stuff: if an exception is thrown while
2995 //moving elements from old_bucket to the target bucket, all moved
2996 //elements are moved back to the original one.
2997 detail::incremental_rehash_rollback<bucket_type, split_traits> rollback
2998 ( buck_ptr[split_idx], old_bucket, this->priv_split_traits());
2999 for( siterator before_i(old_bucket.before_begin()), i(old_bucket.begin()), end_sit(old_bucket.end())
3000 ; i != end_sit; i = before_i, ++i){
3001 const value_type &v = this->priv_value_from_slist_node(i.pointed_node());
3002 const std::size_t hash_value = this->priv_stored_or_compute_hash(v, store_hash_t());
3003 const size_type new_n = this->priv_hash_to_bucket(hash_value);
3004 siterator const last = (priv_last_in_group)(i);
3005 if(new_n == bucket_to_rehash){
3009 bucket_type &new_b = buck_ptr[new_n];
3010 new_b.splice_after(new_b.before_begin(), old_bucket, before_i, last);
3014 this->priv_erasure_update_cache();
3017 else if((ret = split_idx > bucket_cnt/2)){ //!grow
3018 const size_type target_bucket_num = split_idx - 1 - bucket_cnt/2;
3019 bucket_type &target_bucket = buck_ptr[target_bucket_num];
3020 bucket_type &source_bucket = buck_ptr[split_idx-1];
3021 target_bucket.splice_after(target_bucket.cbefore_begin(), source_bucket);
3022 this->priv_split_traits().decrement();
3023 this->priv_insertion_update_cache(target_bucket_num);
3028 //! <b>Effects</b>: If new_bucket_traits.bucket_count() is not
3029 //! this->bucket_count()/2 or this->bucket_count()*2, or
3030 //! this->split_bucket() != new_bucket_traits.bucket_count() returns false
3031 //! and does nothing.
3033 //! Otherwise, copy assigns new_bucket_traits to the internal bucket_traits
3034 //! and transfers all the objects from old buckets to the new ones.
3036 //! <b>Complexity</b>: Linear to size().
3038 //! <b>Throws</b>: Nothing
3040 //! <b>Note</b>: this method is only available if incremental<true> option is activated.
3041 bool incremental_rehash(const bucket_traits &new_bucket_traits)
3043 //This function is only available for containers with incremental hashing
3044 BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
3045 size_type const new_bucket_traits_size = new_bucket_traits.bucket_count();
3046 size_type const cur_bucket_traits = this->bucket_count();
3047 const size_type split_idx = this->split_count();
3049 //Test new bucket size is consistent with internal bucket size and split count
3050 if(new_bucket_traits_size/2 == cur_bucket_traits){
3051 if(!(split_idx >= cur_bucket_traits))
3054 else if(new_bucket_traits_size == cur_bucket_traits/2){
3055 if(!(split_idx <= new_bucket_traits_size))
3062 const size_type ini_n = this->priv_get_cache_bucket_num();
3063 const bucket_ptr old_buckets = this->priv_bucket_pointer();
3064 this->priv_bucket_traits() = new_bucket_traits;
3065 if(new_bucket_traits.bucket_begin() != old_buckets){
3066 for(size_type n = ini_n; n < split_idx; ++n){
3067 bucket_type &new_bucket = new_bucket_traits.bucket_begin()[n];
3068 bucket_type &old_bucket = old_buckets[n];
3069 new_bucket.splice_after(new_bucket.cbefore_begin(), old_bucket);
3071 //Put cache to safe position
3072 this->priv_initialize_cache();
3073 this->priv_insertion_update_cache(ini_n);
3078 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
3080 //! <b>Requires</b>: incremental<> option must be set
3082 //! <b>Effects</b>: returns the current split count
3084 //! <b>Complexity</b>: Constant
3086 //! <b>Throws</b>: Nothing
3087 size_type split_count() const;
3089 //! <b>Effects</b>: Returns the nearest new bucket count optimized for
3090 //! the container that is bigger or equal than n. This suggestion can be
3091 //! used to create bucket arrays with a size that will usually improve
3092 //! container's performance. If such value does not exist, the
3093 //! higher possible value is returned.
3095 //! <b>Complexity</b>: Amortized constant time.
3097 //! <b>Throws</b>: Nothing.
3098 static size_type suggested_upper_bucket_count(size_type n);
3100 //! <b>Effects</b>: Returns the nearest new bucket count optimized for
3101 //! the container that is smaller or equal than n. This suggestion can be
3102 //! used to create bucket arrays with a size that will usually improve
3103 //! container's performance. If such value does not exist, the
3104 //! lowest possible value is returned.
3106 //! <b>Complexity</b>: Amortized constant time.
3108 //! <b>Throws</b>: Nothing.
3109 static size_type suggested_lower_bucket_count(size_type n);
3110 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
3113 friend bool operator==(const hashtable_impl &x, const hashtable_impl &y)
3116 if(constant_time_size && x.size() != y.size()){
3119 for (const_iterator ix = x.cbegin(), ex = x.cend(); ix != ex; ++ix){
3120 std::pair<const_iterator, const_iterator> eqx(x.equal_range(key_of_value()(*ix))),
3121 eqy(y.equal_range(key_of_value()(*ix)));
3122 if (boost::intrusive::iterator_distance(eqx.first, eqx.second) !=
3123 boost::intrusive::iterator_distance(eqy.first, eqy.second) ||
3124 !(priv_algo_is_permutation)(eqx.first, eqx.second, eqy.first) ){
3132 friend bool operator!=(const hashtable_impl &x, const hashtable_impl &y)
3133 { return !(x == y); }
3135 friend bool operator<(const hashtable_impl &x, const hashtable_impl &y)
3136 { return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
3138 friend bool operator>(const hashtable_impl &x, const hashtable_impl &y)
3141 friend bool operator<=(const hashtable_impl &x, const hashtable_impl &y)
3142 { return !(y < x); }
3144 friend bool operator>=(const hashtable_impl &x, const hashtable_impl &y)
3145 { return !(x < y); }
3148 BOOST_INTRUSIVE_FORCEINLINE void check() const {}
3151 void rehash_impl(const bucket_traits &new_bucket_traits, bool do_full_rehash)
3153 const bucket_ptr new_buckets = new_bucket_traits.bucket_begin();
3154 size_type new_bucket_count = new_bucket_traits.bucket_count();
3155 const bucket_ptr old_buckets = this->priv_bucket_pointer();
3156 size_type old_bucket_count = this->bucket_count();
3158 //Check power of two bucket array if the option is activated
3159 BOOST_INTRUSIVE_INVARIANT_ASSERT
3160 (!power_2_buckets || (0 == (new_bucket_count & (new_bucket_count-1u))));
3162 size_type n = this->priv_get_cache_bucket_num();
3163 const bool same_buffer = old_buckets == new_buckets;
3164 //If the new bucket length is a common factor
3165 //of the old one we can avoid hash calculations.
3166 const bool fast_shrink = (!do_full_rehash) && (!incremental) && (old_bucket_count >= new_bucket_count) &&
3167 (power_2_buckets || (old_bucket_count % new_bucket_count) == 0);
3168 //If we are shrinking the same bucket array and it's
3169 //is a fast shrink, just rehash the last nodes
3170 size_type new_first_bucket_num = new_bucket_count;
3171 if(same_buffer && fast_shrink && (n < new_bucket_count)){
3172 new_first_bucket_num = n;
3173 n = new_bucket_count;
3176 //Anti-exception stuff: they destroy the elements if something goes wrong.
3177 //If the source and destination buckets are the same, the second rollback function
3178 //is harmless, because all elements have been already unlinked and destroyed
3179 typedef detail::init_disposer<node_algorithms> NodeDisposer;
3180 typedef detail::exception_array_disposer<bucket_type, NodeDisposer, size_type> ArrayDisposer;
3181 NodeDisposer node_disp;
3182 ArrayDisposer rollback1(new_buckets[0], node_disp, new_bucket_count);
3183 ArrayDisposer rollback2(old_buckets[0], node_disp, old_bucket_count);
3185 //Put size in a safe value for rollback exception
3186 size_type const size_backup = this->priv_size_traits().get_size();
3187 this->priv_size_traits().set_size(0);
3188 //Put cache to safe position
3189 this->priv_initialize_cache();
3190 this->priv_insertion_update_cache(size_type(0u));
3192 //Iterate through nodes
3193 for(; n < old_bucket_count; ++n){
3194 bucket_type &old_bucket = old_buckets[n];
3196 for( siterator before_i(old_bucket.before_begin()), i(old_bucket.begin()), end_sit(old_bucket.end())
3198 ; i = before_i, ++i){
3200 //First obtain hash value (and store it if do_full_rehash)
3201 std::size_t hash_value;
3203 value_type &v = this->priv_value_from_slist_node(i.pointed_node());
3204 hash_value = this->priv_hasher()(key_of_value()(v));
3205 node_functions_t::store_hash(pointer_traits<node_ptr>::pointer_to(this->priv_value_to_node(v)), hash_value, store_hash_t());
3208 const value_type &v = this->priv_value_from_slist_node(i.pointed_node());
3209 hash_value = this->priv_stored_or_compute_hash(v, store_hash_t());
3212 //Now calculate the new bucket position
3213 const size_type new_n = detail::hash_to_bucket_split<power_2_buckets, incremental>
3214 (hash_value, new_bucket_count, new_bucket_count);
3216 //Update first used bucket cache
3217 if(cache_begin && new_n < new_first_bucket_num)
3218 new_first_bucket_num = new_n;
3220 //If the target bucket is new, transfer the whole group
3221 siterator const last = (priv_last_in_group)(i);
3223 if(same_buffer && new_n == n){
3227 bucket_type &new_b = new_buckets[new_n];
3228 new_b.splice_after(new_b.before_begin(), old_bucket, before_i, last);
3233 const size_type new_n = detail::hash_to_bucket_split<power_2_buckets, incremental>(n, new_bucket_count, new_bucket_count);
3234 if(cache_begin && new_n < new_first_bucket_num)
3235 new_first_bucket_num = new_n;
3236 bucket_type &new_b = new_buckets[new_n];
3237 new_b.splice_after( new_b.before_begin()
3239 , old_bucket.before_begin()
3240 , bucket_plus_vtraits_t::priv_get_last(old_bucket, optimize_multikey_t()));
3244 this->priv_size_traits().set_size(size_backup);
3245 this->priv_split_traits().set_size(new_bucket_count);
3246 if(&new_bucket_traits != &this->priv_bucket_traits()){
3247 this->priv_bucket_traits() = new_bucket_traits;
3249 this->priv_initialize_cache();
3250 this->priv_insertion_update_cache(new_first_bucket_num);
3251 rollback1.release();
3252 rollback2.release();
3255 template <class MaybeConstHashtableImpl, class Cloner, class Disposer>
3256 void priv_clone_from(MaybeConstHashtableImpl &src, Cloner cloner, Disposer disposer)
3258 this->clear_and_dispose(disposer);
3259 if(!constant_time_size || !src.empty()){
3260 const size_type src_bucket_count = src.bucket_count();
3261 const size_type dst_bucket_count = this->bucket_count();
3262 //Check power of two bucket array if the option is activated
3263 BOOST_INTRUSIVE_INVARIANT_ASSERT
3264 (!power_2_buckets || (0 == (src_bucket_count & (src_bucket_count-1))));
3265 BOOST_INTRUSIVE_INVARIANT_ASSERT
3266 (!power_2_buckets || (0 == (dst_bucket_count & (dst_bucket_count-1))));
3267 //If src bucket count is bigger or equal, structural copy is possible
3268 const bool structural_copy = (!incremental) && (src_bucket_count >= dst_bucket_count) &&
3269 (power_2_buckets || (src_bucket_count % dst_bucket_count) == 0);
3270 if(structural_copy){
3271 this->priv_structural_clone_from(src, cloner, disposer);
3274 //Unlike previous cloning algorithm, this can throw
3275 //if cloner, hasher or comparison functor throw
3276 typedef typename detail::if_c< detail::is_const<MaybeConstHashtableImpl>::value
3277 , typename MaybeConstHashtableImpl::const_iterator
3278 , typename MaybeConstHashtableImpl::iterator
3279 >::type clone_iterator;
3280 clone_iterator b(src.begin()), e(src.end());
3281 detail::exception_disposer<hashtable_impl, Disposer> rollback(*this, disposer);
3283 //No need to check for duplicates and insert it in the first position
3284 //as this is an unordered container. So use minimal insertion code
3285 std::size_t const hash_to_store = this->priv_stored_or_compute_hash(*b, store_hash_t());;
3286 size_type const bucket_number = this->priv_hash_to_bucket(hash_to_store);
3287 typedef typename detail::if_c
3288 <detail::is_const<MaybeConstHashtableImpl>::value, const_reference, reference>::type reference_type;
3289 reference_type r = *b;
3290 this->priv_clone_front_in_bucket<reference_type>(bucket_number, r, hash_to_store, cloner);
3297 template<class ValueReference, class Cloner>
3298 void priv_clone_front_in_bucket( size_type const bucket_number
3299 , typename detail::identity<ValueReference>::type src_ref
3300 , std::size_t const hash_to_store, Cloner cloner)
3302 //No need to check for duplicates and insert it in the first position
3303 //as this is an unordered container. So use minimal insertion code
3304 //std::size_t const hash_value = this->priv_stored_or_compute_hash(src_ref, store_hash_t());;
3305 //size_type const bucket_number = this->priv_hash_to_bucket(hash_value);
3306 bucket_type &cur_bucket = this->priv_bucket_pointer()[bucket_number];
3307 siterator const prev(cur_bucket.before_begin());
3308 //Just check if the cloned node is equal to the first inserted value in the new bucket
3309 //as equal src values were contiguous and they should be already inserted in the
3310 //destination bucket.
3311 bool const next_is_in_group = optimize_multikey && !cur_bucket.empty() &&
3312 this->priv_equal()( key_of_value()(src_ref)
3313 , key_of_value()(this->priv_value_from_slist_node((++siterator(prev)).pointed_node())));
3314 this->priv_insert_equal_after_find(*cloner(src_ref), bucket_number, hash_to_store, prev, next_is_in_group);
3317 template <class MaybeConstHashtableImpl, class Cloner, class Disposer>
3318 void priv_structural_clone_from(MaybeConstHashtableImpl &src, Cloner cloner, Disposer disposer)
3320 //First clone the first ones
3321 const size_type src_bucket_count = src.bucket_count();
3322 const size_type dst_bucket_count = this->bucket_count();
3323 const bucket_ptr src_buckets = src.priv_bucket_pointer();
3324 const bucket_ptr dst_buckets = this->priv_bucket_pointer();
3325 size_type constructed = 0;
3326 typedef node_cast_adaptor< detail::node_disposer<Disposer, value_traits, CircularSListAlgorithms>
3327 , slist_node_ptr, node_ptr > NodeDisposer;
3328 NodeDisposer node_disp(disposer, &this->priv_value_traits());
3330 detail::exception_array_disposer<bucket_type, NodeDisposer, size_type>
3331 rollback(dst_buckets[0], node_disp, constructed);
3332 //Now insert the remaining ones using the modulo trick
3333 for( //"constructed" already initialized
3334 ; constructed < src_bucket_count
3336 //Since incremental hashing can't be structurally copied, avoid hash_to_bucket_split
3337 const std::size_t new_n = detail::hash_to_bucket(constructed, dst_bucket_count, detail::bool_<power_2_buckets>());
3338 bucket_type &src_b = src_buckets[constructed];
3339 for( siterator b(src_b.begin()), e(src_b.end()); b != e; ++b){
3340 slist_node_ptr const n(b.pointed_node());
3341 typedef typename detail::if_c
3342 <detail::is_const<MaybeConstHashtableImpl>::value, const_reference, reference>::type reference_type;
3343 reference_type r = this->priv_value_from_slist_node(n);
3344 this->priv_clone_front_in_bucket<reference_type>
3345 (new_n, r, this->priv_stored_hash(n, store_hash_t()), cloner);
3348 this->priv_hasher() = src.priv_hasher();
3349 this->priv_equal() = src.priv_equal();
3351 this->priv_size_traits().set_size(src.priv_size_traits().get_size());
3352 this->priv_split_traits().set_size(dst_bucket_count);
3353 this->priv_insertion_update_cache(0u);
3354 this->priv_erasure_update_cache();
3357 std::size_t priv_hash_to_bucket(std::size_t hash_value) const
3359 return detail::hash_to_bucket_split<power_2_buckets, incremental>
3360 (hash_value, this->priv_bucket_traits().bucket_count(), this->priv_split_traits().get_size());
3363 iterator priv_insert_equal_after_find(reference value, size_type bucket_num, std::size_t hash_value, siterator prev, bool const next_is_in_group)
3365 //Now store hash if needed
3366 node_ptr n = pointer_traits<node_ptr>::pointer_to(this->priv_value_to_node(value));
3367 node_functions_t::store_hash(n, hash_value, store_hash_t());
3368 //Checks for some modes
3369 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(n));
3370 //Shortcut to optimize_multikey cases
3371 group_functions_t::insert_in_group
3372 ( next_is_in_group ? detail::dcast_bucket_ptr<node>((++siterator(prev)).pointed_node()) : n
3373 , n, optimize_multikey_t());
3374 //Update cache and increment size if needed
3375 this->priv_insertion_update_cache(bucket_num);
3376 this->priv_size_traits().increment();
3377 //Insert the element in the bucket after it
3378 return iterator(bucket_type::s_insert_after(prev, *n), &this->get_bucket_value_traits());
3381 template<class KeyType, class KeyHasher, class KeyEqual>
3382 siterator priv_find //In case it is not found previt is bucket.before_begin()
3383 ( const KeyType &key, KeyHasher hash_func
3384 , KeyEqual equal_func, size_type &bucket_number, std::size_t &h, siterator &previt) const
3387 return this->priv_find_with_hash(key, equal_func, bucket_number, h, previt);
3390 template<class KeyType, class KeyEqual>
3391 bool priv_is_value_equal_to_key(const value_type &v, const std::size_t h, const KeyType &key, KeyEqual equal_func) const
3394 return (!compare_hash || this->priv_stored_or_compute_hash(v, store_hash_t()) == h) && equal_func(key, key_of_value()(v));
3397 //return previous iterator to the next equal range group in case
3398 static siterator priv_last_in_group(const siterator &it_first_in_group)
3400 return bucket_type::s_iterator_to
3401 (*group_functions_t::get_last_in_group
3402 (detail::dcast_bucket_ptr<node>(it_first_in_group.pointed_node()), optimize_multikey_t()));
3405 template<class KeyType, class KeyEqual>
3406 siterator priv_find_with_hash //In case it is not found previt is bucket.before_begin()
3407 ( const KeyType &key, KeyEqual equal_func, size_type &bucket_number, const std::size_t h, siterator &previt) const
3409 bucket_number = this->priv_hash_to_bucket(h);
3410 bucket_type &b = this->priv_bucket_pointer()[bucket_number];
3411 previt = b.before_begin();
3412 siterator it = previt;
3413 siterator const endit = b.end();
3415 while(++it != endit){
3416 if(this->priv_is_value_equal_to_key(this->priv_value_from_slist_node(it.pointed_node()), h, key, equal_func)){
3419 previt = it = (priv_last_in_group)(it);
3421 previt = b.before_begin();
3422 return this->priv_invalid_local_it();
3425 template<class KeyType, class KeyHasher, class KeyEqual>
3426 std::pair<siterator, siterator> priv_local_equal_range
3427 ( const KeyType &key
3428 , KeyHasher hash_func
3429 , KeyEqual equal_func
3430 , size_type &found_bucket
3431 , size_type &cnt) const
3433 size_type internal_cnt = 0;
3434 //Let's see if the element is present
3439 std::pair<siterator, siterator> to_return
3440 ( this->priv_find(key, hash_func, equal_func, n_bucket, h, prev)
3441 , this->priv_invalid_local_it());
3443 if(to_return.first != to_return.second){
3444 found_bucket = n_bucket;
3445 //If it's present, find the first that it's not equal in
3447 bucket_type &b = this->priv_bucket_pointer()[n_bucket];
3448 siterator it = to_return.first;
3449 ++internal_cnt; //At least one is found
3450 if(optimize_multikey){
3451 to_return.second = ++(priv_last_in_group)(it);
3452 internal_cnt += boost::intrusive::iterator_distance(++it, to_return.second);
3455 siterator const bend = b.end();
3456 while(++it != bend &&
3457 this->priv_is_value_equal_to_key(this->priv_value_from_slist_node(it.pointed_node()), h, key, equal_func)){
3460 to_return.second = it;
3467 template<class KeyType, class KeyHasher, class KeyEqual>
3468 std::pair<siterator, siterator> priv_equal_range
3469 ( const KeyType &key
3470 , KeyHasher hash_func
3471 , KeyEqual equal_func) const
3476 //Let's see if the element is present
3477 std::pair<siterator, siterator> to_return
3478 (this->priv_local_equal_range(key, hash_func, equal_func, n_bucket, cnt));
3479 //If not, find the next element as ".second" if ".second" local iterator
3480 //is not pointing to an element.
3481 bucket_ptr const bp = this->priv_bucket_pointer();
3482 if(to_return.first != to_return.second &&
3483 to_return.second == bp[n_bucket].end()){
3484 to_return.second = this->priv_invalid_local_it();
3486 for( const size_type max_bucket = this->bucket_count()
3487 ; n_bucket != max_bucket
3489 bucket_type &b = bp[n_bucket];
3491 to_return.second = b.begin();
3499 std::size_t priv_get_bucket_num(siterator it)
3500 { return this->priv_get_bucket_num_hash_dispatch(it, store_hash_t()); }
3502 std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::true_) //store_hash
3504 return this->priv_hash_to_bucket
3505 (this->priv_stored_hash(it.pointed_node(), store_hash_t()));
3508 std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::false_) //NO store_hash
3509 { return this->priv_get_bucket_num_no_hash_store(it, optimize_multikey_t()); }
3511 static siterator priv_get_previous(bucket_type &b, siterator i)
3512 { return bucket_plus_vtraits_t::priv_get_previous(b, i, optimize_multikey_t()); }
3520 , class PackedOptions
3522 struct make_bucket_traits
3524 //Real value traits must be calculated from options
3525 typedef typename detail::get_value_traits
3526 <T, typename PackedOptions::proto_value_traits>::type value_traits;
3528 typedef typename PackedOptions::bucket_traits specified_bucket_traits;
3530 //Real bucket traits must be calculated from options and calculated value_traits
3531 typedef typename get_slist_impl
3532 <typename reduced_slist_node_traits
3533 <typename value_traits::node_traits>::type
3537 detail::if_c< detail::is_same
3538 < specified_bucket_traits
3539 , default_bucket_traits
3541 , bucket_traits_impl<slist_impl>
3542 , specified_bucket_traits
3547 //! Helper metafunction to define a \c hashtable that yields to the same type when the
3548 //! same options (either explicitly or implicitly) are used.
3549 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
3550 template<class T, class ...Options>
3552 template<class T, class O1 = void, class O2 = void
3553 , class O3 = void, class O4 = void
3554 , class O5 = void, class O6 = void
3555 , class O7 = void, class O8 = void
3556 , class O9 = void, class O10= void
3559 struct make_hashtable
3562 typedef typename pack_options
3563 < hashtable_defaults,
3564 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
3565 O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
3569 >::type packed_options;
3571 typedef typename detail::get_value_traits
3572 <T, typename packed_options::proto_value_traits>::type value_traits;
3574 typedef typename make_bucket_traits
3575 <T, false, packed_options>::type bucket_traits;
3577 typedef hashtable_impl
3579 , typename packed_options::key_of_value
3580 , typename packed_options::hash
3581 , typename packed_options::equal
3583 , typename packed_options::size_type
3584 , (std::size_t(false)*hash_bool_flags::unique_keys_pos)
3585 |(std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos)
3586 |(std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos)
3587 |(std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos)
3588 |(std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos)
3589 |(std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos)
3590 > implementation_defined;
3593 typedef implementation_defined type;
3596 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
3598 #if defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
3599 template<class T, class ...Options>
3601 template<class T, class O1, class O2, class O3, class O4, class O5, class O6, class O7, class O8, class O9, class O10>
3604 : public make_hashtable<T,
3605 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
3606 O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
3612 typedef typename make_hashtable<T,
3613 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
3614 O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
3619 BOOST_MOVABLE_BUT_NOT_COPYABLE(hashtable)
3622 typedef typename Base::value_traits value_traits;
3623 typedef typename Base::iterator iterator;
3624 typedef typename Base::const_iterator const_iterator;
3625 typedef typename Base::bucket_ptr bucket_ptr;
3626 typedef typename Base::size_type size_type;
3627 typedef typename Base::hasher hasher;
3628 typedef typename Base::bucket_traits bucket_traits;
3629 typedef typename Base::key_equal key_equal;
3631 //Assert if passed value traits are compatible with the type
3632 BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
3634 BOOST_INTRUSIVE_FORCEINLINE explicit hashtable ( const bucket_traits &b_traits
3635 , const hasher & hash_func = hasher()
3636 , const key_equal &equal_func = key_equal()
3637 , const value_traits &v_traits = value_traits())
3638 : Base(b_traits, hash_func, equal_func, v_traits)
3641 BOOST_INTRUSIVE_FORCEINLINE hashtable(BOOST_RV_REF(hashtable) x)
3642 : Base(BOOST_MOVE_BASE(Base, x))
3645 BOOST_INTRUSIVE_FORCEINLINE hashtable& operator=(BOOST_RV_REF(hashtable) x)
3646 { return static_cast<hashtable&>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
3648 template <class Cloner, class Disposer>
3649 BOOST_INTRUSIVE_FORCEINLINE void clone_from(const hashtable &src, Cloner cloner, Disposer disposer)
3650 { Base::clone_from(src, cloner, disposer); }
3652 template <class Cloner, class Disposer>
3653 BOOST_INTRUSIVE_FORCEINLINE void clone_from(BOOST_RV_REF(hashtable) src, Cloner cloner, Disposer disposer)
3654 { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
3659 } //namespace intrusive
3662 #include <boost/intrusive/detail/config_end.hpp>
3664 #endif //BOOST_INTRUSIVE_HASHTABLE_HPP