]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/intrusive/hashtable.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / intrusive / hashtable.hpp
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2006-2015
4 //
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)
8 //
9 // See http://www.boost.org/libs/intrusive for documentation.
10 //
11 /////////////////////////////////////////////////////////////////////////////
12 #ifndef BOOST_INTRUSIVE_HASHTABLE_HPP
13 #define BOOST_INTRUSIVE_HASHTABLE_HPP
14
15 #include <boost/intrusive/detail/config_begin.hpp>
16 #include <boost/intrusive/intrusive_fwd.hpp>
17
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>
30
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>
36
37 //boost
38 #include <boost/container_hash/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>
43
44 //std C++
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
49
50 #if defined(BOOST_HAS_PRAGMA_ONCE)
51 # pragma once
52 #endif
53
54 namespace boost {
55 namespace intrusive {
56
57 /// @cond
58
59 template<class InputIt, class T>
60 InputIt priv_algo_find(InputIt first, InputIt last, const T& value)
61 {
62 for (; first != last; ++first) {
63 if (*first == value) {
64 return first;
65 }
66 }
67 return last;
68 }
69
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)
73 {
74 typename boost::intrusive::iterator_traits<InputIt>::difference_type ret = 0;
75 for (; first != last; ++first) {
76 if (*first == value) {
77 ret++;
78 }
79 }
80 return ret;
81 }
82
83 template <class ForwardIterator1, class ForwardIterator2>
84 bool priv_algo_is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2)
85 {
86 typedef typename
87 boost::intrusive::iterator_traits<ForwardIterator2>::difference_type
88 distance_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))
93 break;
94 }
95 if (first1 == last1){
96 return true;
97 }
98
99 //Establish last2 assuming equal ranges by iterating over the
100 //rest of the list.
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.
106 }
107 distance_type matches = (priv_algo_count)(first2, last2, *scan);
108 if (0 == matches || (priv_algo_count)(scan, last1, *scan) != matches){
109 return false;
110 }
111 }
112 return true;
113 }
114
115 template<int Dummy = 0>
116 struct prime_list_holder
117 {
118 private:
119
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_)
122 {
123 return n < std::size_t(SizeType(-1)) ? static_cast<SizeType>(n) : SizeType(-1);
124 }
125
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_)
128 {
129 return static_cast<SizeType>(n);
130 }
131
132 template <class SizeType> //sizeof(SizeType) > sizeof(std::size_t)
133 static SizeType suggested_upper_bucket_count_dispatch(SizeType n, detail::true_)
134 {
135 std::size_t const c = n > std::size_t(-1)
136 ? std::size_t(-1)
137 : suggested_upper_bucket_count_impl(static_cast<std::size_t>(n));
138 return static_cast<SizeType>(c);
139 }
140
141 template <class SizeType> //sizeof(SizeType) > sizeof(std::size_t)
142 static SizeType suggested_lower_bucket_count_dispatch(SizeType n, detail::true_)
143 {
144 std::size_t const c = n > std::size_t(-1)
145 ? std::size_t(-1)
146 : suggested_lower_bucket_count_impl(static_cast<std::size_t>(n));
147 return static_cast<SizeType>(c);
148 }
149
150 template <class SizeType>
151 static SizeType suggested_upper_bucket_count_dispatch(SizeType n, detail::false_)
152 {
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))>());
155
156 }
157
158 template <class SizeType>
159 static SizeType suggested_lower_bucket_count_dispatch(SizeType n, detail::false_)
160 {
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))>());
163 }
164
165 static const std::size_t prime_list[];
166 static const std::size_t prime_list_size;
167
168 static std::size_t suggested_lower_bucket_count_impl(std::size_t n)
169 {
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);
176 return *bound;
177 }
178
179 static std::size_t suggested_upper_bucket_count_impl(std::size_t n)
180 {
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);
185 return *bound;
186 }
187
188 public:
189
190 template <class SizeType>
191 static BOOST_INTRUSIVE_FORCEINLINE SizeType suggested_upper_bucket_count(SizeType n)
192 {
193 return (suggested_upper_bucket_count_dispatch)(n, detail::bool_<(sizeof(SizeType) > sizeof(std::size_t))>());
194 }
195
196 template <class SizeType>
197 static BOOST_INTRUSIVE_FORCEINLINE SizeType suggested_lower_bucket_count(SizeType n)
198 {
199 return (suggested_lower_bucket_count_dispatch)(n, detail::bool_<(sizeof(SizeType) > sizeof(std::size_t))>());
200 }
201 };
202
203 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
204
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)
212 #endif
213
214 template<int Dummy>
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
251 #else
252 BOOST_INTRUSIVE_PRIME_C(4294967291), BOOST_INTRUSIVE_PRIME_C(4294967295) //Upper limit, just in case
253 #endif
254 };
255
256 #undef BOOST_INTRUSIVE_PRIME_C
257 #undef BOOST_INTRUSIVE_64_BIT_SIZE_T
258
259 #endif //#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
260
261 template<int Dummy>
262 const std::size_t prime_list_holder<Dummy>::prime_list_size
263 = sizeof(prime_list)/sizeof(std::size_t);
264
265 struct hash_bool_flags
266 {
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;
273 };
274
275 namespace detail {
276
277 template<class SupposedValueTraits>
278 struct get_slist_impl_from_supposed_value_traits
279 {
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
285 <node_traits>::type
286 >::type type;
287 };
288
289 template<class SupposedValueTraits>
290 struct unordered_bucket_impl
291 {
292 typedef typename
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;
297 };
298
299 template<class SupposedValueTraits>
300 struct unordered_bucket_ptr_impl
301 {
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;
306
307 typedef typename pointer_traits
308 <node_ptr>::template rebind_pointer
309 < bucket_type >::type implementation_defined;
310 typedef implementation_defined type;
311 };
312
313 template <class T>
314 struct store_hash_is_true
315 {
316 template<bool Add>
317 struct two_or_three {yes_type _[2u + (unsigned)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)*2u;
321 };
322
323 template <class T>
324 struct optimize_multikey_is_true
325 {
326 template<bool Add>
327 struct two_or_three {yes_type _[2u + (unsigned)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)*2u;
331 };
332
333 struct insert_commit_data_impl
334 {
335 std::size_t hash;
336 };
337
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)
341 {
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));
344 }
345
346 template<class NodeTraits>
347 struct group_functions
348 {
349 // A group is reverse-linked
350 //
351 // A is "first in group"
352 // C is "last in group"
353 // __________________
354 // | _____ _____ |
355 // | | | | | | <- Group links
356 // ^ V ^ V ^ V
357 // _ _ _ _
358 // A|_| B|_| C|_| D|_|
359 //
360 // ^ | ^ | ^ | ^ V <- Bucket links
361 // _ _____| |_____| |______| |____| |
362 // |B| |
363 // ^________________________________|
364 //
365
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;
376
377 static slist_node_ptr get_bucket_before_begin
378 (slist_node_ptr bucket_beg, slist_node_ptr bucket_end, node_ptr p)
379 {
380 //First find the last node of p's group.
381 //This requires checking the first node of the next group or
382 //the bucket node.
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)){
387 prev_node = nxt;
388 nxt = node_traits::get_next(nxt);
389 }
390
391 //If we've reached the bucket node just return it.
392 if(bucket_beg <= nxt && nxt <= bucket_end){
393 return nxt;
394 }
395
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);
400
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);
405 }
406 return possible_end;
407 }
408
409 static node_ptr get_prev_to_first_in_group(slist_node_ptr bucket_node, node_ptr first_in_group)
410 {
411 node_ptr nb = detail::dcast_bucket_ptr<node>(bucket_node);
412 node_ptr n;
413 while((n = node_traits::get_next(nb)) != first_in_group){
414 nb = group_traits::get_next(n); //go to last in group
415 }
416 return nb;
417 }
418
419 static void erase_from_group(slist_node_ptr end_ptr, node_ptr to_erase_ptr, detail::true_)
420 {
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);
426 }
427 }
428
429 BOOST_INTRUSIVE_FORCEINLINE static void erase_from_group(slist_node_ptr, node_ptr, detail::false_)
430 {}
431
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); }
434
435 BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_last_in_group(node_ptr n, detail::false_)
436 { return n; }
437
438 static node_ptr get_first_in_group(node_ptr n, detail::true_)
439 {
440 node_ptr ng;
441 while(n == node_traits::get_next((ng = group_traits::get_next(n)))){
442 n = ng;
443 }
444 return n;
445 }
446
447 BOOST_INTRUSIVE_FORCEINLINE static node_ptr next_group_if_first_in_group(node_ptr ptr)
448 { return node_traits::get_next(group_traits::get_next(ptr)); }
449
450 BOOST_INTRUSIVE_FORCEINLINE static node_ptr get_first_in_group(node_ptr n, detail::false_)
451 { return n; }
452
453 BOOST_INTRUSIVE_FORCEINLINE static void insert_in_group(node_ptr first_in_group, node_ptr n, true_)
454 { group_algorithms::link_after(first_in_group, n); }
455
456 static void insert_in_group(node_ptr, node_ptr, false_)
457 {}
458
459 static node_ptr split_group(node_ptr const new_first_in_group)
460 {
461 node_ptr const first((get_first_in_group)(new_first_in_group, detail::true_()));
462 if(first != new_first_in_group){
463 node_ptr const last = group_traits::get_next(first);
464 group_traits::set_next(first, group_traits::get_next(new_first_in_group));
465 group_traits::set_next(new_first_in_group, last);
466 }
467 return first;
468 }
469 };
470
471 template<class BucketType, class SplitTraits>
472 class incremental_rehash_rollback
473 {
474 private:
475 typedef BucketType bucket_type;
476 typedef SplitTraits split_traits;
477
478 incremental_rehash_rollback();
479 incremental_rehash_rollback & operator=(const incremental_rehash_rollback &);
480 incremental_rehash_rollback (const incremental_rehash_rollback &);
481
482 public:
483 incremental_rehash_rollback
484 (bucket_type &source_bucket, bucket_type &destiny_bucket, split_traits &split_tr)
485 : source_bucket_(source_bucket), destiny_bucket_(destiny_bucket)
486 , split_traits_(split_tr), released_(false)
487 {}
488
489 BOOST_INTRUSIVE_FORCEINLINE void release()
490 { released_ = true; }
491
492 ~incremental_rehash_rollback()
493 {
494 if(!released_){
495 //If an exception is thrown, just put all moved nodes back in the old bucket
496 //and move back the split mark.
497 destiny_bucket_.splice_after(destiny_bucket_.before_begin(), source_bucket_);
498 split_traits_.decrement();
499 }
500 }
501
502 private:
503 bucket_type &source_bucket_;
504 bucket_type &destiny_bucket_;
505 split_traits &split_traits_;
506 bool released_;
507 };
508
509 template<class NodeTraits>
510 struct node_functions
511 {
512 BOOST_INTRUSIVE_FORCEINLINE static void store_hash(typename NodeTraits::node_ptr p, std::size_t h, true_)
513 { return NodeTraits::set_hash(p, h); }
514
515 BOOST_INTRUSIVE_FORCEINLINE static void store_hash(typename NodeTraits::node_ptr, std::size_t, false_)
516 {}
517 };
518
519 BOOST_INTRUSIVE_FORCEINLINE std::size_t hash_to_bucket(std::size_t hash_value, std::size_t bucket_cnt, detail::false_)
520 { return hash_value % bucket_cnt; }
521
522 BOOST_INTRUSIVE_FORCEINLINE std::size_t hash_to_bucket(std::size_t hash_value, std::size_t bucket_cnt, detail::true_)
523 { return hash_value & (bucket_cnt - 1); }
524
525 template<bool Power2Buckets, bool Incremental>
526 std::size_t hash_to_bucket_split(std::size_t hash_value, std::size_t bucket_cnt, std::size_t split)
527 {
528 std::size_t bucket_number = detail::hash_to_bucket(hash_value, bucket_cnt, detail::bool_<Power2Buckets>());
529 BOOST_IF_CONSTEXPR(Incremental)
530 bucket_number -= static_cast<std::size_t>(bucket_number >= split)*(bucket_cnt/2);
531 return bucket_number;
532 }
533
534 } //namespace detail {
535
536 //!This metafunction will obtain the type of a bucket
537 //!from the value_traits or hook option to be used with
538 //!a hash container.
539 template<class ValueTraitsOrHookOption>
540 struct unordered_bucket
541 : public detail::unordered_bucket_impl
542 <typename ValueTraitsOrHookOption::
543 template pack<empty>::proto_value_traits
544 >
545 {};
546
547 //!This metafunction will obtain the type of a bucket pointer
548 //!from the value_traits or hook option to be used with
549 //!a hash container.
550 template<class ValueTraitsOrHookOption>
551 struct unordered_bucket_ptr
552 : public detail::unordered_bucket_ptr_impl
553 <typename ValueTraitsOrHookOption::
554 template pack<empty>::proto_value_traits
555 >
556 {};
557
558 //!This metafunction will obtain the type of the default bucket traits
559 //!(when the user does not specify the bucket_traits<> option) from the
560 //!value_traits or hook option to be used with
561 //!a hash container.
562 template<class ValueTraitsOrHookOption>
563 struct unordered_default_bucket_traits
564 {
565 typedef typename ValueTraitsOrHookOption::
566 template pack<empty>::proto_value_traits supposed_value_traits;
567 typedef typename detail::
568 get_slist_impl_from_supposed_value_traits
569 <supposed_value_traits>::type slist_impl;
570 typedef bucket_traits_impl
571 <slist_impl> implementation_defined;
572 typedef implementation_defined type;
573 };
574
575 struct default_bucket_traits;
576
577 //hashtable default hook traits
578 struct default_hashtable_hook_applier
579 { template <class T> struct apply{ typedef typename T::default_hashtable_hook type; }; };
580
581 template<>
582 struct is_default_hook_tag<default_hashtable_hook_applier>
583 { static const bool value = true; };
584
585 struct hashtable_defaults
586 {
587 typedef default_hashtable_hook_applier proto_value_traits;
588 typedef std::size_t size_type;
589 typedef void key_of_value;
590 typedef void equal;
591 typedef void hash;
592 typedef default_bucket_traits bucket_traits;
593 static const bool constant_time_size = true;
594 static const bool power_2_buckets = false;
595 static const bool cache_begin = false;
596 static const bool compare_hash = false;
597 static const bool incremental = false;
598 };
599
600 template<class ValueTraits, bool IsConst>
601 struct downcast_node_to_value_t
602 : public detail::node_to_value<ValueTraits, IsConst>
603 {
604 typedef detail::node_to_value<ValueTraits, IsConst> base_t;
605 typedef typename base_t::result_type result_type;
606 typedef ValueTraits value_traits;
607 typedef typename get_slist_impl
608 <typename reduced_slist_node_traits
609 <typename value_traits::node_traits>::type
610 >::type slist_impl;
611 typedef typename detail::add_const_if_c
612 <typename slist_impl::node, IsConst>::type & first_argument_type;
613 typedef typename detail::add_const_if_c
614 < typename ValueTraits::node_traits::node
615 , IsConst>::type & intermediate_argument_type;
616 typedef typename pointer_traits
617 <typename ValueTraits::pointer>::
618 template rebind_pointer
619 <const ValueTraits>::type const_value_traits_ptr;
620
621 BOOST_INTRUSIVE_FORCEINLINE downcast_node_to_value_t(const_value_traits_ptr ptr)
622 : base_t(ptr)
623 {}
624
625 BOOST_INTRUSIVE_FORCEINLINE result_type operator()(first_argument_type arg) const
626 { return this->base_t::operator()(static_cast<intermediate_argument_type>(arg)); }
627 };
628
629 template<class F, class SlistNodePtr, class NodePtr>
630 struct node_cast_adaptor
631 //Use public inheritance to avoid MSVC bugs with closures
632 : public detail::ebo_functor_holder<F>
633 {
634 typedef detail::ebo_functor_holder<F> base_t;
635
636 typedef typename pointer_traits<SlistNodePtr>::element_type slist_node;
637 typedef typename pointer_traits<NodePtr>::element_type node;
638
639 template<class ConvertibleToF, class RealValuTraits>
640 BOOST_INTRUSIVE_FORCEINLINE node_cast_adaptor(const ConvertibleToF &c2f, const RealValuTraits *traits)
641 : base_t(base_t(c2f, traits))
642 {}
643
644 BOOST_INTRUSIVE_FORCEINLINE typename base_t::node_ptr operator()(const slist_node &to_clone)
645 { return base_t::operator()(static_cast<const node &>(to_clone)); }
646
647 BOOST_INTRUSIVE_FORCEINLINE void operator()(SlistNodePtr to_clone)
648 {
649 base_t::operator()(pointer_traits<NodePtr>::pointer_to(static_cast<node &>(*to_clone)));
650 }
651 };
652
653 //bucket_plus_vtraits stores ValueTraits + BucketTraits
654 //this data is needed by iterators to obtain the
655 //value from the iterator and detect the bucket
656 template<class ValueTraits, class BucketTraits>
657 struct bucket_plus_vtraits
658 {
659 typedef BucketTraits bucket_traits;
660 typedef ValueTraits value_traits;
661
662 static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
663
664 typedef typename
665 detail::get_slist_impl_from_supposed_value_traits
666 <value_traits>::type slist_impl;
667 typedef typename value_traits::node_traits node_traits;
668 typedef unordered_group_adapter<node_traits> group_traits;
669 typedef typename slist_impl::iterator siterator;
670 typedef bucket_impl<slist_impl> bucket_type;
671 typedef detail::group_functions<node_traits> group_functions_t;
672 typedef typename slist_impl::node_algorithms node_algorithms;
673 typedef typename slist_impl::node_ptr slist_node_ptr;
674 typedef typename node_traits::node_ptr node_ptr;
675 typedef typename node_traits::node node;
676 typedef typename value_traits::value_type value_type;
677 typedef typename value_traits::pointer pointer;
678 typedef typename value_traits::const_pointer const_pointer;
679 typedef typename pointer_traits<pointer>::reference reference;
680 typedef typename pointer_traits
681 <const_pointer>::reference const_reference;
682 typedef circular_slist_algorithms<group_traits> group_algorithms;
683 typedef typename pointer_traits
684 <typename value_traits::pointer>::
685 template rebind_pointer
686 <const value_traits>::type const_value_traits_ptr;
687 typedef typename pointer_traits
688 <typename value_traits::pointer>::
689 template rebind_pointer
690 <const bucket_plus_vtraits>::type const_bucket_value_traits_ptr;
691 typedef typename detail::unordered_bucket_ptr_impl
692 <value_traits>::type bucket_ptr;
693
694 template<class BucketTraitsType>
695 BOOST_INTRUSIVE_FORCEINLINE bucket_plus_vtraits(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits)
696 : data(val_traits, ::boost::forward<BucketTraitsType>(b_traits))
697 {}
698
699 BOOST_INTRUSIVE_FORCEINLINE bucket_plus_vtraits & operator =(const bucket_plus_vtraits &x)
700 { data.bucket_traits_ = x.data.bucket_traits_; return *this; }
701
702 BOOST_INTRUSIVE_FORCEINLINE const_value_traits_ptr priv_value_traits_ptr() const
703 { return pointer_traits<const_value_traits_ptr>::pointer_to(this->priv_value_traits()); }
704
705 //bucket_value_traits
706 //
707 BOOST_INTRUSIVE_FORCEINLINE const bucket_plus_vtraits &get_bucket_value_traits() const
708 { return *this; }
709
710 BOOST_INTRUSIVE_FORCEINLINE bucket_plus_vtraits &get_bucket_value_traits()
711 { return *this; }
712
713 BOOST_INTRUSIVE_FORCEINLINE const_bucket_value_traits_ptr bucket_value_traits_ptr() const
714 { return pointer_traits<const_bucket_value_traits_ptr>::pointer_to(this->get_bucket_value_traits()); }
715
716 //value traits
717 //
718 BOOST_INTRUSIVE_FORCEINLINE const value_traits &priv_value_traits() const
719 { return this->data; }
720
721 BOOST_INTRUSIVE_FORCEINLINE value_traits &priv_value_traits()
722 { return this->data; }
723
724 //bucket_traits
725 //
726 BOOST_INTRUSIVE_FORCEINLINE const bucket_traits &priv_bucket_traits() const
727 { return this->data.bucket_traits_; }
728
729 BOOST_INTRUSIVE_FORCEINLINE bucket_traits &priv_bucket_traits()
730 { return this->data.bucket_traits_; }
731
732 //bucket operations
733 BOOST_INTRUSIVE_FORCEINLINE bucket_ptr priv_bucket_pointer() const BOOST_NOEXCEPT
734 { return this->priv_bucket_traits().bucket_begin(); }
735
736 std::size_t priv_bucket_count() const BOOST_NOEXCEPT
737 {
738 const std::size_t bc = this->priv_bucket_traits().bucket_count();
739 return bc;
740 }
741
742 BOOST_INTRUSIVE_FORCEINLINE bucket_type &priv_bucket(std::size_t n) const BOOST_NOEXCEPT
743 {
744 BOOST_INTRUSIVE_INVARIANT_ASSERT(n < this->priv_bucket_traits().bucket_count());
745 return priv_bucket_pointer()[std::ptrdiff_t(n)];
746 }
747
748 BOOST_INTRUSIVE_FORCEINLINE bucket_ptr priv_invalid_bucket() const
749 {
750 const bucket_traits &rbt = this->priv_bucket_traits();
751 return rbt.bucket_begin() + std::ptrdiff_t(rbt.bucket_count());
752 }
753
754 BOOST_INTRUSIVE_FORCEINLINE siterator priv_invalid_local_it() const
755 { return this->priv_bucket_traits().bucket_begin()->before_begin(); }
756
757 template<class NodeDisposer>
758 static std::size_t priv_erase_from_single_bucket(bucket_type &b, siterator sbefore_first, siterator slast, NodeDisposer node_disposer, detail::true_) //optimize multikey
759 {
760 std::size_t n = 0;
761 siterator const sfirst(++siterator(sbefore_first));
762 if(sfirst != slast){
763 node_ptr const nf = detail::dcast_bucket_ptr<node>(sfirst.pointed_node());
764 node_ptr const nl = detail::dcast_bucket_ptr<node>(slast.pointed_node());
765 node_ptr const ne = detail::dcast_bucket_ptr<node>(b.end().pointed_node());
766
767 if(group_functions_t::next_group_if_first_in_group(nf) != nf) {
768 // The node is at the beginning of a group.
769 if(nl != ne){
770 group_functions_t::split_group(nl);
771 }
772 }
773 else {
774 node_ptr const group1 = group_functions_t::split_group(nf);
775 if(nl != ne) {
776 node_ptr const group2 = group_functions_t::split_group(ne);
777 if(nf == group2) { //Both first and last in the same group
778 //so join group1 and group2
779 node_ptr const end1 = group_traits::get_next(group1);
780 node_ptr const end2 = group_traits::get_next(group2);
781 group_traits::set_next(group1, end2);
782 group_traits::set_next(group2, end1);
783 }
784 }
785 }
786
787 siterator it(++siterator(sbefore_first));
788 while(it != slast){
789 node_disposer((it++).pointed_node());
790 ++n;
791 }
792 b.erase_after(sbefore_first, slast);
793 }
794 return n;
795 }
796
797 template<class NodeDisposer>
798 static std::size_t priv_erase_from_single_bucket(bucket_type &b, siterator sbefore_first, siterator slast, NodeDisposer node_disposer, detail::false_) //optimize multikey
799 {
800 std::size_t n = 0;
801 siterator it(++siterator(sbefore_first));
802 while(it != slast){
803 node_disposer((it++).pointed_node());
804 ++n;
805 }
806 b.erase_after(sbefore_first, slast);
807 return n;
808 }
809
810 template<class NodeDisposer>
811 static void priv_erase_node(bucket_type &b, siterator i, NodeDisposer node_disposer, detail::true_) //optimize multikey
812 {
813 node_ptr const ne(detail::dcast_bucket_ptr<node>(b.end().pointed_node()));
814 node_ptr n(detail::dcast_bucket_ptr<node>(i.pointed_node()));
815 node_ptr pos = node_traits::get_next(group_traits::get_next(n));
816 node_ptr bn;
817 node_ptr nn(node_traits::get_next(n));
818
819 if(pos != n) {
820 //Node is the first of the group
821 bn = group_functions_t::get_prev_to_first_in_group(ne, n);
822
823 //Unlink the rest of the group if it's not the last node of its group
824 if(nn != ne && group_traits::get_next(nn) == n){
825 group_algorithms::unlink_after(nn);
826 }
827 }
828 else if(nn != ne && group_traits::get_next(nn) == n){
829 //Node is not the end of the group
830 bn = group_traits::get_next(n);
831 group_algorithms::unlink_after(nn);
832 }
833 else{
834 //Node is the end of the group
835 bn = group_traits::get_next(n);
836 node_ptr const x(group_algorithms::get_previous_node(n));
837 group_algorithms::unlink_after(x);
838 }
839 b.erase_after_and_dispose(bucket_type::s_iterator_to(*bn), node_disposer);
840 }
841
842 template<class NodeDisposer>
843 BOOST_INTRUSIVE_FORCEINLINE static void priv_erase_node(bucket_type &b, siterator i, NodeDisposer node_disposer, detail::false_) //optimize multikey
844 { b.erase_after_and_dispose(b.previous(i), node_disposer); }
845
846 template<class NodeDisposer, bool OptimizeMultikey>
847 std::size_t priv_erase_node_range( siterator const &before_first_it, std::size_t const first_bucket
848 , siterator const &last_it, std::size_t const last_bucket
849 , NodeDisposer node_disposer, detail::bool_<OptimizeMultikey> optimize_multikey_tag)
850 {
851 std::size_t num_erased(0);
852 siterator last_step_before_it;
853 if(first_bucket != last_bucket){
854 bucket_type *b = &this->priv_bucket(0);
855 num_erased += this->priv_erase_from_single_bucket
856 (b[first_bucket], before_first_it, b[first_bucket].end(), node_disposer, optimize_multikey_tag);
857 for(std::size_t i = 0, n = (last_bucket - first_bucket - 1); i != n; ++i){
858 num_erased += this->priv_erase_whole_bucket(b[first_bucket+i+1], node_disposer);
859 }
860 last_step_before_it = b[last_bucket].before_begin();
861 }
862 else{
863 last_step_before_it = before_first_it;
864 }
865 num_erased += this->priv_erase_from_single_bucket
866 (this->priv_bucket(last_bucket), last_step_before_it, last_it, node_disposer, optimize_multikey_tag);
867 return num_erased;
868 }
869
870 static siterator priv_get_last(bucket_type &b, detail::true_) //optimize multikey
871 {
872 //First find the last node of p's group.
873 //This requires checking the first node of the next group or
874 //the bucket node.
875 slist_node_ptr end_ptr(b.end().pointed_node());
876 node_ptr possible_end(node_traits::get_next( detail::dcast_bucket_ptr<node>(end_ptr)));
877 node_ptr last_node_group(possible_end);
878
879 while(end_ptr != possible_end){
880 last_node_group = group_traits::get_next(detail::dcast_bucket_ptr<node>(possible_end));
881 possible_end = node_traits::get_next(last_node_group);
882 }
883 return bucket_type::s_iterator_to(*last_node_group);
884 }
885
886 template<class NodeDisposer>
887 std::size_t priv_erase_whole_bucket(bucket_type &b, NodeDisposer node_disposer)
888 {
889 std::size_t num_erased = 0;
890 siterator b_begin(b.before_begin());
891 siterator nxt(b_begin);
892 ++nxt;
893 siterator const end_sit(b.end());
894 while(nxt != end_sit){
895 //No need to init group links as we'll delete all bucket nodes
896 nxt = bucket_type::s_erase_after_and_dispose(b_begin, node_disposer);
897 ++num_erased;
898 }
899 return num_erased;
900 }
901
902 BOOST_INTRUSIVE_FORCEINLINE static siterator priv_get_last(bucket_type &b, detail::false_) //NOT optimize multikey
903 { return b.previous(b.end()); }
904
905 static siterator priv_get_previous(bucket_type &b, siterator i, detail::true_) //optimize multikey
906 {
907 node_ptr const elem(detail::dcast_bucket_ptr<node>(i.pointed_node()));
908 node_ptr const prev_in_group(group_traits::get_next(elem));
909 bool const first_in_group = node_traits::get_next(prev_in_group) != elem;
910 typename bucket_type::node &n = first_in_group
911 ? *group_functions_t::get_prev_to_first_in_group(b.end().pointed_node(), elem)
912 : *group_traits::get_next(elem)
913 ;
914 return bucket_type::s_iterator_to(n);
915 }
916
917 BOOST_INTRUSIVE_FORCEINLINE static siterator priv_get_previous(bucket_type &b, siterator i, detail::false_) //NOT optimize multikey
918 { return b.previous(i); }
919
920 std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::true_) //optimize multikey
921 {
922 const bucket_type &f = this->priv_bucket(0u);
923 const bucket_type &l = this->priv_bucket(this->priv_bucket_count() - 1u);
924 slist_node_ptr bb = group_functions_t::get_bucket_before_begin
925 ( f.end().pointed_node()
926 , l.end().pointed_node()
927 , detail::dcast_bucket_ptr<node>(it.pointed_node()));
928 //Now get the bucket_impl from the iterator
929 const bucket_type &b = static_cast<const bucket_type&>
930 (bucket_type::slist_type::container_from_end_iterator(bucket_type::s_iterator_to(*bb)));
931 //Now just calculate the index b has in the bucket array
932 return static_cast<std::size_t>(&b - &f);
933 }
934
935 std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::false_) //NO optimize multikey
936 {
937 const bucket_type &f = this->priv_bucket(0u);
938 const bucket_type &l = this->priv_bucket(this->priv_bucket_count() - 1u);
939 slist_node_ptr first_ptr(f.cend().pointed_node())
940 , last_ptr (l.cend().pointed_node());
941
942 //The end node is embedded in the singly linked list:
943 //iterate until we reach it.
944 while(!(std::less_equal<slist_node_ptr>()(first_ptr, it.pointed_node()) &&
945 std::less_equal<slist_node_ptr>()(it.pointed_node(), last_ptr))){
946 ++it;
947 }
948 //Now get the bucket_impl from the iterator
949 const bucket_type &b = static_cast<const bucket_type&>
950 (bucket_type::container_from_end_iterator(it));
951
952 //Now just calculate the index b has in the bucket array
953 return static_cast<std::size_t>(&b - &f);
954 }
955
956 BOOST_INTRUSIVE_FORCEINLINE static std::size_t priv_stored_hash(slist_node_ptr n, detail::true_) //store_hash
957 { return node_traits::get_hash(detail::dcast_bucket_ptr<node>(n)); }
958
959 BOOST_INTRUSIVE_FORCEINLINE static std::size_t priv_stored_hash(slist_node_ptr, detail::false_) //NO store_hash
960 { return std::size_t(-1); }
961
962 BOOST_INTRUSIVE_FORCEINLINE node &priv_value_to_node(reference v)
963 { return *this->priv_value_traits().to_node_ptr(v); }
964
965 BOOST_INTRUSIVE_FORCEINLINE const node &priv_value_to_node(const_reference v) const
966 { return *this->priv_value_traits().to_node_ptr(v); }
967
968 BOOST_INTRUSIVE_FORCEINLINE reference priv_value_from_slist_node(slist_node_ptr n)
969 { return *this->priv_value_traits().to_value_ptr(detail::dcast_bucket_ptr<node>(n)); }
970
971 BOOST_INTRUSIVE_FORCEINLINE const_reference priv_value_from_slist_node(slist_node_ptr n) const
972 { return *this->priv_value_traits().to_value_ptr(detail::dcast_bucket_ptr<node>(n)); }
973
974 void priv_clear_buckets(const bucket_ptr buckets_ptr, const std::size_t bucket_cnt)
975 {
976 bucket_ptr buckets_it = buckets_ptr;
977 for(std::size_t bucket_i = 0; bucket_i != bucket_cnt; ++buckets_it, ++bucket_i){
978 BOOST_IF_CONSTEXPR(safemode_or_autounlink){
979 buckets_it->clear_and_dispose(detail::init_disposer<node_algorithms>());
980 }
981 else{
982 buckets_it->clear();
983 }
984 }
985 }
986
987 BOOST_INTRUSIVE_FORCEINLINE std::size_t priv_stored_or_compute_hash(const value_type &v, detail::true_) const //For store_hash == true
988 { return node_traits::get_hash(this->priv_value_traits().to_node_ptr(v)); }
989
990 typedef hashtable_iterator<bucket_plus_vtraits, false> iterator;
991 typedef hashtable_iterator<bucket_plus_vtraits, true> const_iterator;
992
993 BOOST_INTRUSIVE_FORCEINLINE iterator end() BOOST_NOEXCEPT
994 { return iterator(this->priv_invalid_local_it(), 0); }
995
996 BOOST_INTRUSIVE_FORCEINLINE const_iterator end() const BOOST_NOEXCEPT
997 { return this->cend(); }
998
999 BOOST_INTRUSIVE_FORCEINLINE const_iterator cend() const BOOST_NOEXCEPT
1000 { return const_iterator(this->priv_invalid_local_it(), 0); }
1001
1002 //Public functions:
1003 struct data_type : public ValueTraits
1004 {
1005 template<class BucketTraitsType>
1006 BOOST_INTRUSIVE_FORCEINLINE data_type(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits)
1007 : ValueTraits(val_traits), bucket_traits_(::boost::forward<BucketTraitsType>(b_traits))
1008 {}
1009
1010 bucket_traits bucket_traits_;
1011 } data;
1012 };
1013
1014 template<class Hash, class>
1015 struct get_hash
1016 {
1017 typedef Hash type;
1018 };
1019
1020 template<class T>
1021 struct get_hash<void, T>
1022 {
1023 typedef ::boost::hash<T> type;
1024 };
1025
1026 template<class EqualTo, class>
1027 struct get_equal_to
1028 {
1029 typedef EqualTo type;
1030 };
1031
1032 template<class T>
1033 struct get_equal_to<void, T>
1034 {
1035 typedef std::equal_to<T> type;
1036 };
1037
1038 template<class KeyOfValue, class T>
1039 struct get_hash_key_of_value
1040 {
1041 typedef KeyOfValue type;
1042 };
1043
1044 template<class T>
1045 struct get_hash_key_of_value<void, T>
1046 {
1047 typedef ::boost::intrusive::detail::identity<T> type;
1048 };
1049
1050 template<class T, class VoidOrKeyOfValue>
1051 struct hash_key_types_base
1052 {
1053 typedef typename get_hash_key_of_value
1054 < VoidOrKeyOfValue, T>::type key_of_value;
1055 typedef typename key_of_value::type key_type;
1056 };
1057
1058 template<class T, class VoidOrKeyOfValue, class VoidOrKeyHash>
1059 struct hash_key_hash
1060 : get_hash
1061 < VoidOrKeyHash
1062 , typename hash_key_types_base<T, VoidOrKeyOfValue>::key_type
1063 >
1064 {};
1065
1066 template<class T, class VoidOrKeyOfValue, class VoidOrKeyEqual>
1067 struct hash_key_equal
1068 : get_equal_to
1069 < VoidOrKeyEqual
1070 , typename hash_key_types_base<T, VoidOrKeyOfValue>::key_type
1071 >
1072
1073 {};
1074
1075 //bucket_hash_t
1076 //Stores bucket_plus_vtraits plust the hash function
1077 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class BucketTraits>
1078 struct bucket_hash_t
1079 //Use public inheritance to avoid MSVC bugs with closures
1080 : public detail::ebo_functor_holder
1081 <typename hash_key_hash < typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits::value_type
1082 , VoidOrKeyOfValue
1083 , VoidOrKeyHash
1084 >::type
1085 >
1086 , bucket_plus_vtraits<ValueTraits, BucketTraits> //4
1087 {
1088 typedef typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits value_traits;
1089 typedef typename value_traits::value_type value_type;
1090 typedef typename value_traits::node_traits node_traits;
1091 typedef hash_key_hash
1092 < value_type, VoidOrKeyOfValue, VoidOrKeyHash> hash_key_hash_t;
1093 typedef typename hash_key_hash_t::type hasher;
1094 typedef typename hash_key_types_base<value_type, VoidOrKeyOfValue>::key_of_value key_of_value;
1095
1096 typedef BucketTraits bucket_traits;
1097 typedef bucket_plus_vtraits<ValueTraits, BucketTraits> bucket_plus_vtraits_t;
1098 typedef detail::ebo_functor_holder<hasher> base_t;
1099
1100 template<class BucketTraitsType>
1101 BOOST_INTRUSIVE_FORCEINLINE bucket_hash_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h)
1102 : detail::ebo_functor_holder<hasher>(h), bucket_plus_vtraits_t(val_traits, ::boost::forward<BucketTraitsType>(b_traits))
1103 {}
1104
1105 BOOST_INTRUSIVE_FORCEINLINE const hasher &priv_hasher() const
1106 { return this->base_t::get(); }
1107
1108 hasher &priv_hasher()
1109 { return this->base_t::get(); }
1110
1111 using bucket_plus_vtraits_t::priv_stored_or_compute_hash; //For store_hash == true
1112
1113 BOOST_INTRUSIVE_FORCEINLINE std::size_t priv_stored_or_compute_hash(const value_type &v, detail::false_) const //For store_hash == false
1114 { return this->priv_hasher()(key_of_value()(v)); }
1115 };
1116
1117 template<class ValueTraits, class BucketTraits, class VoidOrKeyOfValue, class VoidOrKeyEqual>
1118 struct hashtable_equal_holder
1119 {
1120 typedef detail::ebo_functor_holder
1121 < typename hash_key_equal < typename bucket_plus_vtraits<ValueTraits, BucketTraits>::value_traits::value_type
1122 , VoidOrKeyOfValue
1123 , VoidOrKeyEqual
1124 >::type
1125 > type;
1126 };
1127
1128
1129 //bucket_hash_equal_t
1130 //Stores bucket_hash_t and the equality function when the first
1131 //non-empty bucket shall not be cached.
1132 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class VoidOrKeyEqual, class BucketTraits, bool>
1133 struct bucket_hash_equal_t
1134 //Use public inheritance to avoid MSVC bugs with closures
1135 : public bucket_hash_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, BucketTraits> //3
1136 , public hashtable_equal_holder<ValueTraits, BucketTraits, VoidOrKeyOfValue, VoidOrKeyEqual>::type //equal
1137 {
1138 typedef typename hashtable_equal_holder
1139 <ValueTraits, BucketTraits, VoidOrKeyOfValue, VoidOrKeyEqual>::type equal_holder_t;
1140 typedef bucket_hash_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, BucketTraits> bucket_hash_type;
1141 typedef bucket_plus_vtraits<ValueTraits,BucketTraits> bucket_plus_vtraits_t;
1142 typedef ValueTraits value_traits;
1143 typedef typename equal_holder_t::functor_type key_equal;
1144 typedef typename bucket_hash_type::hasher hasher;
1145 typedef BucketTraits bucket_traits;
1146 typedef typename bucket_plus_vtraits_t::slist_impl slist_impl;
1147 typedef typename slist_impl::iterator siterator;
1148 typedef bucket_impl<slist_impl> bucket_type;
1149 typedef typename detail::unordered_bucket_ptr_impl<value_traits>::type bucket_ptr;
1150
1151 template<class BucketTraitsType>
1152 bucket_hash_equal_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h, const key_equal &e)
1153 : bucket_hash_type(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h)
1154 , equal_holder_t(e)
1155 {}
1156
1157 BOOST_INTRUSIVE_FORCEINLINE bucket_ptr priv_get_cache()
1158 { return this->bucket_hash_type::priv_bucket_pointer(); }
1159
1160 BOOST_INTRUSIVE_FORCEINLINE void priv_set_cache(bucket_ptr)
1161 {}
1162
1163 BOOST_INTRUSIVE_FORCEINLINE std::size_t priv_get_cache_bucket_num()
1164 { return 0u; }
1165
1166 BOOST_INTRUSIVE_FORCEINLINE void priv_initialize_cache()
1167 {}
1168
1169 BOOST_INTRUSIVE_FORCEINLINE void priv_swap_cache(bucket_hash_equal_t &)
1170 {}
1171
1172 siterator priv_begin() const
1173 {
1174 std::size_t n = 0;
1175 std::size_t bucket_cnt = this->bucket_hash_type::priv_bucket_count();
1176 for (n = 0; n < bucket_cnt; ++n){
1177 bucket_type &b = this->bucket_hash_type::priv_bucket(n);
1178 if(!b.empty()){
1179 return b.begin();
1180 }
1181 }
1182 return this->bucket_hash_type::priv_invalid_local_it();
1183 }
1184
1185 BOOST_INTRUSIVE_FORCEINLINE void priv_insertion_update_cache(std::size_t)
1186 {}
1187
1188 BOOST_INTRUSIVE_FORCEINLINE void priv_erasure_update_cache_range(std::size_t, std::size_t)
1189 {}
1190
1191 BOOST_INTRUSIVE_FORCEINLINE void priv_erasure_update_cache()
1192 {}
1193
1194 BOOST_INTRUSIVE_FORCEINLINE const key_equal &priv_equal() const
1195 { return this->equal_holder_t::get(); }
1196
1197 BOOST_INTRUSIVE_FORCEINLINE key_equal &priv_equal()
1198 { return this->equal_holder_t::get(); }
1199 };
1200
1201 //bucket_hash_equal_t
1202 //Stores bucket_hash_t and the equality function when the first
1203 //non-empty bucket shall be cached.
1204 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class VoidOrKeyEqual, class BucketTraits> //cache_begin == true version
1205 struct bucket_hash_equal_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual, BucketTraits, true>
1206 //Use public inheritance to avoid MSVC bugs with closures
1207 : bucket_hash_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, BucketTraits> //2
1208 , hashtable_equal_holder<ValueTraits, BucketTraits, VoidOrKeyOfValue, VoidOrKeyEqual>::type
1209 {
1210 typedef typename hashtable_equal_holder
1211 <ValueTraits, BucketTraits, VoidOrKeyOfValue, VoidOrKeyEqual>::type equal_holder_t;
1212
1213 typedef bucket_plus_vtraits<ValueTraits,BucketTraits> bucket_plus_vtraits_t;
1214 typedef ValueTraits value_traits;
1215 typedef typename equal_holder_t::functor_type key_equal;
1216 typedef bucket_hash_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, BucketTraits> bucket_hash_type;
1217 typedef typename bucket_hash_type::hasher hasher;
1218 typedef BucketTraits bucket_traits;
1219 typedef typename bucket_plus_vtraits_t::slist_impl::iterator siterator;
1220
1221 template<class BucketTraitsType>
1222 bucket_hash_equal_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h, const key_equal &e)
1223 : bucket_hash_type(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h)
1224 , equal_holder_t(e)
1225 {}
1226
1227 typedef typename detail::unordered_bucket_ptr_impl
1228 <typename bucket_hash_type::value_traits>::type bucket_ptr;
1229
1230 BOOST_INTRUSIVE_FORCEINLINE bucket_ptr priv_get_cache() const
1231 { return cached_begin_; }
1232
1233 BOOST_INTRUSIVE_FORCEINLINE void priv_set_cache(bucket_ptr p)
1234 { cached_begin_ = p; }
1235
1236 BOOST_INTRUSIVE_FORCEINLINE std::size_t priv_get_cache_bucket_num()
1237 { return std::size_t(this->cached_begin_ - this->bucket_hash_type::priv_bucket_pointer()); }
1238
1239 BOOST_INTRUSIVE_FORCEINLINE void priv_initialize_cache()
1240 { this->cached_begin_ = this->bucket_hash_type::priv_invalid_bucket(); }
1241
1242 BOOST_INTRUSIVE_FORCEINLINE void priv_swap_cache(bucket_hash_equal_t &other)
1243 { ::boost::adl_move_swap(this->cached_begin_, other.cached_begin_); }
1244
1245 siterator priv_begin() const
1246 {
1247 if(this->cached_begin_ == this->bucket_hash_type::priv_invalid_bucket()){
1248 return this->bucket_hash_type::priv_invalid_local_it();
1249 }
1250 else{
1251 return this->cached_begin_->begin();
1252 }
1253 }
1254
1255 void priv_insertion_update_cache(std::size_t insertion_bucket)
1256 {
1257 BOOST_INTRUSIVE_INVARIANT_ASSERT(insertion_bucket < this->bucket_hash_type::priv_bucket_count());
1258 bucket_ptr p = this->bucket_hash_type::priv_bucket_pointer() + std::ptrdiff_t(insertion_bucket);
1259 if(p < this->cached_begin_){
1260 this->cached_begin_ = p;
1261 }
1262 }
1263
1264 BOOST_INTRUSIVE_FORCEINLINE const key_equal &priv_equal() const
1265 { return this->equal_holder_t::get(); }
1266
1267 BOOST_INTRUSIVE_FORCEINLINE key_equal &priv_equal()
1268 { return this->equal_holder_t::get(); }
1269
1270 void priv_erasure_update_cache_range(std::size_t first_bucket_num, std::size_t last_bucket_num)
1271 {
1272 //If the last bucket is the end, the cache must be updated
1273 //to the last position if all
1274 if(this->priv_get_cache_bucket_num() == first_bucket_num &&
1275 this->bucket_hash_type::priv_bucket(first_bucket_num).empty() ){
1276 this->priv_set_cache(this->bucket_hash_type::priv_bucket_pointer() + std::ptrdiff_t(last_bucket_num));
1277 this->priv_erasure_update_cache();
1278 }
1279 }
1280
1281 void priv_erasure_update_cache()
1282 {
1283 if(this->cached_begin_ != this->bucket_hash_type::priv_invalid_bucket()){
1284 std::size_t current_n = std::size_t(this->priv_get_cache() - this->bucket_hash_type::priv_bucket_pointer());
1285 for( const std::size_t num_buckets = this->bucket_hash_type::priv_bucket_count()
1286 ; current_n < num_buckets
1287 ; ++current_n, ++cached_begin_){
1288 if(!cached_begin_->empty()){
1289 return;
1290 }
1291 }
1292 this->priv_initialize_cache();
1293 }
1294 }
1295
1296 bucket_ptr cached_begin_;
1297 };
1298
1299 //This wrapper around size_traits is used
1300 //to maintain minimal container size with compilers like MSVC
1301 //that have problems with EBO and multiple empty base classes
1302 template<class DeriveFrom, class SizeType, bool>
1303 struct hashtable_size_traits_wrapper
1304 : public DeriveFrom
1305 {
1306 template<class Base, class Arg0, class Arg1, class Arg2>
1307 hashtable_size_traits_wrapper( BOOST_FWD_REF(Base) base, BOOST_FWD_REF(Arg0) arg0
1308 , BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2)
1309 : DeriveFrom(::boost::forward<Base>(base)
1310 , ::boost::forward<Arg0>(arg0)
1311 , ::boost::forward<Arg1>(arg1)
1312 , ::boost::forward<Arg2>(arg2))
1313 {}
1314 typedef detail::size_holder < true, SizeType> size_traits;//size_traits
1315
1316 size_traits size_traits_;
1317
1318 typedef const size_traits & size_traits_const_t;
1319 typedef size_traits & size_traits_t;
1320
1321 BOOST_INTRUSIVE_FORCEINLINE size_traits_const_t priv_size_traits() const
1322 { return size_traits_; }
1323
1324 BOOST_INTRUSIVE_FORCEINLINE size_traits_t priv_size_traits()
1325 { return size_traits_; }
1326 };
1327
1328 template<class DeriveFrom, class SizeType>
1329 struct hashtable_size_traits_wrapper<DeriveFrom, SizeType, false>
1330 : public DeriveFrom
1331 {
1332 template<class Base, class Arg0, class Arg1, class Arg2>
1333 hashtable_size_traits_wrapper( BOOST_FWD_REF(Base) base, BOOST_FWD_REF(Arg0) arg0
1334 , BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2)
1335 : DeriveFrom(::boost::forward<Base>(base)
1336 , ::boost::forward<Arg0>(arg0)
1337 , ::boost::forward<Arg1>(arg1)
1338 , ::boost::forward<Arg2>(arg2))
1339 {}
1340
1341 typedef detail::size_holder< false, SizeType> size_traits;
1342
1343 typedef size_traits size_traits_const_t;
1344 typedef size_traits size_traits_t;
1345
1346 BOOST_INTRUSIVE_FORCEINLINE size_traits priv_size_traits() const
1347 { return size_traits(); }
1348 };
1349
1350 //hashdata_internal
1351 //Stores bucket_hash_equal_t and split_traits
1352 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class VoidOrKeyEqual, class BucketTraits, class SizeType, std::size_t BoolFlags>
1353 struct hashdata_internal
1354 : public hashtable_size_traits_wrapper
1355 < bucket_hash_equal_t
1356 < ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual
1357 , BucketTraits
1358 , 0 != (BoolFlags & hash_bool_flags::cache_begin_pos)
1359 > //2
1360 , SizeType
1361 , (BoolFlags & hash_bool_flags::incremental_pos) != 0
1362 >
1363 {
1364 typedef hashtable_size_traits_wrapper
1365 < bucket_hash_equal_t
1366 < ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual
1367 , BucketTraits
1368 , 0 != (BoolFlags & hash_bool_flags::cache_begin_pos)
1369 > //2
1370 , SizeType
1371 , (BoolFlags & hash_bool_flags::incremental_pos) != 0
1372 > internal_type;
1373 typedef typename internal_type::key_equal key_equal;
1374 typedef typename internal_type::hasher hasher;
1375 typedef bucket_plus_vtraits<ValueTraits,BucketTraits> bucket_plus_vtraits_t;
1376 typedef SizeType size_type;
1377 typedef typename internal_type::size_traits split_traits;
1378 typedef typename bucket_plus_vtraits_t::bucket_ptr bucket_ptr;
1379 typedef typename bucket_plus_vtraits_t::const_value_traits_ptr const_value_traits_ptr;
1380 typedef typename bucket_plus_vtraits_t::siterator siterator;
1381 typedef typename bucket_plus_vtraits_t::bucket_traits bucket_traits;
1382 typedef typename bucket_plus_vtraits_t::value_traits value_traits;
1383 typedef typename bucket_plus_vtraits_t::bucket_type bucket_type;
1384 typedef typename value_traits::value_type value_type;
1385 typedef typename value_traits::pointer pointer;
1386 typedef typename value_traits::const_pointer const_pointer;
1387 typedef typename pointer_traits<pointer>::reference reference;
1388 typedef typename pointer_traits
1389 <const_pointer>::reference const_reference;
1390 typedef typename value_traits::node_traits node_traits;
1391 typedef typename node_traits::node node;
1392 typedef typename node_traits::node_ptr node_ptr;
1393 typedef typename node_traits::const_node_ptr const_node_ptr;
1394 typedef detail::node_functions<node_traits> node_functions_t;
1395 typedef typename get_slist_impl
1396 <typename reduced_slist_node_traits
1397 <typename value_traits::node_traits>::type
1398 >::type slist_impl;
1399 typedef typename slist_impl::node_algorithms node_algorithms;
1400 typedef typename slist_impl::node_ptr slist_node_ptr;
1401
1402 typedef hash_key_types_base
1403 < typename ValueTraits::value_type
1404 , VoidOrKeyOfValue
1405 > hash_types_base;
1406 typedef typename hash_types_base::key_of_value key_of_value;
1407
1408 static const bool store_hash = detail::store_hash_is_true<node_traits>::value;
1409 static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
1410 static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value;
1411
1412 typedef detail::bool_<store_hash> store_hash_t;
1413
1414 typedef detail::transform_iterator
1415 < typename slist_impl::iterator
1416 , downcast_node_to_value_t
1417 < value_traits
1418 , false> > local_iterator;
1419
1420 typedef detail::transform_iterator
1421 < typename slist_impl::iterator
1422 , downcast_node_to_value_t
1423 < value_traits
1424 , true> > const_local_iterator;
1425 //
1426
1427 template<class BucketTraitsType>
1428 hashdata_internal( const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits
1429 , const hasher & h, const key_equal &e)
1430 : internal_type(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h, e)
1431 {}
1432
1433 BOOST_INTRUSIVE_FORCEINLINE typename internal_type::size_traits_t priv_split_traits()
1434 { return this->priv_size_traits(); }
1435
1436 BOOST_INTRUSIVE_FORCEINLINE typename internal_type::size_traits_const_t priv_split_traits() const
1437 { return this->priv_size_traits(); }
1438
1439 ~hashdata_internal()
1440 { this->priv_clear_buckets(); }
1441
1442 void priv_clear_buckets()
1443 {
1444 const std::size_t cache_num = std::size_t(this->priv_get_cache() - this->internal_type::priv_bucket_pointer());
1445 this->internal_type::priv_clear_buckets
1446 ( this->priv_get_cache()
1447 , this->internal_type::priv_bucket_count() - cache_num);
1448 }
1449
1450 void priv_clear_buckets_and_cache()
1451 {
1452 this->priv_clear_buckets();
1453 this->priv_initialize_cache();
1454 }
1455
1456 void priv_initialize_buckets_and_cache()
1457 {
1458 this->internal_type::priv_clear_buckets
1459 ( this->internal_type::priv_bucket_pointer()
1460 , this->internal_type::priv_bucket_count());
1461 this->priv_initialize_cache();
1462 }
1463
1464 typedef hashtable_iterator<bucket_plus_vtraits_t, false> iterator;
1465 typedef hashtable_iterator<bucket_plus_vtraits_t, true> const_iterator;
1466
1467 static std::size_t priv_stored_hash(slist_node_ptr n, detail::true_ true_value)
1468 { return bucket_plus_vtraits<ValueTraits, BucketTraits>::priv_stored_hash(n, true_value); }
1469
1470 static std::size_t priv_stored_hash(slist_node_ptr n, detail::false_ false_value)
1471 { return bucket_plus_vtraits<ValueTraits, BucketTraits>::priv_stored_hash(n, false_value); }
1472
1473 //public functions
1474 BOOST_INTRUSIVE_FORCEINLINE SizeType split_count() const BOOST_NOEXCEPT
1475 { return this->priv_split_traits().get_size(); }
1476
1477 BOOST_INTRUSIVE_FORCEINLINE iterator iterator_to(reference value) BOOST_NOEXCEPT
1478 {
1479 return iterator(bucket_type::s_iterator_to
1480 (this->priv_value_to_node(value)), &this->get_bucket_value_traits());
1481 }
1482
1483 const_iterator iterator_to(const_reference value) const BOOST_NOEXCEPT
1484 {
1485 siterator const sit = bucket_type::s_iterator_to
1486 ( *pointer_traits<node_ptr>::const_cast_from
1487 (pointer_traits<const_node_ptr>::pointer_to(this->priv_value_to_node(value)))
1488 );
1489 return const_iterator(sit, &this->get_bucket_value_traits());
1490 }
1491
1492 static local_iterator s_local_iterator_to(reference value) BOOST_NOEXCEPT
1493 {
1494 BOOST_STATIC_ASSERT((!stateful_value_traits));
1495 siterator sit = bucket_type::s_iterator_to(*value_traits::to_node_ptr(value));
1496 return local_iterator(sit, const_value_traits_ptr());
1497 }
1498
1499 static const_local_iterator s_local_iterator_to(const_reference value) BOOST_NOEXCEPT
1500 {
1501 BOOST_STATIC_ASSERT((!stateful_value_traits));
1502 siterator const sit = bucket_type::s_iterator_to
1503 ( *pointer_traits<node_ptr>::const_cast_from
1504 (value_traits::to_node_ptr(value))
1505 );
1506 return const_local_iterator(sit, const_value_traits_ptr());
1507 }
1508
1509 local_iterator local_iterator_to(reference value) BOOST_NOEXCEPT
1510 {
1511 siterator sit = bucket_type::s_iterator_to(this->priv_value_to_node(value));
1512 return local_iterator(sit, this->priv_value_traits_ptr());
1513 }
1514
1515 const_local_iterator local_iterator_to(const_reference value) const BOOST_NOEXCEPT
1516 {
1517 siterator sit = bucket_type::s_iterator_to
1518 ( *pointer_traits<node_ptr>::const_cast_from
1519 (pointer_traits<const_node_ptr>::pointer_to(this->priv_value_to_node(value)))
1520 );
1521 return const_local_iterator(sit, this->priv_value_traits_ptr());
1522 }
1523
1524 BOOST_INTRUSIVE_FORCEINLINE size_type bucket_count() const BOOST_NOEXCEPT
1525 { return size_type(this->priv_bucket_count()); }
1526
1527 BOOST_INTRUSIVE_FORCEINLINE size_type bucket_size(size_type n) const BOOST_NOEXCEPT
1528 { return (size_type)this->priv_bucket(n).size(); }
1529
1530 BOOST_INTRUSIVE_FORCEINLINE bucket_ptr bucket_pointer() const BOOST_NOEXCEPT
1531 { return this->priv_bucket_pointer(); }
1532
1533 BOOST_INTRUSIVE_FORCEINLINE local_iterator begin(size_type n) BOOST_NOEXCEPT
1534 { return local_iterator(this->priv_bucket(n).begin(), this->priv_value_traits_ptr()); }
1535
1536 BOOST_INTRUSIVE_FORCEINLINE const_local_iterator begin(size_type n) const BOOST_NOEXCEPT
1537 { return this->cbegin(n); }
1538
1539 static BOOST_INTRUSIVE_FORCEINLINE size_type suggested_upper_bucket_count(size_type n) BOOST_NOEXCEPT
1540 {
1541 return prime_list_holder<0>::suggested_upper_bucket_count(n);
1542 }
1543
1544 static BOOST_INTRUSIVE_FORCEINLINE size_type suggested_lower_bucket_count(size_type n) BOOST_NOEXCEPT
1545 {
1546 return prime_list_holder<0>::suggested_lower_bucket_count(n);
1547 }
1548
1549 const_local_iterator cbegin(size_type n) const BOOST_NOEXCEPT
1550 {
1551 return const_local_iterator
1552 ( this->priv_bucket(n).begin()
1553 , this->priv_value_traits_ptr());
1554 }
1555
1556 using internal_type::end;
1557 using internal_type::cend;
1558
1559 local_iterator end(size_type n) BOOST_NOEXCEPT
1560 { return local_iterator(this->priv_bucket(n).end(), this->priv_value_traits_ptr()); }
1561
1562 BOOST_INTRUSIVE_FORCEINLINE const_local_iterator end(size_type n) const BOOST_NOEXCEPT
1563 { return this->cend(n); }
1564
1565 const_local_iterator cend(size_type n) const BOOST_NOEXCEPT
1566 {
1567 return const_local_iterator
1568 ( this->priv_bucket(n).end()
1569 , this->priv_value_traits_ptr());
1570 }
1571
1572 //Public functions for hashtable_impl
1573
1574 BOOST_INTRUSIVE_FORCEINLINE iterator begin() BOOST_NOEXCEPT
1575 { return iterator(this->priv_begin(), &this->get_bucket_value_traits()); }
1576
1577 BOOST_INTRUSIVE_FORCEINLINE const_iterator begin() const BOOST_NOEXCEPT
1578 { return this->cbegin(); }
1579
1580 BOOST_INTRUSIVE_FORCEINLINE const_iterator cbegin() const BOOST_NOEXCEPT
1581 { return const_iterator(this->priv_begin(), &this->get_bucket_value_traits()); }
1582
1583 BOOST_INTRUSIVE_FORCEINLINE hasher hash_function() const
1584 { return this->priv_hasher(); }
1585
1586 BOOST_INTRUSIVE_FORCEINLINE key_equal key_eq() const
1587 { return this->priv_equal(); }
1588 };
1589
1590 /// @endcond
1591
1592 //! The class template hashtable is an intrusive hash table container, that
1593 //! is used to construct intrusive unordered_set and unordered_multiset containers. The
1594 //! no-throw guarantee holds only, if the VoidOrKeyEqual object and Hasher don't throw.
1595 //!
1596 //! hashtable is a semi-intrusive container: each object to be stored in the
1597 //! container must contain a proper hook, but the container also needs
1598 //! additional auxiliary memory to work: hashtable needs a pointer to an array
1599 //! of type `bucket_type` to be passed in the constructor. This bucket array must
1600 //! have at least the same lifetime as the container. This makes the use of
1601 //! hashtable more complicated than purely intrusive containers.
1602 //! `bucket_type` is default-constructible, copyable and assignable
1603 //!
1604 //! The template parameter \c T is the type to be managed by the container.
1605 //! The user can specify additional options and if no options are provided
1606 //! default options are used.
1607 //!
1608 //! The container supports the following options:
1609 //! \c base_hook<>/member_hook<>/value_traits<>,
1610 //! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<>
1611 //! \c bucket_traits<>, power_2_buckets<>, cache_begin<> and incremental<>.
1612 //!
1613 //! hashtable only provides forward iterators but it provides 4 iterator types:
1614 //! iterator and const_iterator to navigate through the whole container and
1615 //! local_iterator and const_local_iterator to navigate through the values
1616 //! stored in a single bucket. Local iterators are faster and smaller.
1617 //!
1618 //! It's not recommended to use non constant-time size hashtables because several
1619 //! key functions, like "empty()", become non-constant time functions. Non
1620 //! constant_time size hashtables are mainly provided to support auto-unlink hooks.
1621 //!
1622 //! hashtables, does not make automatic rehashings nor
1623 //! offers functions related to a load factor. Rehashing can be explicitly requested
1624 //! and the user must provide a new bucket array that will be used from that moment.
1625 //!
1626 //! Since no automatic rehashing is done, iterators are never invalidated when
1627 //! inserting or erasing elements. Iterators are only invalidated when rehashing.
1628 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1629 template<class T, class ...Options>
1630 #else
1631 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class VoidOrKeyEqual, class BucketTraits, class SizeType, std::size_t BoolFlags>
1632 #endif
1633 class hashtable_impl
1634 : private hashtable_size_traits_wrapper
1635 < hashdata_internal
1636 < ValueTraits
1637 , VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual
1638 , BucketTraits, SizeType
1639 , BoolFlags & (hash_bool_flags::incremental_pos | hash_bool_flags::cache_begin_pos) //1
1640 >
1641 , SizeType
1642 , (BoolFlags & hash_bool_flags::constant_time_size_pos) != 0
1643 >
1644 {
1645 typedef hashtable_size_traits_wrapper
1646 < hashdata_internal
1647 < ValueTraits
1648 , VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual
1649 , BucketTraits, SizeType
1650 , BoolFlags & (hash_bool_flags::incremental_pos | hash_bool_flags::cache_begin_pos) //1
1651 >
1652 , SizeType
1653 , (BoolFlags & hash_bool_flags::constant_time_size_pos) != 0
1654 > internal_type;
1655 typedef typename internal_type::size_traits size_traits;
1656 typedef hash_key_types_base
1657 < typename ValueTraits::value_type
1658 , VoidOrKeyOfValue
1659 > hash_types_base;
1660 public:
1661 typedef ValueTraits value_traits;
1662
1663 /// @cond
1664 typedef BucketTraits bucket_traits;
1665
1666 typedef typename internal_type::slist_impl slist_impl;
1667 typedef bucket_plus_vtraits<ValueTraits, BucketTraits> bucket_plus_vtraits_t;
1668 typedef typename bucket_plus_vtraits_t::const_value_traits_ptr const_value_traits_ptr;
1669
1670 using internal_type::begin;
1671 using internal_type::cbegin;
1672 using internal_type::end;
1673 using internal_type::cend;
1674 using internal_type::hash_function;
1675 using internal_type::key_eq;
1676 using internal_type::bucket_size;
1677 using internal_type::bucket_count;
1678 using internal_type::local_iterator_to;
1679 using internal_type::s_local_iterator_to;
1680 using internal_type::iterator_to;
1681 using internal_type::bucket_pointer;
1682 using internal_type::suggested_upper_bucket_count;
1683 using internal_type::suggested_lower_bucket_count;
1684 using internal_type::split_count;
1685
1686 /// @endcond
1687
1688 typedef typename value_traits::pointer pointer;
1689 typedef typename value_traits::const_pointer const_pointer;
1690 typedef typename value_traits::value_type value_type;
1691 typedef typename hash_types_base::key_type key_type;
1692 typedef typename hash_types_base::key_of_value key_of_value;
1693 typedef typename pointer_traits<pointer>::reference reference;
1694 typedef typename pointer_traits<const_pointer>::reference const_reference;
1695 typedef typename pointer_traits<pointer>::difference_type difference_type;
1696 typedef SizeType size_type;
1697 typedef typename internal_type::key_equal key_equal;
1698 typedef typename internal_type::hasher hasher;
1699 typedef bucket_impl<slist_impl> bucket_type;
1700 typedef typename internal_type::bucket_ptr bucket_ptr;
1701 typedef typename slist_impl::iterator siterator;
1702 typedef typename slist_impl::const_iterator const_siterator;
1703 typedef typename internal_type::iterator iterator;
1704 typedef typename internal_type::const_iterator const_iterator;
1705 typedef typename internal_type::local_iterator local_iterator;
1706 typedef typename internal_type::const_local_iterator const_local_iterator;
1707 typedef typename value_traits::node_traits node_traits;
1708 typedef typename node_traits::node node;
1709 typedef typename pointer_traits
1710 <pointer>::template rebind_pointer
1711 < node >::type node_ptr;
1712 typedef typename pointer_traits
1713 <pointer>::template rebind_pointer
1714 < const node >::type const_node_ptr;
1715 typedef typename pointer_traits
1716 <node_ptr>::reference node_reference;
1717 typedef typename pointer_traits
1718 <const_node_ptr>::reference const_node_reference;
1719 typedef typename slist_impl::node_algorithms node_algorithms;
1720
1721 static const bool stateful_value_traits = internal_type::stateful_value_traits;
1722 static const bool store_hash = internal_type::store_hash;
1723
1724 static const bool unique_keys = 0 != (BoolFlags & hash_bool_flags::unique_keys_pos);
1725 static const bool constant_time_size = 0 != (BoolFlags & hash_bool_flags::constant_time_size_pos);
1726 static const bool cache_begin = 0 != (BoolFlags & hash_bool_flags::cache_begin_pos);
1727 static const bool compare_hash = 0 != (BoolFlags & hash_bool_flags::compare_hash_pos);
1728 static const bool incremental = 0 != (BoolFlags & hash_bool_flags::incremental_pos);
1729 static const bool power_2_buckets = incremental || (0 != (BoolFlags & hash_bool_flags::power_2_buckets_pos));
1730
1731 static const bool optimize_multikey
1732 = detail::optimize_multikey_is_true<node_traits>::value && !unique_keys;
1733
1734 /// @cond
1735 static const bool is_multikey = !unique_keys;
1736 private:
1737
1738 //Configuration error: compare_hash<> can't be specified without store_hash<>
1739 //See documentation for more explanations
1740 BOOST_STATIC_ASSERT((!compare_hash || store_hash));
1741
1742 typedef typename slist_impl::node_ptr slist_node_ptr;
1743 typedef typename pointer_traits
1744 <slist_node_ptr>::template rebind_pointer
1745 < void >::type void_pointer;
1746 //We'll define group traits, but these won't be instantiated if
1747 //optimize_multikey is not true
1748 typedef unordered_group_adapter<node_traits> group_traits;
1749 typedef circular_slist_algorithms<group_traits> group_algorithms;
1750 typedef typename internal_type::store_hash_t store_hash_t;
1751 typedef detail::bool_<optimize_multikey> optimize_multikey_t;
1752 typedef detail::bool_<cache_begin> cache_begin_t;
1753 typedef detail::bool_<power_2_buckets> power_2_buckets_t;
1754 typedef typename internal_type::split_traits split_traits;
1755 typedef detail::group_functions<node_traits> group_functions_t;
1756 typedef detail::node_functions<node_traits> node_functions_t;
1757
1758 private:
1759 //noncopyable, movable
1760 BOOST_MOVABLE_BUT_NOT_COPYABLE(hashtable_impl)
1761
1762 static const bool safemode_or_autounlink = internal_type::safemode_or_autounlink;
1763
1764 //Constant-time size is incompatible with auto-unlink hooks!
1765 BOOST_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink)));
1766 //Cache begin is incompatible with auto-unlink hooks!
1767 BOOST_STATIC_ASSERT(!(cache_begin && ((int)value_traits::link_mode == (int)auto_unlink)));
1768
1769 template<class Disposer>
1770 struct typeof_node_disposer
1771 {
1772 typedef node_cast_adaptor
1773 < detail::node_disposer< Disposer, value_traits, CircularSListAlgorithms>
1774 , slist_node_ptr, node_ptr > type;
1775 };
1776
1777 template<class Disposer>
1778 typename typeof_node_disposer<Disposer>::type
1779 make_node_disposer(const Disposer &disposer) const
1780 {
1781 typedef typename typeof_node_disposer<Disposer>::type return_t;
1782 return return_t(disposer, &this->priv_value_traits());
1783 }
1784
1785 /// @endcond
1786
1787 public:
1788 typedef detail::insert_commit_data_impl insert_commit_data;
1789
1790
1791 public:
1792
1793 //! <b>Requires</b>: buckets must not be being used by any other resource.
1794 //!
1795 //! <b>Effects</b>: Constructs an empty unordered_set, storing a reference
1796 //! to the bucket array and copies of the key_hasher and equal_func functors.
1797 //!
1798 //! <b>Complexity</b>: Constant.
1799 //!
1800 //! <b>Throws</b>: If value_traits::node_traits::node
1801 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1802 //! or the copy constructor or invocation of hash_func or equal_func throws.
1803 //!
1804 //! <b>Notes</b>: buckets array must be disposed only after
1805 //! *this is disposed.
1806 explicit hashtable_impl ( const bucket_traits &b_traits
1807 , const hasher & hash_func = hasher()
1808 , const key_equal &equal_func = key_equal()
1809 , const value_traits &v_traits = value_traits())
1810 : internal_type(v_traits, b_traits, hash_func, equal_func)
1811 {
1812 this->priv_initialize_buckets_and_cache();
1813 this->priv_size_traits().set_size(size_type(0));
1814 size_type bucket_sz = this->bucket_count();
1815 BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_sz != 0);
1816 //Check power of two bucket array if the option is activated
1817 BOOST_INTRUSIVE_INVARIANT_ASSERT
1818 (!power_2_buckets || (0 == (bucket_sz & (bucket_sz-1))));
1819 this->priv_split_traits().set_size(size_type(bucket_sz>>1u));
1820 }
1821
1822 //! <b>Requires</b>: buckets must not be being used by any other resource
1823 //! and dereferencing iterator must yield an lvalue of type value_type.
1824 //!
1825 //! <b>Effects</b>: Constructs an empty container and inserts elements from
1826 //! [b, e).
1827 //!
1828 //! <b>Complexity</b>: If N is distance(b, e): Average case is O(N)
1829 //! (with a good hash function and with buckets_len >= N),worst case O(N^2).
1830 //!
1831 //! <b>Throws</b>: If value_traits::node_traits::node
1832 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1833 //! or the copy constructor or invocation of hasher or key_equal throws.
1834 //!
1835 //! <b>Notes</b>: buckets array must be disposed only after
1836 //! *this is disposed.
1837 template<class Iterator>
1838 hashtable_impl ( bool unique, Iterator b, Iterator e
1839 , const bucket_traits &b_traits
1840 , const hasher & hash_func = hasher()
1841 , const key_equal &equal_func = key_equal()
1842 , const value_traits &v_traits = value_traits())
1843 : internal_type(v_traits, b_traits, hash_func, equal_func)
1844 {
1845 this->priv_initialize_buckets_and_cache();
1846 this->priv_size_traits().set_size(size_type(0));
1847 size_type bucket_sz = this->bucket_count();
1848 BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_sz != 0);
1849 //Check power of two bucket array if the option is activated
1850 BOOST_INTRUSIVE_INVARIANT_ASSERT
1851 (!power_2_buckets || (0 == (bucket_sz & (bucket_sz-1))));
1852 this->priv_split_traits().set_size(size_type(bucket_sz>>1u));
1853 //Now insert
1854 if(unique)
1855 this->insert_unique(b, e);
1856 else
1857 this->insert_equal(b, e);
1858 }
1859
1860 //! <b>Effects</b>: Constructs a container moving resources from another container.
1861 //! Internal value traits, bucket traits, hasher and comparison are move constructed and
1862 //! nodes belonging to x are linked to *this.
1863 //!
1864 //! <b>Complexity</b>: Constant.
1865 //!
1866 //! <b>Throws</b>: If value_traits::node_traits::node's
1867 //! move constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1868 //! or the move constructor of value traits, bucket traits, hasher or comparison throws.
1869 hashtable_impl(BOOST_RV_REF(hashtable_impl) x)
1870 : internal_type( ::boost::move(x.priv_value_traits())
1871 , ::boost::move(x.priv_bucket_traits())
1872 , ::boost::move(x.priv_hasher())
1873 , ::boost::move(x.priv_equal())
1874 )
1875 {
1876 this->priv_swap_cache(x);
1877 x.priv_initialize_cache();
1878 this->priv_size_traits().set_size(x.priv_size_traits().get_size());
1879 x.priv_size_traits().set_size(size_type(0));
1880 this->priv_split_traits().set_size(x.priv_split_traits().get_size());
1881 x.priv_split_traits().set_size(size_type(0));
1882 }
1883
1884 //! <b>Effects</b>: Equivalent to swap.
1885 //!
1886 hashtable_impl& operator=(BOOST_RV_REF(hashtable_impl) x)
1887 { this->swap(x); return *this; }
1888
1889 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1890 //! <b>Effects</b>: Detaches all elements from this. The objects in the unordered_set
1891 //! are not deleted (i.e. no destructors are called).
1892 //!
1893 //! <b>Complexity</b>: Linear to the number of elements in the unordered_set, if
1894 //! it's a safe-mode or auto-unlink value. Otherwise constant.
1895 //!
1896 //! <b>Throws</b>: Nothing.
1897 ~hashtable_impl();
1898
1899 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the unordered_set.
1900 //!
1901 //! <b>Complexity</b>: Amortized constant time.
1902 //! Worst case (empty unordered_set): O(this->bucket_count())
1903 //!
1904 //! <b>Throws</b>: Nothing.
1905 iterator begin() BOOST_NOEXCEPT;
1906
1907 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
1908 //! of the unordered_set.
1909 //!
1910 //! <b>Complexity</b>: Amortized constant time.
1911 //! Worst case (empty unordered_set): O(this->bucket_count())
1912 //!
1913 //! <b>Throws</b>: Nothing.
1914 const_iterator begin() const BOOST_NOEXCEPT;
1915
1916 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
1917 //! of the unordered_set.
1918 //!
1919 //! <b>Complexity</b>: Amortized constant time.
1920 //! Worst case (empty unordered_set): O(this->bucket_count())
1921 //!
1922 //! <b>Throws</b>: Nothing.
1923 const_iterator cbegin() const BOOST_NOEXCEPT;
1924
1925 //! <b>Effects</b>: Returns an iterator pointing to the end of the unordered_set.
1926 //!
1927 //! <b>Complexity</b>: Constant.
1928 //!
1929 //! <b>Throws</b>: Nothing.
1930 iterator end() BOOST_NOEXCEPT;
1931
1932 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set.
1933 //!
1934 //! <b>Complexity</b>: Constant.
1935 //!
1936 //! <b>Throws</b>: Nothing.
1937 const_iterator end() const BOOST_NOEXCEPT;
1938
1939 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set.
1940 //!
1941 //! <b>Complexity</b>: Constant.
1942 //!
1943 //! <b>Throws</b>: Nothing.
1944 const_iterator cend() const BOOST_NOEXCEPT;
1945
1946 //! <b>Effects</b>: Returns the hasher object used by the unordered_set.
1947 //!
1948 //! <b>Complexity</b>: Constant.
1949 //!
1950 //! <b>Throws</b>: If hasher copy-constructor throws.
1951 hasher hash_function() const;
1952
1953 //! <b>Effects</b>: Returns the key_equal object used by the unordered_set.
1954 //!
1955 //! <b>Complexity</b>: Constant.
1956 //!
1957 //! <b>Throws</b>: If key_equal copy-constructor throws.
1958 key_equal key_eq() const;
1959
1960 #endif
1961
1962 //! <b>Effects</b>: Returns true if the container is empty.
1963 //!
1964 //! <b>Complexity</b>: if constant-time size and cache_begin options are disabled,
1965 //! average constant time (worst case, with empty() == true: O(this->bucket_count()).
1966 //! Otherwise constant.
1967 //!
1968 //! <b>Throws</b>: Nothing.
1969 bool empty() const BOOST_NOEXCEPT
1970 {
1971 BOOST_IF_CONSTEXPR(constant_time_size){
1972 return !this->size();
1973 }
1974 else if(cache_begin){
1975 return this->begin() == this->end();
1976 }
1977 else{
1978 size_type bucket_cnt = this->bucket_count();
1979 const bucket_type *b = boost::movelib::to_raw_pointer(this->priv_bucket_pointer());
1980 for (size_type n = 0; n < bucket_cnt; ++n, ++b){
1981 if(!b->empty()){
1982 return false;
1983 }
1984 }
1985 return true;
1986 }
1987 }
1988
1989 //! <b>Effects</b>: Returns the number of elements stored in the unordered_set.
1990 //!
1991 //! <b>Complexity</b>: Linear to elements contained in *this if
1992 //! constant_time_size is false. Constant-time otherwise.
1993 //!
1994 //! <b>Throws</b>: Nothing.
1995 size_type size() const BOOST_NOEXCEPT
1996 {
1997 BOOST_IF_CONSTEXPR(constant_time_size)
1998 return this->priv_size_traits().get_size();
1999 else{
2000 std::size_t len = 0;
2001 std::size_t bucket_cnt = this->bucket_count();
2002 const bucket_type *b = boost::movelib::to_raw_pointer(this->priv_bucket_pointer());
2003 for (std::size_t n = 0; n < bucket_cnt; ++n, ++b){
2004 len += b->size();
2005 }
2006 BOOST_INTRUSIVE_INVARIANT_ASSERT((len <= SizeType(-1)));
2007 return size_type(len);
2008 }
2009 }
2010
2011 //! <b>Requires</b>: the hasher and the equality function unqualified swap
2012 //! call should not throw.
2013 //!
2014 //! <b>Effects</b>: Swaps the contents of two unordered_sets.
2015 //! Swaps also the contained bucket array and equality and hasher functors.
2016 //!
2017 //! <b>Complexity</b>: Constant.
2018 //!
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)
2022 {
2023 //These can throw
2024 ::boost::adl_move_swap(this->priv_equal(), other.priv_equal());
2025 ::boost::adl_move_swap(this->priv_hasher(), other.priv_hasher());
2026 //These can't throw
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());
2032 }
2033
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.
2037 //!
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.
2043 //!
2044 //! If store_hash option is true, this method does not use the hash function.
2045 //!
2046 //! If any operation throws, all cloned elements are unlinked and disposed
2047 //! calling Disposer::operator()(pointer).
2048 //!
2049 //! <b>Complexity</b>: Linear to erased plus inserted elements.
2050 //!
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); }
2056
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.
2060 //!
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.
2066 //!
2067 //! If store_hash option is true, this method does not use the hash function.
2068 //!
2069 //! If any operation throws, all cloned elements are unlinked and disposed
2070 //! calling Disposer::operator()(pointer).
2071 //!
2072 //! <b>Complexity</b>: Linear to erased plus inserted elements.
2073 //!
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); }
2079
2080 //! <b>Requires</b>: value must be an lvalue
2081 //!
2082 //! <b>Effects</b>: Inserts the value into the unordered_set.
2083 //!
2084 //! <b>Returns</b>: An iterator to the inserted value.
2085 //!
2086 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2087 //!
2088 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Strong guarantee.
2089 //!
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)
2093 {
2094 size_type bucket_num;
2095 std::size_t hash_value;
2096 siterator prev;
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);
2101 }
2102
2103 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
2104 //! of type value_type.
2105 //!
2106 //! <b>Effects</b>: Equivalent to this->insert_equal(t) for each element in [b, e).
2107 //!
2108 //! <b>Complexity</b>: Average case O(N), where N is distance(b, e).
2109 //! Worst case O(N*this->size()).
2110 //!
2111 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
2112 //!
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)
2117 {
2118 for (; b != e; ++b)
2119 this->insert_equal(*b);
2120 }
2121
2122 //! <b>Requires</b>: value must be an lvalue
2123 //!
2124 //! <b>Effects</b>: Tries to inserts value into the unordered_set.
2125 //!
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
2130 //! and false.
2131 //!
2132 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2133 //!
2134 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Strong guarantee.
2135 //!
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)
2139 {
2140 insert_commit_data commit_data;
2141 std::pair<iterator, bool> ret = this->insert_unique_check(key_of_value()(value), commit_data);
2142 if(ret.second){
2143 ret.first = this->insert_unique_commit(value, commit_data);
2144 }
2145 return ret;
2146 }
2147
2148 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
2149 //! of type value_type.
2150 //!
2151 //! <b>Effects</b>: Equivalent to this->insert_unique(t) for each element in [b, e).
2152 //!
2153 //! <b>Complexity</b>: Average case O(N), where N is distance(b, e).
2154 //! Worst case O(N*this->size()).
2155 //!
2156 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
2157 //!
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)
2162 {
2163 for (; b != e; ++b)
2164 this->insert_unique(*b);
2165 }
2166
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.
2170 //!
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.
2174 //!
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.
2177 //!
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.
2183 //!
2184 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2185 //!
2186 //! <b>Throws</b>: If hash_func or equal_func throw. Strong guarantee.
2187 //!
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.
2194 //!
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.
2197 //!
2198 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
2199 //! objects are inserted or erased from the unordered_set.
2200 //!
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)
2208 {
2209 size_type bucket_num;
2210 siterator prev;
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());
2215 }
2216
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.
2219 //!
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.
2225 //!
2226 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2227 //!
2228 //! <b>Throws</b>: If hasher or key_compare throw. Strong guarantee.
2229 //!
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.
2236 //!
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.
2239 //!
2240 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
2241 //! objects are inserted or erased from the unordered_set.
2242 //!
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); }
2247
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".
2252 //!
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.
2255 //!
2256 //! <b>Returns</b>: An iterator to the newly inserted object.
2257 //!
2258 //! <b>Complexity</b>: Constant time.
2259 //!
2260 //! <b>Throws</b>: Nothing.
2261 //!
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.
2265 //!
2266 //! After a successful rehashing insert_commit_data remains valid.
2267 iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) BOOST_NOEXCEPT
2268 {
2269 size_type bucket_num = this->priv_hash_to_bucket(commit_data.hash);
2270 bucket_type &b = this->priv_bucket(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());
2278 }
2279
2280 //! <b>Effects</b>: Erases the element pointed to by i.
2281 //!
2282 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2283 //!
2284 //! <b>Throws</b>: Nothing.
2285 //!
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) BOOST_NOEXCEPT
2289 { this->erase_and_dispose(i, detail::null_disposer()); }
2290
2291 //! <b>Effects</b>: Erases the range pointed to by b end e.
2292 //!
2293 //! <b>Complexity</b>: Average case O(distance(b, e)),
2294 //! worst case O(this->size()).
2295 //!
2296 //! <b>Throws</b>: Nothing.
2297 //!
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) BOOST_NOEXCEPT
2301 { this->erase_and_dispose(b, e, detail::null_disposer()); }
2302
2303 //! <b>Effects</b>: Erases all the elements with the given value.
2304 //!
2305 //! <b>Returns</b>: The number of erased elements.
2306 //!
2307 //! <b>Complexity</b>: Average case O(this->count(value)).
2308 //! Worst case O(this->size()).
2309 //!
2310 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2311 //! Basic guarantee.
2312 //!
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()); }
2317
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.
2321 //!
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.
2325 //!
2326 //! <b>Effects</b>: Erases all the elements that have the same hash and
2327 //! compare equal with the given key.
2328 //!
2329 //! <b>Returns</b>: The number of erased elements.
2330 //!
2331 //! <b>Complexity</b>: Average case O(this->count(value)).
2332 //! Worst case O(this->size()).
2333 //!
2334 //! <b>Throws</b>: If hash_func or equal_func throw. Basic guarantee.
2335 //!
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()); }
2341
2342 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
2343 //!
2344 //! <b>Effects</b>: Erases the element pointed to by i.
2345 //! Disposer::operator()(pointer) is called for the removed element.
2346 //!
2347 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2348 //!
2349 //! <b>Throws</b>: Nothing.
2350 //!
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) BOOST_NOEXCEPT
2357 {
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(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);
2364 }
2365
2366 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
2367 //!
2368 //! <b>Effects</b>: Erases the range pointed to by b end e.
2369 //! Disposer::operator()(pointer) is called for the removed elements.
2370 //!
2371 //! <b>Complexity</b>: Average case O(distance(b, e)),
2372 //! worst case O(this->size()).
2373 //!
2374 //! <b>Throws</b>: Nothing.
2375 //!
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) BOOST_NOEXCEPT
2380 {
2381 if(b != e){
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);
2385
2386 siterator before_first_local_it
2387 = this->priv_get_previous(this->priv_bucket(first_bucket_num), first_local_it);
2388 size_type last_bucket_num;
2389 siterator last_local_it;
2390
2391 //For the end iterator, we will assign the end iterator
2392 //of the last bucket
2393 if(e == this->end()){
2394 last_bucket_num = size_type(this->bucket_count() - 1u);
2395 last_local_it = this->priv_bucket(last_bucket_num).end();
2396 }
2397 else{
2398 last_local_it = e.slist_it();
2399 last_bucket_num = this->priv_get_bucket_num(last_local_it);
2400 }
2401 size_type const num_erased = (size_type)this->priv_erase_node_range
2402 ( before_first_local_it, first_bucket_num, last_local_it, last_bucket_num
2403 , make_node_disposer(disposer), optimize_multikey_t());
2404 this->priv_size_traits().set_size(size_type(this->priv_size_traits().get_size()-num_erased));
2405 this->priv_erasure_update_cache_range(first_bucket_num, last_bucket_num);
2406 }
2407 }
2408
2409 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
2410 //!
2411 //! <b>Effects</b>: Erases all the elements with the given value.
2412 //! Disposer::operator()(pointer) is called for the removed elements.
2413 //!
2414 //! <b>Returns</b>: The number of erased elements.
2415 //!
2416 //! <b>Complexity</b>: Average case O(this->count(value)).
2417 //! Worst case O(this->size()).
2418 //!
2419 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2420 //! Basic guarantee.
2421 //!
2422 //! <b>Note</b>: Invalidates the iterators (but not the references)
2423 //! to the erased elements. No destructors are called.
2424 template<class Disposer>
2425 BOOST_INTRUSIVE_FORCEINLINE size_type erase_and_dispose(const key_type &key, Disposer disposer)
2426 { return this->erase_and_dispose(key, this->priv_hasher(), this->priv_equal(), disposer); }
2427
2428 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
2429 //!
2430 //! <b>Effects</b>: Erases all the elements with the given key.
2431 //! according to the comparison functor "equal_func".
2432 //! Disposer::operator()(pointer) is called for the removed elements.
2433 //!
2434 //! <b>Returns</b>: The number of erased elements.
2435 //!
2436 //! <b>Complexity</b>: Average case O(this->count(value)).
2437 //! Worst case O(this->size()).
2438 //!
2439 //! <b>Throws</b>: If hash_func or equal_func throw. Basic guarantee.
2440 //!
2441 //! <b>Note</b>: Invalidates the iterators
2442 //! to the erased elements.
2443 template<class KeyType, class KeyHasher, class KeyEqual, class Disposer>
2444 size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func
2445 ,KeyEqual equal_func, Disposer disposer)
2446 {
2447 size_type bucket_num;
2448 std::size_t h;
2449 siterator prev;
2450 siterator it = this->priv_find(key, hash_func, equal_func, bucket_num, h, prev);
2451 bool const success = it != this->priv_invalid_local_it();
2452
2453 std::size_t cnt(0);
2454 if(success){
2455 if(optimize_multikey){
2456 cnt = this->priv_erase_from_single_bucket
2457 (this->priv_bucket(bucket_num), prev, ++(priv_last_in_group)(it), make_node_disposer(disposer), optimize_multikey_t());
2458 }
2459 else{
2460 bucket_type &b = this->priv_bucket(bucket_num);
2461 siterator const end_sit = b.end();
2462 do{
2463 ++cnt;
2464 ++it;
2465 }while(it != end_sit &&
2466 this->priv_is_value_equal_to_key
2467 (this->priv_value_from_slist_node(it.pointed_node()), h, key, equal_func));
2468 bucket_type::s_erase_after_and_dispose(prev, it, make_node_disposer(disposer));
2469 }
2470 this->priv_size_traits().set_size(size_type(this->priv_size_traits().get_size()-cnt));
2471 this->priv_erasure_update_cache();
2472 }
2473
2474 return static_cast<size_type>(cnt);
2475 }
2476
2477 //! <b>Effects</b>: Erases all of the elements.
2478 //!
2479 //! <b>Complexity</b>: Linear to the number of elements on the container.
2480 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
2481 //!
2482 //! <b>Throws</b>: Nothing.
2483 //!
2484 //! <b>Note</b>: Invalidates the iterators (but not the references)
2485 //! to the erased elements. No destructors are called.
2486 void clear() BOOST_NOEXCEPT
2487 {
2488 this->priv_clear_buckets_and_cache();
2489 this->priv_size_traits().set_size(size_type(0));
2490 }
2491
2492 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
2493 //!
2494 //! <b>Effects</b>: Erases all of the elements.
2495 //!
2496 //! <b>Complexity</b>: Linear to the number of elements on the container.
2497 //! Disposer::operator()(pointer) is called for the removed elements.
2498 //!
2499 //! <b>Throws</b>: Nothing.
2500 //!
2501 //! <b>Note</b>: Invalidates the iterators (but not the references)
2502 //! to the erased elements. No destructors are called.
2503 template<class Disposer>
2504 void clear_and_dispose(Disposer disposer) BOOST_NOEXCEPT
2505 {
2506 if(!constant_time_size || !this->empty()){
2507 size_type num_buckets = this->bucket_count();
2508 bucket_ptr b = this->priv_bucket_pointer();
2509 typename typeof_node_disposer<Disposer>::type d(disposer, &this->priv_value_traits());
2510 for(; num_buckets--; ++b){
2511 b->clear_and_dispose(d);
2512 }
2513 this->priv_size_traits().set_size(size_type(0));
2514 }
2515 this->priv_initialize_cache();
2516 }
2517
2518 //! <b>Effects</b>: Returns the number of contained elements with the given value
2519 //!
2520 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2521 //!
2522 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2523 BOOST_INTRUSIVE_FORCEINLINE size_type count(const key_type &key) const
2524 { return this->count(key, this->priv_hasher(), this->priv_equal()); }
2525
2526 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2527 //! the same hash values as the stored hasher. The difference is that
2528 //! "hash_func" hashes the given key instead of the value_type.
2529 //!
2530 //! "equal_func" must be a equality function that induces
2531 //! the same equality as key_equal. The difference is that
2532 //! "equal_func" compares an arbitrary key with the contained values.
2533 //!
2534 //! <b>Effects</b>: Returns the number of contained elements with the given key
2535 //!
2536 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2537 //!
2538 //! <b>Throws</b>: If hash_func or equal throw.
2539 template<class KeyType, class KeyHasher, class KeyEqual>
2540 size_type count(const KeyType &key, KeyHasher hash_func, KeyEqual equal_func) const
2541 {
2542 size_type cnt;
2543 size_type n_bucket;
2544 this->priv_local_equal_range(key, hash_func, equal_func, n_bucket, cnt);
2545 return cnt;
2546 }
2547
2548 //! <b>Effects</b>: Finds an iterator to the first element is equal to
2549 //! "value" or end() if that element does not exist.
2550 //!
2551 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2552 //!
2553 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2554 BOOST_INTRUSIVE_FORCEINLINE iterator find(const key_type &key)
2555 { return this->find(key, this->priv_hasher(), this->priv_equal()); }
2556
2557 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2558 //! the same hash values as the stored hasher. The difference is that
2559 //! "hash_func" hashes the given key instead of the value_type.
2560 //!
2561 //! "equal_func" must be a equality function that induces
2562 //! the same equality as key_equal. The difference is that
2563 //! "equal_func" compares an arbitrary key with the contained values.
2564 //!
2565 //! <b>Effects</b>: Finds an iterator to the first element whose key is
2566 //! "key" according to the given hash and equality functor or end() if
2567 //! that element does not exist.
2568 //!
2569 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2570 //!
2571 //! <b>Throws</b>: If hash_func or equal_func throw.
2572 //!
2573 //! <b>Note</b>: This function is used when constructing a value_type
2574 //! is expensive and the value_type can be compared with a cheaper
2575 //! key type. Usually this key is part of the value_type.
2576 template<class KeyType, class KeyHasher, class KeyEqual>
2577 iterator find(const KeyType &key, KeyHasher hash_func, KeyEqual equal_func)
2578 {
2579 size_type bucket_n;
2580 std::size_t h;
2581 siterator prev;
2582 return iterator( this->priv_find(key, hash_func, equal_func, bucket_n, h, prev)
2583 , &this->get_bucket_value_traits());
2584 }
2585
2586 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
2587 //! "key" or end() if that element does not exist.
2588 //!
2589 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2590 //!
2591 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2592 BOOST_INTRUSIVE_FORCEINLINE const_iterator find(const key_type &key) const
2593 { return this->find(key, this->priv_hasher(), this->priv_equal()); }
2594
2595 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2596 //! the same hash values as the stored hasher. The difference is that
2597 //! "hash_func" hashes the given key instead of the value_type.
2598 //!
2599 //! "equal_func" must be a equality function that induces
2600 //! the same equality as key_equal. The difference is that
2601 //! "equal_func" compares an arbitrary key with the contained values.
2602 //!
2603 //! <b>Effects</b>: Finds an iterator to the first element whose key is
2604 //! "key" according to the given hasher and equality functor or end() if
2605 //! that element does not exist.
2606 //!
2607 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
2608 //!
2609 //! <b>Throws</b>: If hash_func or equal_func throw.
2610 //!
2611 //! <b>Note</b>: This function is used when constructing a value_type
2612 //! is expensive and the value_type can be compared with a cheaper
2613 //! key type. Usually this key is part of the value_type.
2614 template<class KeyType, class KeyHasher, class KeyEqual>
2615 const_iterator find
2616 (const KeyType &key, KeyHasher hash_func, KeyEqual equal_func) const
2617 {
2618 size_type bucket_n;
2619 std::size_t hash_value;
2620 siterator prev;
2621 return const_iterator( this->priv_find(key, hash_func, equal_func, bucket_n, hash_value, prev)
2622 , &this->get_bucket_value_traits());
2623 }
2624
2625 //! <b>Effects</b>: Returns a range containing all elements with values equivalent
2626 //! to value. Returns std::make_pair(this->end(), this->end()) if no such
2627 //! elements exist.
2628 //!
2629 //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
2630 //!
2631 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2632 BOOST_INTRUSIVE_FORCEINLINE std::pair<iterator,iterator> equal_range(const key_type &key)
2633 { return this->equal_range(key, this->priv_hasher(), this->priv_equal()); }
2634
2635 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2636 //! the same hash values as the stored hasher. The difference is that
2637 //! "hash_func" hashes the given key instead of the value_type.
2638 //!
2639 //! "equal_func" must be a equality function that induces
2640 //! the same equality as key_equal. The difference is that
2641 //! "equal_func" compares an arbitrary key with the contained values.
2642 //!
2643 //! <b>Effects</b>: Returns a range containing all elements with equivalent
2644 //! keys. Returns std::make_pair(this->end(), this->end()) if no such
2645 //! elements exist.
2646 //!
2647 //! <b>Complexity</b>: Average case O(this->count(key, hash_func, equal_func)).
2648 //! Worst case O(this->size()).
2649 //!
2650 //! <b>Throws</b>: If hash_func or the equal_func throw.
2651 //!
2652 //! <b>Note</b>: This function is used when constructing a value_type
2653 //! is expensive and the value_type can be compared with a cheaper
2654 //! key type. Usually this key is part of the value_type.
2655 template<class KeyType, class KeyHasher, class KeyEqual>
2656 std::pair<iterator,iterator> equal_range
2657 (const KeyType &key, KeyHasher hash_func, KeyEqual equal_func)
2658 {
2659 std::pair<siterator, siterator> ret =
2660 this->priv_equal_range(key, hash_func, equal_func);
2661 return std::pair<iterator, iterator>
2662 ( iterator(ret.first, &this->get_bucket_value_traits())
2663 , iterator(ret.second, &this->get_bucket_value_traits()));
2664 }
2665
2666 //! <b>Effects</b>: Returns a range containing all elements with values equivalent
2667 //! to value. Returns std::make_pair(this->end(), this->end()) if no such
2668 //! elements exist.
2669 //!
2670 //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
2671 //!
2672 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
2673 BOOST_INTRUSIVE_FORCEINLINE std::pair<const_iterator, const_iterator>
2674 equal_range(const key_type &key) const
2675 { return this->equal_range(key, this->priv_hasher(), this->priv_equal()); }
2676
2677 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2678 //! the same hash values as the stored hasher. The difference is that
2679 //! "hash_func" hashes the given key instead of the value_type.
2680 //!
2681 //! "equal_func" must be a equality function that induces
2682 //! the same equality as key_equal. The difference is that
2683 //! "equal_func" compares an arbitrary key with the contained values.
2684 //!
2685 //! <b>Effects</b>: Returns a range containing all elements with equivalent
2686 //! keys. Returns std::make_pair(this->end(), this->end()) if no such
2687 //! elements exist.
2688 //!
2689 //! <b>Complexity</b>: Average case O(this->count(key, hash_func, equal_func)).
2690 //! Worst case O(this->size()).
2691 //!
2692 //! <b>Throws</b>: If the hasher or equal_func throw.
2693 //!
2694 //! <b>Note</b>: This function is used when constructing a value_type
2695 //! is expensive and the value_type can be compared with a cheaper
2696 //! key type. Usually this key is part of the value_type.
2697 template<class KeyType, class KeyHasher, class KeyEqual>
2698 std::pair<const_iterator,const_iterator> equal_range
2699 (const KeyType &key, KeyHasher hash_func, KeyEqual equal_func) const
2700 {
2701 std::pair<siterator, siterator> ret =
2702 this->priv_equal_range(key, hash_func, equal_func);
2703 return std::pair<const_iterator, const_iterator>
2704 ( const_iterator(ret.first, &this->get_bucket_value_traits())
2705 , const_iterator(ret.second, &this->get_bucket_value_traits()));
2706 }
2707
2708 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2709
2710 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2711 //! appropriate type. Otherwise the behavior is undefined.
2712 //!
2713 //! <b>Effects</b>: Returns: a valid iterator belonging to the unordered_set
2714 //! that points to the value
2715 //!
2716 //! <b>Complexity</b>: Constant.
2717 //!
2718 //! <b>Throws</b>: If the internal hash function throws.
2719 iterator iterator_to(reference value) BOOST_NOEXCEPT;
2720
2721 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2722 //! appropriate type. Otherwise the behavior is undefined.
2723 //!
2724 //! <b>Effects</b>: Returns: a valid const_iterator belonging to the
2725 //! unordered_set that points to the value
2726 //!
2727 //! <b>Complexity</b>: Constant.
2728 //!
2729 //! <b>Throws</b>: If the internal hash function throws.
2730 const_iterator iterator_to(const_reference value) const BOOST_NOEXCEPT;
2731
2732 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2733 //! appropriate type. Otherwise the behavior is undefined.
2734 //!
2735 //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_set
2736 //! that points to the value
2737 //!
2738 //! <b>Complexity</b>: Constant.
2739 //!
2740 //! <b>Throws</b>: Nothing.
2741 //!
2742 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2743 //! is stateless.
2744 static local_iterator s_local_iterator_to(reference value) BOOST_NOEXCEPT;
2745
2746 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2747 //! appropriate type. Otherwise the behavior is undefined.
2748 //!
2749 //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
2750 //! the unordered_set that points to the value
2751 //!
2752 //! <b>Complexity</b>: Constant.
2753 //!
2754 //! <b>Throws</b>: Nothing.
2755 //!
2756 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
2757 //! is stateless.
2758 static const_local_iterator s_local_iterator_to(const_reference value) BOOST_NOEXCEPT;
2759
2760 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2761 //! appropriate type. Otherwise the behavior is undefined.
2762 //!
2763 //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_set
2764 //! that points to the value
2765 //!
2766 //! <b>Complexity</b>: Constant.
2767 //!
2768 //! <b>Throws</b>: Nothing.
2769 local_iterator local_iterator_to(reference value) BOOST_NOEXCEPT;
2770
2771 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
2772 //! appropriate type. Otherwise the behavior is undefined.
2773 //!
2774 //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
2775 //! the unordered_set that points to the value
2776 //!
2777 //! <b>Complexity</b>: Constant.
2778 //!
2779 //! <b>Throws</b>: Nothing.
2780 const_local_iterator local_iterator_to(const_reference value) const BOOST_NOEXCEPT;
2781
2782 //! <b>Effects</b>: Returns the number of buckets passed in the constructor
2783 //! or the last rehash function.
2784 //!
2785 //! <b>Complexity</b>: Constant.
2786 //!
2787 //! <b>Throws</b>: Nothing.
2788 size_type bucket_count() const BOOST_NOEXCEPT;
2789
2790 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2791 //!
2792 //! <b>Effects</b>: Returns the number of elements in the nth bucket.
2793 //!
2794 //! <b>Complexity</b>: Constant.
2795 //!
2796 //! <b>Throws</b>: Nothing.
2797 size_type bucket_size(size_type n) const BOOST_NOEXCEPT;
2798 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2799
2800 //! <b>Effects</b>: Returns the index of the bucket in which elements
2801 //! with keys equivalent to k would be found, if any such element existed.
2802 //!
2803 //! <b>Complexity</b>: Constant.
2804 //!
2805 //! <b>Throws</b>: If the hash functor throws.
2806 //!
2807 //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
2808 BOOST_INTRUSIVE_FORCEINLINE size_type bucket(const key_type& k) const
2809 { return this->bucket(k, this->priv_hasher()); }
2810
2811 //! <b>Requires</b>: "hash_func" must be a hash function that induces
2812 //! the same hash values as the stored hasher. The difference is that
2813 //! "hash_func" hashes the given key instead of the value_type.
2814 //!
2815 //! <b>Effects</b>: Returns the index of the bucket in which elements
2816 //! with keys equivalent to k would be found, if any such element existed.
2817 //!
2818 //! <b>Complexity</b>: Constant.
2819 //!
2820 //! <b>Throws</b>: If hash_func throws.
2821 //!
2822 //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
2823 template<class KeyType, class KeyHasher>
2824 BOOST_INTRUSIVE_FORCEINLINE size_type bucket(const KeyType& k, KeyHasher hash_func) const
2825 { return this->priv_hash_to_bucket(hash_func(k)); }
2826
2827 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2828 //! <b>Effects</b>: Returns the bucket array pointer passed in the constructor
2829 //! or the last rehash function.
2830 //!
2831 //! <b>Complexity</b>: Constant.
2832 //!
2833 //! <b>Throws</b>: Nothing.
2834 bucket_ptr bucket_pointer() const BOOST_NOEXCEPT;
2835
2836 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2837 //!
2838 //! <b>Effects</b>: Returns a local_iterator pointing to the beginning
2839 //! of the sequence stored in the bucket n.
2840 //!
2841 //! <b>Complexity</b>: Constant.
2842 //!
2843 //! <b>Throws</b>: Nothing.
2844 //!
2845 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2846 //! containing all of the elements in the nth bucket.
2847 local_iterator begin(size_type n) BOOST_NOEXCEPT;
2848
2849 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2850 //!
2851 //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
2852 //! of the sequence stored in the bucket n.
2853 //!
2854 //! <b>Complexity</b>: Constant.
2855 //!
2856 //! <b>Throws</b>: Nothing.
2857 //!
2858 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2859 //! containing all of the elements in the nth bucket.
2860 const_local_iterator begin(size_type n) const BOOST_NOEXCEPT;
2861
2862 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2863 //!
2864 //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
2865 //! of the sequence stored in the bucket n.
2866 //!
2867 //! <b>Complexity</b>: Constant.
2868 //!
2869 //! <b>Throws</b>: Nothing.
2870 //!
2871 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2872 //! containing all of the elements in the nth bucket.
2873 const_local_iterator cbegin(size_type n) const BOOST_NOEXCEPT;
2874
2875 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2876 //!
2877 //! <b>Effects</b>: Returns a local_iterator pointing to the end
2878 //! of the sequence stored in the bucket n.
2879 //!
2880 //! <b>Complexity</b>: Constant.
2881 //!
2882 //! <b>Throws</b>: Nothing.
2883 //!
2884 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2885 //! containing all of the elements in the nth bucket.
2886 local_iterator end(size_type n) BOOST_NOEXCEPT;
2887
2888 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2889 //!
2890 //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
2891 //! of the sequence stored in the bucket n.
2892 //!
2893 //! <b>Complexity</b>: Constant.
2894 //!
2895 //! <b>Throws</b>: Nothing.
2896 //!
2897 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2898 //! containing all of the elements in the nth bucket.
2899 const_local_iterator end(size_type n) const BOOST_NOEXCEPT;
2900
2901 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
2902 //!
2903 //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
2904 //! of the sequence stored in the bucket n.
2905 //!
2906 //! <b>Complexity</b>: Constant.
2907 //!
2908 //! <b>Throws</b>: Nothing.
2909 //!
2910 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
2911 //! containing all of the elements in the nth bucket.
2912 const_local_iterator cend(size_type n) const BOOST_NOEXCEPT;
2913 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2914
2915 //! <b>Requires</b>: new_bucket_traits can hold a pointer to a new bucket array
2916 //! or the same as the old bucket array with a different length. new_size is the length of the
2917 //! the array pointed by new_buckets. If new_bucket_traits.bucket_begin() == this->bucket_pointer()
2918 //! new_bucket_traits.bucket_count() can be bigger or smaller than this->bucket_count().
2919 //! 'new_bucket_traits' copy constructor should not throw.
2920 //!
2921 //! <b>Effects</b>:
2922 //! If `new_bucket_traits.bucket_begin() == this->bucket_pointer()` is false,
2923 //! unlinks values from the old bucket and inserts then in the new one according
2924 //! to the hash value of values.
2925 //!
2926 //! If `new_bucket_traits.bucket_begin() == this->bucket_pointer()` is true,
2927 //! the implementations avoids moving values as much as possible.
2928 //!
2929 //! Bucket traits hold by *this is assigned from new_bucket_traits.
2930 //! If the container is configured as incremental<>, the split bucket is set
2931 //! to the new bucket_count().
2932 //!
2933 //! If store_hash option is true, this method does not use the hash function.
2934 //! If false, the implementation tries to minimize calls to the hash function
2935 //! (e.g. once for equivalent values if optimize_multikey<true> is true).
2936 //!
2937 //! If rehash is successful updates the internal bucket_traits with new_bucket_traits.
2938 //!
2939 //! <b>Complexity</b>: Average case linear in this->size(), worst case quadratic.
2940 //!
2941 //! <b>Throws</b>: If the hasher functor throws. Basic guarantee.
2942 BOOST_INTRUSIVE_FORCEINLINE void rehash(const bucket_traits &new_bucket_traits)
2943 { this->rehash_impl(new_bucket_traits, false); }
2944
2945 //! <b>Note</b>: This function is used when keys from inserted elements are changed
2946 //! (e.g. a language change when key is a string) but uniqueness and hash properties are
2947 //! preserved so a fast full rehash recovers invariants for *this without extracting and
2948 //! reinserting all elements again.
2949 //!
2950 //! <b>Requires</b>: Calls produced to the hash function should not alter the value uniqueness
2951 //! properties of already inserted elements. If hasher(key1) == hasher(key2) was true when
2952 //! elements were inserted, it shall be true during calls produced in the execution of this function.
2953 //!
2954 //! key_equal is not called inside this function so it is assumed that key_equal(value1, value2)
2955 //! should produce the same results as before for inserted elements.
2956 //!
2957 //! <b>Effects</b>: Reprocesses all values hold by *this, recalculating their hash values
2958 //! and redistributing them though the buckets.
2959 //!
2960 //! If store_hash option is true, this method uses the hash function and updates the stored hash value.
2961 //!
2962 //! <b>Complexity</b>: Average case linear in this->size(), worst case quadratic.
2963 //!
2964 //! <b>Throws</b>: If the hasher functor throws. Basic guarantee.
2965 BOOST_INTRUSIVE_FORCEINLINE void full_rehash()
2966 { this->rehash_impl(this->priv_bucket_traits(), true); }
2967
2968 //! <b>Requires</b>:
2969 //!
2970 //! <b>Effects</b>:
2971 //!
2972 //! <b>Complexity</b>:
2973 //!
2974 //! <b>Throws</b>:
2975 //!
2976 //! <b>Note</b>: this method is only available if incremental<true> option is activated.
2977 bool incremental_rehash(bool grow = true)
2978 {
2979 //This function is only available for containers with incremental hashing
2980 BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
2981 const std::size_t split_idx = this->priv_split_traits().get_size();
2982 const std::size_t bucket_cnt = this->bucket_count();
2983 bool ret = false;
2984
2985 if(grow){
2986 //Test if the split variable can be changed
2987 if((ret = split_idx < bucket_cnt)){
2988 const std::size_t bucket_to_rehash = split_idx - bucket_cnt/2u;
2989 bucket_type &old_bucket = this->priv_bucket(bucket_to_rehash);
2990 this->priv_split_traits().increment();
2991
2992 //Anti-exception stuff: if an exception is thrown while
2993 //moving elements from old_bucket to the target bucket, all moved
2994 //elements are moved back to the original one.
2995 detail::incremental_rehash_rollback<bucket_type, split_traits> rollback
2996 ( this->priv_bucket(split_idx), old_bucket, this->priv_split_traits());
2997 for( siterator before_i(old_bucket.before_begin()), i(old_bucket.begin()), end_sit(old_bucket.end())
2998 ; i != end_sit; i = before_i, ++i){
2999 const value_type &v = this->priv_value_from_slist_node(i.pointed_node());
3000 const std::size_t hash_value = this->priv_stored_or_compute_hash(v, store_hash_t());
3001 const std::size_t new_n = this->priv_hash_to_bucket(hash_value);
3002 siterator const last = (priv_last_in_group)(i);
3003 if(new_n == bucket_to_rehash){
3004 before_i = last;
3005 }
3006 else{
3007 bucket_type &new_b = this->priv_bucket(new_n);
3008 new_b.splice_after(new_b.before_begin(), old_bucket, before_i, last);
3009 }
3010 }
3011 rollback.release();
3012 this->priv_erasure_update_cache();
3013 }
3014 }
3015 else if((ret = split_idx > bucket_cnt/2u)){ //!grow
3016 const std::size_t target_bucket_num = split_idx - 1u - bucket_cnt/2u;
3017 bucket_type &target_bucket = this->priv_bucket(target_bucket_num);
3018 bucket_type &source_bucket = this->priv_bucket(split_idx-1u);
3019 target_bucket.splice_after(target_bucket.cbefore_begin(), source_bucket);
3020 this->priv_split_traits().decrement();
3021 this->priv_insertion_update_cache(target_bucket_num);
3022 }
3023 return ret;
3024 }
3025
3026 //! <b>Effects</b>: If new_bucket_traits.bucket_count() is not
3027 //! this->bucket_count()/2 or this->bucket_count()*2, or
3028 //! this->split_bucket() != new_bucket_traits.bucket_count() returns false
3029 //! and does nothing.
3030 //!
3031 //! Otherwise, copy assigns new_bucket_traits to the internal bucket_traits
3032 //! and transfers all the objects from old buckets to the new ones.
3033 //!
3034 //! <b>Complexity</b>: Linear to size().
3035 //!
3036 //! <b>Throws</b>: Nothing
3037 //!
3038 //! <b>Note</b>: this method is only available if incremental<true> option is activated.
3039 bool incremental_rehash(const bucket_traits &new_bucket_traits) BOOST_NOEXCEPT
3040 {
3041 //This function is only available for containers with incremental hashing
3042 BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
3043 std::size_t new_bucket_count = new_bucket_traits.bucket_count();
3044 BOOST_INTRUSIVE_INVARIANT_ASSERT(sizeof(SizeType) >= sizeof(std::size_t) || new_bucket_count <= SizeType(-1));
3045 size_type const new_bucket_traits_size = static_cast<SizeType>(new_bucket_count);
3046 size_type const cur_bucket_traits = this->bucket_count();
3047 const size_type split_idx = this->split_count();
3048
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))
3052 return false;
3053 }
3054 else if(new_bucket_traits_size == cur_bucket_traits/2){
3055 if(!(split_idx <= new_bucket_traits_size))
3056 return false;
3057 }
3058 else{
3059 return false;
3060 }
3061
3062 const size_type ini_n = (size_type)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()[difference_type(n)];
3068 bucket_type &old_bucket = old_buckets[difference_type(n)];
3069 new_bucket.splice_after(new_bucket.cbefore_begin(), old_bucket);
3070 }
3071 //Put cache to safe position
3072 this->priv_initialize_cache();
3073 this->priv_insertion_update_cache(ini_n);
3074 }
3075 return true;
3076 }
3077
3078 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
3079
3080 //! <b>Requires</b>: incremental<> option must be set
3081 //!
3082 //! <b>Effects</b>: returns the current split count
3083 //!
3084 //! <b>Complexity</b>: Constant
3085 //!
3086 //! <b>Throws</b>: Nothing
3087 size_type split_count() const BOOST_NOEXCEPT;
3088
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.
3094 //!
3095 //! <b>Complexity</b>: Amortized constant time.
3096 //!
3097 //! <b>Throws</b>: Nothing.
3098 static size_type suggested_upper_bucket_count(size_type n) BOOST_NOEXCEPT;
3099
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.
3105 //!
3106 //! <b>Complexity</b>: Amortized constant time.
3107 //!
3108 //! <b>Throws</b>: Nothing.
3109 static size_type suggested_lower_bucket_count(size_type n) BOOST_NOEXCEPT;
3110 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
3111
3112
3113 friend bool operator==(const hashtable_impl &x, const hashtable_impl &y)
3114 {
3115 //Taken from N3068
3116 if(constant_time_size && x.size() != y.size()){
3117 return false;
3118 }
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) ){
3125 return false;
3126 }
3127 ix = eqx.second;
3128 }
3129 return true;
3130 }
3131
3132 friend bool operator!=(const hashtable_impl &x, const hashtable_impl &y)
3133 { return !(x == y); }
3134
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()); }
3137
3138 friend bool operator>(const hashtable_impl &x, const hashtable_impl &y)
3139 { return y < x; }
3140
3141 friend bool operator<=(const hashtable_impl &x, const hashtable_impl &y)
3142 { return !(y < x); }
3143
3144 friend bool operator>=(const hashtable_impl &x, const hashtable_impl &y)
3145 { return !(x < y); }
3146
3147 /// @cond
3148 BOOST_INTRUSIVE_FORCEINLINE void check() const {}
3149 private:
3150
3151 void rehash_impl(const bucket_traits &new_bucket_traits, bool do_full_rehash)
3152 {
3153 std::size_t nbc = new_bucket_traits.bucket_count();
3154 BOOST_INTRUSIVE_INVARIANT_ASSERT(sizeof(SizeType) >= sizeof(std::size_t) || nbc <= SizeType(-1));
3155
3156 const bucket_ptr new_buckets = new_bucket_traits.bucket_begin();
3157 size_type new_bucket_count = static_cast<SizeType>(nbc);
3158 const bucket_ptr old_buckets = this->priv_bucket_pointer();
3159 size_type old_bucket_count = this->bucket_count();
3160
3161 //Check power of two bucket array if the option is activated
3162 BOOST_INTRUSIVE_INVARIANT_ASSERT
3163 (!power_2_buckets || (0 == (new_bucket_count & (new_bucket_count-1u))));
3164
3165 size_type n = (size_type)this->priv_get_cache_bucket_num();
3166 const bool same_buffer = old_buckets == new_buckets;
3167 //If the new bucket length is a common factor
3168 //of the old one we can avoid hash calculations.
3169 const bool fast_shrink = (!do_full_rehash) && (!incremental) && (old_bucket_count >= new_bucket_count) &&
3170 (power_2_buckets || (old_bucket_count % new_bucket_count) == 0);
3171 //If we are shrinking the same bucket array and it's
3172 //is a fast shrink, just rehash the last nodes
3173 size_type new_first_bucket_num = new_bucket_count;
3174 if(same_buffer && fast_shrink && (n < new_bucket_count)){
3175 new_first_bucket_num = n;
3176 n = new_bucket_count;
3177 }
3178
3179 //Anti-exception stuff: they destroy the elements if something goes wrong.
3180 //If the source and destination buckets are the same, the second rollback function
3181 //is harmless, because all elements have been already unlinked and destroyed
3182 typedef detail::init_disposer<node_algorithms> NodeDisposer;
3183 typedef detail::exception_array_disposer<bucket_type, NodeDisposer, size_type> ArrayDisposer;
3184 NodeDisposer node_disp;
3185 ArrayDisposer rollback1(new_buckets[0], node_disp, new_bucket_count);
3186 ArrayDisposer rollback2(old_buckets[0], node_disp, old_bucket_count);
3187
3188 //Put size in a safe value for rollback exception
3189 size_type const size_backup = this->priv_size_traits().get_size();
3190 this->priv_size_traits().set_size(0);
3191 //Put cache to safe position
3192 this->priv_initialize_cache();
3193 this->priv_insertion_update_cache(size_type(0u));
3194
3195 //Iterate through nodes
3196 for(; n < old_bucket_count; ++n){
3197 bucket_type &old_bucket = old_buckets[difference_type(n)];
3198 if(!fast_shrink){
3199 for( siterator before_i(old_bucket.before_begin()), i(old_bucket.begin()), end_sit(old_bucket.end())
3200 ; i != end_sit
3201 ; i = before_i, ++i){
3202
3203 //First obtain hash value (and store it if do_full_rehash)
3204 std::size_t hash_value;
3205 if(do_full_rehash){
3206 value_type &v = this->priv_value_from_slist_node(i.pointed_node());
3207 hash_value = this->priv_hasher()(key_of_value()(v));
3208 node_functions_t::store_hash(pointer_traits<node_ptr>::pointer_to(this->priv_value_to_node(v)), hash_value, store_hash_t());
3209 }
3210 else{
3211 const value_type &v = this->priv_value_from_slist_node(i.pointed_node());
3212 hash_value = this->priv_stored_or_compute_hash(v, store_hash_t());
3213 }
3214
3215 //Now calculate the new bucket position
3216 const size_type new_n = (size_type)detail::hash_to_bucket_split<power_2_buckets, incremental>
3217 (hash_value, new_bucket_count, new_bucket_count);
3218
3219 //Update first used bucket cache
3220 if(cache_begin && new_n < new_first_bucket_num)
3221 new_first_bucket_num = new_n;
3222
3223 //If the target bucket is new, transfer the whole group
3224 siterator const last = (priv_last_in_group)(i);
3225
3226 if(same_buffer && new_n == n){
3227 before_i = last;
3228 }
3229 else{
3230 bucket_type &new_b = new_buckets[difference_type(new_n)];
3231 new_b.splice_after(new_b.before_begin(), old_bucket, before_i, last);
3232 }
3233 }
3234 }
3235 else{
3236 const size_type new_n = (size_type)detail::hash_to_bucket_split
3237 <power_2_buckets, incremental>(n, new_bucket_count, new_bucket_count);
3238 if(cache_begin && new_n < new_first_bucket_num)
3239 new_first_bucket_num = new_n;
3240 bucket_type &new_b = new_buckets[difference_type(new_n)];
3241 new_b.splice_after( new_b.before_begin()
3242 , old_bucket
3243 , old_bucket.before_begin()
3244 , bucket_plus_vtraits_t::priv_get_last(old_bucket, optimize_multikey_t()));
3245 }
3246 }
3247
3248 this->priv_size_traits().set_size(size_backup);
3249 this->priv_split_traits().set_size(new_bucket_count);
3250 if(&new_bucket_traits != &this->priv_bucket_traits()){
3251 this->priv_bucket_traits() = new_bucket_traits;
3252 }
3253 this->priv_initialize_cache();
3254 this->priv_insertion_update_cache(new_first_bucket_num);
3255 rollback1.release();
3256 rollback2.release();
3257 }
3258
3259 template <class MaybeConstHashtableImpl, class Cloner, class Disposer>
3260 void priv_clone_from(MaybeConstHashtableImpl &src, Cloner cloner, Disposer disposer)
3261 {
3262 this->clear_and_dispose(disposer);
3263 if(!constant_time_size || !src.empty()){
3264 const size_type src_bucket_count = src.bucket_count();
3265 const size_type dst_bucket_count = this->bucket_count();
3266 //Check power of two bucket array if the option is activated
3267 BOOST_INTRUSIVE_INVARIANT_ASSERT
3268 (!power_2_buckets || (0 == (src_bucket_count & (src_bucket_count-1))));
3269 BOOST_INTRUSIVE_INVARIANT_ASSERT
3270 (!power_2_buckets || (0 == (dst_bucket_count & (dst_bucket_count-1))));
3271 //If src bucket count is bigger or equal, structural copy is possible
3272 const bool structural_copy = (!incremental) && (src_bucket_count >= dst_bucket_count) &&
3273 (power_2_buckets || (src_bucket_count % dst_bucket_count) == 0);
3274 if(structural_copy){
3275 this->priv_structural_clone_from(src, cloner, disposer);
3276 }
3277 else{
3278 //Unlike previous cloning algorithm, this can throw
3279 //if cloner, hasher or comparison functor throw
3280 typedef typename detail::if_c< detail::is_const<MaybeConstHashtableImpl>::value
3281 , typename MaybeConstHashtableImpl::const_iterator
3282 , typename MaybeConstHashtableImpl::iterator
3283 >::type clone_iterator;
3284 clone_iterator b(src.begin()), e(src.end());
3285 detail::exception_disposer<hashtable_impl, Disposer> rollback(*this, disposer);
3286 for(; b != e; ++b){
3287 //No need to check for duplicates and insert it in the first position
3288 //as this is an unordered container. So use minimal insertion code
3289 std::size_t const hash_to_store = this->priv_stored_or_compute_hash(*b, store_hash_t());;
3290 size_type const bucket_number = this->priv_hash_to_bucket(hash_to_store);
3291 typedef typename detail::if_c
3292 <detail::is_const<MaybeConstHashtableImpl>::value, const_reference, reference>::type reference_type;
3293 reference_type r = *b;
3294 this->priv_clone_front_in_bucket<reference_type>(bucket_number, r, hash_to_store, cloner);
3295 }
3296 rollback.release();
3297 }
3298 }
3299 }
3300
3301 template<class ValueReference, class Cloner>
3302 void priv_clone_front_in_bucket( size_type const bucket_number
3303 , typename detail::identity<ValueReference>::type src_ref
3304 , std::size_t const hash_to_store, Cloner cloner)
3305 {
3306 //No need to check for duplicates and insert it in the first position
3307 //as this is an unordered container. So use minimal insertion code
3308 //std::size_t const hash_value = this->priv_stored_or_compute_hash(src_ref, store_hash_t());;
3309 //size_type const bucket_number = this->priv_hash_to_bucket(hash_value);
3310 bucket_type &cur_bucket = this->priv_bucket(bucket_number);
3311 siterator const prev(cur_bucket.before_begin());
3312 //Just check if the cloned node is equal to the first inserted value in the new bucket
3313 //as equal src values were contiguous and they should be already inserted in the
3314 //destination bucket.
3315 bool const next_is_in_group = optimize_multikey && !cur_bucket.empty() &&
3316 this->priv_equal()( key_of_value()(src_ref)
3317 , key_of_value()(this->priv_value_from_slist_node((++siterator(prev)).pointed_node())));
3318 this->priv_insert_equal_after_find(*cloner(src_ref), bucket_number, hash_to_store, prev, next_is_in_group);
3319 }
3320
3321 template <class MaybeConstHashtableImpl, class Cloner, class Disposer>
3322 void priv_structural_clone_from(MaybeConstHashtableImpl &src, Cloner cloner, Disposer disposer)
3323 {
3324 //First clone the first ones
3325 const size_type src_bucket_count = src.bucket_count();
3326 const size_type dst_bucket_count = this->bucket_count();
3327 size_type constructed = 0;
3328 typedef node_cast_adaptor< detail::node_disposer<Disposer, value_traits, CircularSListAlgorithms>
3329 , slist_node_ptr, node_ptr > NodeDisposer;
3330 NodeDisposer node_disp(disposer, &this->priv_value_traits());
3331
3332 detail::exception_array_disposer<bucket_type, NodeDisposer, size_type>
3333 rollback(this->priv_bucket(0), node_disp, constructed);
3334 //Now insert the remaining ones using the modulo trick
3335 for( //"constructed" already initialized
3336 ; constructed < src_bucket_count
3337 ; ++constructed){
3338 //Since incremental hashing can't be structurally copied, avoid hash_to_bucket_split
3339 const size_type new_n = (size_type) detail::hash_to_bucket(constructed, dst_bucket_count, detail::bool_<power_2_buckets>());
3340 bucket_type &src_b = src.priv_bucket(constructed);
3341 for( siterator b(src_b.begin()), e(src_b.end()); b != e; ++b){
3342 slist_node_ptr const n(b.pointed_node());
3343 typedef typename detail::if_c
3344 <detail::is_const<MaybeConstHashtableImpl>::value, const_reference, reference>::type reference_type;
3345 reference_type r = this->priv_value_from_slist_node(n);
3346 this->priv_clone_front_in_bucket<reference_type>
3347 (new_n, r, this->priv_stored_hash(n, store_hash_t()), cloner);
3348 }
3349 }
3350 this->priv_hasher() = src.priv_hasher();
3351 this->priv_equal() = src.priv_equal();
3352 rollback.release();
3353 this->priv_size_traits().set_size(src.priv_size_traits().get_size());
3354 this->priv_split_traits().set_size(dst_bucket_count);
3355 this->priv_insertion_update_cache(0u);
3356 this->priv_erasure_update_cache();
3357 }
3358
3359 size_type priv_hash_to_bucket(std::size_t hash_value) const
3360 {
3361 return static_cast<size_type>(detail::hash_to_bucket_split<power_2_buckets, incremental>
3362 (hash_value, this->priv_bucket_traits().bucket_count(), this->priv_split_traits().get_size()));
3363 }
3364
3365 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)
3366 {
3367 //Now store hash if needed
3368 node_ptr n = pointer_traits<node_ptr>::pointer_to(this->priv_value_to_node(value));
3369 node_functions_t::store_hash(n, hash_value, store_hash_t());
3370 //Checks for some modes
3371 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::unique(n));
3372 //Shortcut to optimize_multikey cases
3373 group_functions_t::insert_in_group
3374 ( next_is_in_group ? detail::dcast_bucket_ptr<node>((++siterator(prev)).pointed_node()) : n
3375 , n, optimize_multikey_t());
3376 //Update cache and increment size if needed
3377 this->priv_insertion_update_cache(bucket_num);
3378 this->priv_size_traits().increment();
3379 //Insert the element in the bucket after it
3380 return iterator(bucket_type::s_insert_after(prev, *n), &this->get_bucket_value_traits());
3381 }
3382
3383 template<class KeyType, class KeyHasher, class KeyEqual>
3384 siterator priv_find //In case it is not found previt is bucket.before_begin()
3385 ( const KeyType &key, KeyHasher hash_func
3386 , KeyEqual equal_func, size_type &bucket_number, std::size_t &h, siterator &previt) const
3387 {
3388 h = hash_func(key);
3389 return this->priv_find_with_hash(key, equal_func, bucket_number, h, previt);
3390 }
3391
3392 template<class KeyType, class KeyEqual>
3393 bool priv_is_value_equal_to_key(const value_type &v, const std::size_t h, const KeyType &key, KeyEqual equal_func) const
3394 {
3395 (void)h;
3396 return (!compare_hash || this->priv_stored_or_compute_hash(v, store_hash_t()) == h) && equal_func(key, key_of_value()(v));
3397 }
3398
3399 //return previous iterator to the next equal range group in case
3400 static siterator priv_last_in_group(const siterator &it_first_in_group) BOOST_NOEXCEPT
3401 {
3402 return bucket_type::s_iterator_to
3403 (*group_functions_t::get_last_in_group
3404 (detail::dcast_bucket_ptr<node>(it_first_in_group.pointed_node()), optimize_multikey_t()));
3405 }
3406
3407 template<class KeyType, class KeyEqual>
3408 siterator priv_find_with_hash //In case it is not found previt is bucket.before_begin()
3409 ( const KeyType &key, KeyEqual equal_func, size_type &bucket_number, const std::size_t h, siterator &previt) const
3410 {
3411 bucket_number = this->priv_hash_to_bucket(h);
3412 bucket_type &b = this->priv_bucket(bucket_number);
3413 previt = b.before_begin();
3414 siterator it = previt;
3415 siterator const endit = b.end();
3416
3417 while(++it != endit){
3418 if(this->priv_is_value_equal_to_key(this->priv_value_from_slist_node(it.pointed_node()), h, key, equal_func)){
3419 return it;
3420 }
3421 previt = it = (priv_last_in_group)(it);
3422 }
3423 previt = b.before_begin();
3424 return this->priv_invalid_local_it();
3425 }
3426
3427 template<class KeyType, class KeyHasher, class KeyEqual>
3428 std::pair<siterator, siterator> priv_local_equal_range
3429 ( const KeyType &key
3430 , KeyHasher hash_func
3431 , KeyEqual equal_func
3432 , size_type &found_bucket
3433 , size_type &cnt) const
3434 {
3435 std::size_t internal_cnt = 0;
3436 //Let's see if the element is present
3437
3438 siterator prev;
3439 size_type n_bucket;
3440 std::size_t h;
3441 std::pair<siterator, siterator> to_return
3442 ( this->priv_find(key, hash_func, equal_func, n_bucket, h, prev)
3443 , this->priv_invalid_local_it());
3444
3445 if(to_return.first != to_return.second){
3446 found_bucket = n_bucket;
3447 //If it's present, find the first that it's not equal in
3448 //the same bucket
3449 bucket_type &b = this->priv_bucket(n_bucket);
3450 siterator it = to_return.first;
3451 ++internal_cnt; //At least one is found
3452 if(optimize_multikey){
3453 to_return.second = ++(priv_last_in_group)(it);
3454 internal_cnt += boost::intrusive::iterator_udistance(++it, to_return.second);
3455 }
3456 else{
3457 siterator const bend = b.end();
3458 while(++it != bend &&
3459 this->priv_is_value_equal_to_key(this->priv_value_from_slist_node(it.pointed_node()), h, key, equal_func)){
3460 ++internal_cnt;
3461 }
3462 to_return.second = it;
3463 }
3464 }
3465 cnt = size_type(internal_cnt);
3466 return to_return;
3467 }
3468
3469 template<class KeyType, class KeyHasher, class KeyEqual>
3470 std::pair<siterator, siterator> priv_equal_range
3471 ( const KeyType &key
3472 , KeyHasher hash_func
3473 , KeyEqual equal_func) const
3474 {
3475 size_type n_bucket;
3476 size_type cnt;
3477
3478 //Let's see if the element is present
3479 std::pair<siterator, siterator> to_return
3480 (this->priv_local_equal_range(key, hash_func, equal_func, n_bucket, cnt));
3481 //If not, find the next element as ".second" if ".second" local iterator
3482 //is not pointing to an element.
3483 if(to_return.first != to_return.second &&
3484 to_return.second == this->priv_bucket(n_bucket).end()){
3485 to_return.second = this->priv_invalid_local_it();
3486 ++n_bucket;
3487 for( const size_type max_bucket = this->bucket_count()
3488 ; n_bucket != max_bucket
3489 ; ++n_bucket){
3490 bucket_type &b = this->priv_bucket(n_bucket);
3491 if(!b.empty()){
3492 to_return.second = b.begin();
3493 break;
3494 }
3495 }
3496 }
3497 return to_return;
3498 }
3499
3500 size_type priv_get_bucket_num(siterator it) BOOST_NOEXCEPT
3501 { return this->priv_get_bucket_num_hash_dispatch(it, store_hash_t()); }
3502
3503 size_type priv_get_bucket_num_hash_dispatch(siterator it, detail::true_) BOOST_NOEXCEPT //store_hash
3504 {
3505 return (size_type)this->priv_hash_to_bucket
3506 (this->priv_stored_hash(it.pointed_node(), store_hash_t()));
3507 }
3508
3509 size_type priv_get_bucket_num_hash_dispatch(siterator it, detail::false_) BOOST_NOEXCEPT //NO store_hash
3510 { return (size_type)this->priv_get_bucket_num_no_hash_store(it, optimize_multikey_t()); }
3511
3512 static siterator priv_get_previous(bucket_type &b, siterator i) BOOST_NOEXCEPT
3513 { return bucket_plus_vtraits_t::priv_get_previous(b, i, optimize_multikey_t()); }
3514
3515 /// @endcond
3516 };
3517
3518 /// @cond
3519 template < class T
3520 , bool UniqueKeys
3521 , class PackedOptions
3522 >
3523 struct make_bucket_traits
3524 {
3525 //Real value traits must be calculated from options
3526 typedef typename detail::get_value_traits
3527 <T, typename PackedOptions::proto_value_traits>::type value_traits;
3528
3529 typedef typename PackedOptions::bucket_traits specified_bucket_traits;
3530
3531 //Real bucket traits must be calculated from options and calculated value_traits
3532 typedef typename get_slist_impl
3533 <typename reduced_slist_node_traits
3534 <typename value_traits::node_traits>::type
3535 >::type slist_impl;
3536
3537 typedef typename
3538 detail::if_c< detail::is_same
3539 < specified_bucket_traits
3540 , default_bucket_traits
3541 >::value
3542 , bucket_traits_impl<slist_impl>
3543 , specified_bucket_traits
3544 >::type type;
3545 };
3546 /// @endcond
3547
3548 //! Helper metafunction to define a \c hashtable that yields to the same type when the
3549 //! same options (either explicitly or implicitly) are used.
3550 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
3551 template<class T, class ...Options>
3552 #else
3553 template<class T, class O1 = void, class O2 = void
3554 , class O3 = void, class O4 = void
3555 , class O5 = void, class O6 = void
3556 , class O7 = void, class O8 = void
3557 , class O9 = void, class O10= void
3558 >
3559 #endif
3560 struct make_hashtable
3561 {
3562 /// @cond
3563 typedef typename pack_options
3564 < hashtable_defaults,
3565 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
3566 O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
3567 #else
3568 Options...
3569 #endif
3570 >::type packed_options;
3571
3572 typedef typename detail::get_value_traits
3573 <T, typename packed_options::proto_value_traits>::type value_traits;
3574
3575 typedef typename make_bucket_traits
3576 <T, false, packed_options>::type bucket_traits;
3577
3578 typedef hashtable_impl
3579 < value_traits
3580 , typename packed_options::key_of_value
3581 , typename packed_options::hash
3582 , typename packed_options::equal
3583 , bucket_traits
3584 , typename packed_options::size_type
3585 , (std::size_t(false)*hash_bool_flags::unique_keys_pos)
3586 |(std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos)
3587 |(std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos)
3588 |(std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos)
3589 |(std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos)
3590 |(std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos)
3591 > implementation_defined;
3592
3593 /// @endcond
3594 typedef implementation_defined type;
3595 };
3596
3597 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
3598
3599 #if defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
3600 template<class T, class ...Options>
3601 #else
3602 template<class T, class O1, class O2, class O3, class O4, class O5, class O6, class O7, class O8, class O9, class O10>
3603 #endif
3604 class hashtable
3605 : public make_hashtable<T,
3606 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
3607 O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
3608 #else
3609 Options...
3610 #endif
3611 >::type
3612 {
3613 typedef typename make_hashtable<T,
3614 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
3615 O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
3616 #else
3617 Options...
3618 #endif
3619 >::type Base;
3620 BOOST_MOVABLE_BUT_NOT_COPYABLE(hashtable)
3621
3622 public:
3623 typedef typename Base::value_traits value_traits;
3624 typedef typename Base::iterator iterator;
3625 typedef typename Base::const_iterator const_iterator;
3626 typedef typename Base::bucket_ptr bucket_ptr;
3627 typedef typename Base::size_type size_type;
3628 typedef typename Base::hasher hasher;
3629 typedef typename Base::bucket_traits bucket_traits;
3630 typedef typename Base::key_equal key_equal;
3631
3632 //Assert if passed value traits are compatible with the type
3633 BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
3634
3635 BOOST_INTRUSIVE_FORCEINLINE explicit hashtable ( const bucket_traits &b_traits
3636 , const hasher & hash_func = hasher()
3637 , const key_equal &equal_func = key_equal()
3638 , const value_traits &v_traits = value_traits())
3639 : Base(b_traits, hash_func, equal_func, v_traits)
3640 {}
3641
3642 BOOST_INTRUSIVE_FORCEINLINE hashtable(BOOST_RV_REF(hashtable) x)
3643 : Base(BOOST_MOVE_BASE(Base, x))
3644 {}
3645
3646 BOOST_INTRUSIVE_FORCEINLINE hashtable& operator=(BOOST_RV_REF(hashtable) x)
3647 { return static_cast<hashtable&>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
3648
3649 template <class Cloner, class Disposer>
3650 BOOST_INTRUSIVE_FORCEINLINE void clone_from(const hashtable &src, Cloner cloner, Disposer disposer)
3651 { Base::clone_from(src, cloner, disposer); }
3652
3653 template <class Cloner, class Disposer>
3654 BOOST_INTRUSIVE_FORCEINLINE void clone_from(BOOST_RV_REF(hashtable) src, Cloner cloner, Disposer disposer)
3655 { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
3656 };
3657
3658 #endif
3659
3660 } //namespace intrusive
3661 } //namespace boost
3662
3663 #include <boost/intrusive/detail/config_end.hpp>
3664
3665 #endif //BOOST_INTRUSIVE_HASHTABLE_HPP