Chris@16
|
1 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Ion Gaztanaga 2006-2013
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //
|
Chris@16
|
9 // See http://www.boost.org/libs/intrusive for documentation.
|
Chris@16
|
10 //
|
Chris@16
|
11 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
12 #ifndef BOOST_INTRUSIVE_HASHTABLE_HPP
|
Chris@16
|
13 #define BOOST_INTRUSIVE_HASHTABLE_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/intrusive/detail/config_begin.hpp>
|
Chris@101
|
16 #include <boost/intrusive/intrusive_fwd.hpp>
|
Chris@101
|
17
|
Chris@16
|
18 //General intrusive utilities
|
Chris@16
|
19 #include <boost/intrusive/detail/hashtable_node.hpp>
|
Chris@16
|
20 #include <boost/intrusive/detail/transform_iterator.hpp>
|
Chris@16
|
21 #include <boost/intrusive/link_mode.hpp>
|
Chris@16
|
22 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
|
Chris@101
|
23 #include <boost/intrusive/detail/is_stateful_value_traits.hpp>
|
Chris@101
|
24 #include <boost/intrusive/detail/node_to_value.hpp>
|
Chris@101
|
25 #include <boost/intrusive/detail/exception_disposer.hpp>
|
Chris@101
|
26 #include <boost/intrusive/detail/node_cloner_disposer.hpp>
|
Chris@101
|
27 #include <boost/intrusive/detail/simple_disposers.hpp>
|
Chris@101
|
28 #include <boost/intrusive/detail/size_holder.hpp>
|
Chris@101
|
29
|
Chris@16
|
30 //Implementation utilities
|
Chris@16
|
31 #include <boost/intrusive/unordered_set_hook.hpp>
|
Chris@16
|
32 #include <boost/intrusive/slist.hpp>
|
Chris@16
|
33 #include <boost/intrusive/pointer_traits.hpp>
|
Chris@16
|
34 #include <boost/intrusive/detail/mpl.hpp>
|
Chris@101
|
35
|
Chris@101
|
36 //boost
|
Chris@101
|
37 #include <boost/functional/hash.hpp>
|
Chris@101
|
38 #include <boost/intrusive/detail/assert.hpp>
|
Chris@101
|
39 #include <boost/static_assert.hpp>
|
Chris@101
|
40 #include <boost/move/utility_core.hpp>
|
Chris@101
|
41 #include <boost/move/adl_move_swap.hpp>
|
Chris@101
|
42
|
Chris@101
|
43 //std C++
|
Chris@101
|
44 #include <boost/intrusive/detail/minimal_less_equal_header.hpp> //std::equal_to
|
Chris@101
|
45 #include <boost/intrusive/detail/minimal_pair_header.hpp> //std::pair
|
Chris@101
|
46 #include <algorithm> //std::lower_bound, std::upper_bound
|
Chris@101
|
47 #include <cstddef> //std::size_t
|
Chris@101
|
48
|
Chris@101
|
49 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@101
|
50 # pragma once
|
Chris@101
|
51 #endif
|
Chris@16
|
52
|
Chris@16
|
53 namespace boost {
|
Chris@16
|
54 namespace intrusive {
|
Chris@16
|
55
|
Chris@16
|
56 /// @cond
|
Chris@16
|
57
|
Chris@101
|
58 template<int Dummy = 0>
|
Chris@101
|
59 struct prime_list_holder
|
Chris@101
|
60 {
|
Chris@101
|
61 static const std::size_t prime_list[];
|
Chris@101
|
62 static const std::size_t prime_list_size;
|
Chris@101
|
63 };
|
Chris@101
|
64
|
Chris@101
|
65 //We only support LLP64(Win64) or LP64(most Unix) data models
|
Chris@101
|
66 #ifdef _WIN64 //In 64 bit windows sizeof(size_t) == sizeof(unsigned long long)
|
Chris@101
|
67 #define BOOST_INTRUSIVE_PRIME_C(NUMBER) NUMBER##ULL
|
Chris@101
|
68 #define BOOST_INTRUSIVE_64_BIT_SIZE_T 1
|
Chris@101
|
69 #else //In 32 bit windows and 32/64 bit unixes sizeof(size_t) == sizeof(unsigned long)
|
Chris@101
|
70 #define BOOST_INTRUSIVE_PRIME_C(NUMBER) NUMBER##UL
|
Chris@101
|
71 #define BOOST_INTRUSIVE_64_BIT_SIZE_T (((((ULONG_MAX>>16)>>16)>>16)>>15) != 0)
|
Chris@101
|
72 #endif
|
Chris@101
|
73
|
Chris@101
|
74 template<int Dummy>
|
Chris@101
|
75 const std::size_t prime_list_holder<Dummy>::prime_list[] = {
|
Chris@101
|
76 BOOST_INTRUSIVE_PRIME_C(3), BOOST_INTRUSIVE_PRIME_C(7),
|
Chris@101
|
77 BOOST_INTRUSIVE_PRIME_C(11), BOOST_INTRUSIVE_PRIME_C(17),
|
Chris@101
|
78 BOOST_INTRUSIVE_PRIME_C(29), BOOST_INTRUSIVE_PRIME_C(53),
|
Chris@101
|
79 BOOST_INTRUSIVE_PRIME_C(97), BOOST_INTRUSIVE_PRIME_C(193),
|
Chris@101
|
80 BOOST_INTRUSIVE_PRIME_C(389), BOOST_INTRUSIVE_PRIME_C(769),
|
Chris@101
|
81 BOOST_INTRUSIVE_PRIME_C(1543), BOOST_INTRUSIVE_PRIME_C(3079),
|
Chris@101
|
82 BOOST_INTRUSIVE_PRIME_C(6151), BOOST_INTRUSIVE_PRIME_C(12289),
|
Chris@101
|
83 BOOST_INTRUSIVE_PRIME_C(24593), BOOST_INTRUSIVE_PRIME_C(49157),
|
Chris@101
|
84 BOOST_INTRUSIVE_PRIME_C(98317), BOOST_INTRUSIVE_PRIME_C(196613),
|
Chris@101
|
85 BOOST_INTRUSIVE_PRIME_C(393241), BOOST_INTRUSIVE_PRIME_C(786433),
|
Chris@101
|
86 BOOST_INTRUSIVE_PRIME_C(1572869), BOOST_INTRUSIVE_PRIME_C(3145739),
|
Chris@101
|
87 BOOST_INTRUSIVE_PRIME_C(6291469), BOOST_INTRUSIVE_PRIME_C(12582917),
|
Chris@101
|
88 BOOST_INTRUSIVE_PRIME_C(25165843), BOOST_INTRUSIVE_PRIME_C(50331653),
|
Chris@101
|
89 BOOST_INTRUSIVE_PRIME_C(100663319), BOOST_INTRUSIVE_PRIME_C(201326611),
|
Chris@101
|
90 BOOST_INTRUSIVE_PRIME_C(402653189), BOOST_INTRUSIVE_PRIME_C(805306457),
|
Chris@101
|
91 BOOST_INTRUSIVE_PRIME_C(1610612741), BOOST_INTRUSIVE_PRIME_C(3221225473),
|
Chris@101
|
92 #if BOOST_INTRUSIVE_64_BIT_SIZE_T
|
Chris@101
|
93 //Taken from Boost.MultiIndex code, thanks to Joaquin M Lopez Munoz.
|
Chris@101
|
94 BOOST_INTRUSIVE_PRIME_C(6442450939), BOOST_INTRUSIVE_PRIME_C(12884901893),
|
Chris@101
|
95 BOOST_INTRUSIVE_PRIME_C(25769803751), BOOST_INTRUSIVE_PRIME_C(51539607551),
|
Chris@101
|
96 BOOST_INTRUSIVE_PRIME_C(103079215111), BOOST_INTRUSIVE_PRIME_C(206158430209),
|
Chris@101
|
97 BOOST_INTRUSIVE_PRIME_C(412316860441), BOOST_INTRUSIVE_PRIME_C(824633720831),
|
Chris@101
|
98 BOOST_INTRUSIVE_PRIME_C(1649267441651), BOOST_INTRUSIVE_PRIME_C(3298534883309),
|
Chris@101
|
99 BOOST_INTRUSIVE_PRIME_C(6597069766657), BOOST_INTRUSIVE_PRIME_C(13194139533299),
|
Chris@101
|
100 BOOST_INTRUSIVE_PRIME_C(26388279066623), BOOST_INTRUSIVE_PRIME_C(52776558133303),
|
Chris@101
|
101 BOOST_INTRUSIVE_PRIME_C(105553116266489), BOOST_INTRUSIVE_PRIME_C(211106232532969),
|
Chris@101
|
102 BOOST_INTRUSIVE_PRIME_C(422212465066001), BOOST_INTRUSIVE_PRIME_C(844424930131963),
|
Chris@101
|
103 BOOST_INTRUSIVE_PRIME_C(1688849860263953), BOOST_INTRUSIVE_PRIME_C(3377699720527861),
|
Chris@101
|
104 BOOST_INTRUSIVE_PRIME_C(6755399441055731), BOOST_INTRUSIVE_PRIME_C(13510798882111483),
|
Chris@101
|
105 BOOST_INTRUSIVE_PRIME_C(27021597764222939), BOOST_INTRUSIVE_PRIME_C(54043195528445957),
|
Chris@101
|
106 BOOST_INTRUSIVE_PRIME_C(108086391056891903), BOOST_INTRUSIVE_PRIME_C(216172782113783843),
|
Chris@101
|
107 BOOST_INTRUSIVE_PRIME_C(432345564227567621), BOOST_INTRUSIVE_PRIME_C(864691128455135207),
|
Chris@101
|
108 BOOST_INTRUSIVE_PRIME_C(1729382256910270481), BOOST_INTRUSIVE_PRIME_C(3458764513820540933),
|
Chris@101
|
109 BOOST_INTRUSIVE_PRIME_C(6917529027641081903), BOOST_INTRUSIVE_PRIME_C(13835058055282163729),
|
Chris@101
|
110 BOOST_INTRUSIVE_PRIME_C(18446744073709551557)
|
Chris@101
|
111 #else
|
Chris@101
|
112 BOOST_INTRUSIVE_PRIME_C(4294967291)
|
Chris@101
|
113 #endif
|
Chris@101
|
114 };
|
Chris@101
|
115
|
Chris@101
|
116 #undef BOOST_INTRUSIVE_PRIME_C
|
Chris@101
|
117 #undef BOOST_INTRUSIVE_64_BIT_SIZE_T
|
Chris@101
|
118
|
Chris@101
|
119 template<int Dummy>
|
Chris@101
|
120 const std::size_t prime_list_holder<Dummy>::prime_list_size
|
Chris@101
|
121 = sizeof(prime_list)/sizeof(std::size_t);
|
Chris@101
|
122
|
Chris@16
|
123 struct hash_bool_flags
|
Chris@16
|
124 {
|
Chris@16
|
125 static const std::size_t unique_keys_pos = 1u;
|
Chris@16
|
126 static const std::size_t constant_time_size_pos = 2u;
|
Chris@16
|
127 static const std::size_t power_2_buckets_pos = 4u;
|
Chris@16
|
128 static const std::size_t cache_begin_pos = 8u;
|
Chris@16
|
129 static const std::size_t compare_hash_pos = 16u;
|
Chris@16
|
130 static const std::size_t incremental_pos = 32u;
|
Chris@16
|
131 };
|
Chris@16
|
132
|
Chris@16
|
133 namespace detail {
|
Chris@16
|
134
|
Chris@16
|
135 template<class SupposedValueTraits>
|
Chris@16
|
136 struct get_slist_impl_from_supposed_value_traits
|
Chris@16
|
137 {
|
Chris@101
|
138 typedef SupposedValueTraits value_traits;
|
Chris@16
|
139 typedef typename detail::get_node_traits
|
Chris@101
|
140 <value_traits>::type node_traits;
|
Chris@16
|
141 typedef typename get_slist_impl
|
Chris@16
|
142 <typename reduced_slist_node_traits
|
Chris@16
|
143 <node_traits>::type
|
Chris@16
|
144 >::type type;
|
Chris@16
|
145 };
|
Chris@16
|
146
|
Chris@16
|
147 template<class SupposedValueTraits>
|
Chris@16
|
148 struct unordered_bucket_impl
|
Chris@16
|
149 {
|
Chris@16
|
150 typedef typename
|
Chris@16
|
151 get_slist_impl_from_supposed_value_traits
|
Chris@16
|
152 <SupposedValueTraits>::type slist_impl;
|
Chris@16
|
153 typedef detail::bucket_impl<slist_impl> implementation_defined;
|
Chris@16
|
154 typedef implementation_defined type;
|
Chris@16
|
155 };
|
Chris@16
|
156
|
Chris@16
|
157 template<class SupposedValueTraits>
|
Chris@16
|
158 struct unordered_bucket_ptr_impl
|
Chris@16
|
159 {
|
Chris@16
|
160 typedef typename detail::get_node_traits
|
Chris@16
|
161 <SupposedValueTraits>::type::node_ptr node_ptr;
|
Chris@16
|
162 typedef typename unordered_bucket_impl
|
Chris@16
|
163 <SupposedValueTraits>::type bucket_type;
|
Chris@16
|
164
|
Chris@16
|
165 typedef typename pointer_traits
|
Chris@16
|
166 <node_ptr>::template rebind_pointer
|
Chris@16
|
167 < bucket_type >::type implementation_defined;
|
Chris@16
|
168 typedef implementation_defined type;
|
Chris@16
|
169 };
|
Chris@16
|
170
|
Chris@16
|
171 template <class T>
|
Chris@16
|
172 struct store_hash_bool
|
Chris@16
|
173 {
|
Chris@16
|
174 template<bool Add>
|
Chris@16
|
175 struct two_or_three {one _[2 + Add];};
|
Chris@16
|
176 template <class U> static one test(...);
|
Chris@16
|
177 template <class U> static two_or_three<U::store_hash> test (int);
|
Chris@16
|
178 static const std::size_t value = sizeof(test<T>(0));
|
Chris@16
|
179 };
|
Chris@16
|
180
|
Chris@16
|
181 template <class T>
|
Chris@16
|
182 struct store_hash_is_true
|
Chris@16
|
183 {
|
Chris@16
|
184 static const bool value = store_hash_bool<T>::value > sizeof(one)*2;
|
Chris@16
|
185 };
|
Chris@16
|
186
|
Chris@16
|
187 template <class T>
|
Chris@16
|
188 struct optimize_multikey_bool
|
Chris@16
|
189 {
|
Chris@16
|
190 template<bool Add>
|
Chris@16
|
191 struct two_or_three {one _[2 + Add];};
|
Chris@16
|
192 template <class U> static one test(...);
|
Chris@16
|
193 template <class U> static two_or_three<U::optimize_multikey> test (int);
|
Chris@16
|
194 static const std::size_t value = sizeof(test<T>(0));
|
Chris@16
|
195 };
|
Chris@16
|
196
|
Chris@16
|
197 template <class T>
|
Chris@16
|
198 struct optimize_multikey_is_true
|
Chris@16
|
199 {
|
Chris@16
|
200 static const bool value = optimize_multikey_bool<T>::value > sizeof(one)*2;
|
Chris@16
|
201 };
|
Chris@16
|
202
|
Chris@16
|
203 struct insert_commit_data_impl
|
Chris@16
|
204 {
|
Chris@16
|
205 std::size_t hash;
|
Chris@16
|
206 };
|
Chris@16
|
207
|
Chris@16
|
208 template<class Node, class SlistNodePtr>
|
Chris@16
|
209 inline typename pointer_traits<SlistNodePtr>::template rebind_pointer<Node>::type
|
Chris@16
|
210 dcast_bucket_ptr(const SlistNodePtr &p)
|
Chris@16
|
211 {
|
Chris@16
|
212 typedef typename pointer_traits<SlistNodePtr>::template rebind_pointer<Node>::type node_ptr;
|
Chris@16
|
213 return pointer_traits<node_ptr>::pointer_to(static_cast<Node&>(*p));
|
Chris@16
|
214 }
|
Chris@16
|
215
|
Chris@16
|
216 template<class NodeTraits>
|
Chris@16
|
217 struct group_functions
|
Chris@16
|
218 {
|
Chris@16
|
219 typedef NodeTraits node_traits;
|
Chris@16
|
220 typedef unordered_group_adapter<node_traits> group_traits;
|
Chris@16
|
221 typedef typename node_traits::node_ptr node_ptr;
|
Chris@16
|
222 typedef typename node_traits::node node;
|
Chris@16
|
223 typedef typename reduced_slist_node_traits
|
Chris@16
|
224 <node_traits>::type reduced_node_traits;
|
Chris@16
|
225 typedef typename reduced_node_traits::node_ptr slist_node_ptr;
|
Chris@16
|
226 typedef typename reduced_node_traits::node slist_node;
|
Chris@16
|
227 typedef circular_slist_algorithms<group_traits> group_algorithms;
|
Chris@16
|
228
|
Chris@16
|
229 static slist_node_ptr get_bucket_before_begin
|
Chris@16
|
230 (const slist_node_ptr &bucket_beg, const slist_node_ptr &bucket_end, const node_ptr &p)
|
Chris@16
|
231 {
|
Chris@16
|
232 //First find the last node of p's group.
|
Chris@16
|
233 //This requires checking the first node of the next group or
|
Chris@16
|
234 //the bucket node.
|
Chris@16
|
235 node_ptr prev_node = p;
|
Chris@16
|
236 node_ptr nxt(node_traits::get_next(p));
|
Chris@16
|
237 while(!(bucket_beg <= nxt && nxt <= bucket_end) &&
|
Chris@16
|
238 (group_traits::get_next(nxt) == prev_node)){
|
Chris@16
|
239 prev_node = nxt;
|
Chris@16
|
240 nxt = node_traits::get_next(nxt);
|
Chris@16
|
241 }
|
Chris@16
|
242
|
Chris@16
|
243 //If we've reached the bucket node just return it.
|
Chris@16
|
244 if(bucket_beg <= nxt && nxt <= bucket_end){
|
Chris@16
|
245 return nxt;
|
Chris@16
|
246 }
|
Chris@16
|
247
|
Chris@16
|
248 //Otherwise, iterate using group links until the bucket node
|
Chris@16
|
249 node_ptr first_node_of_group = nxt;
|
Chris@16
|
250 node_ptr last_node_group = group_traits::get_next(first_node_of_group);
|
Chris@16
|
251 slist_node_ptr possible_end = node_traits::get_next(last_node_group);
|
Chris@16
|
252
|
Chris@16
|
253 while(!(bucket_beg <= possible_end && possible_end <= bucket_end)){
|
Chris@16
|
254 first_node_of_group = detail::dcast_bucket_ptr<node>(possible_end);
|
Chris@16
|
255 last_node_group = group_traits::get_next(first_node_of_group);
|
Chris@16
|
256 possible_end = node_traits::get_next(last_node_group);
|
Chris@16
|
257 }
|
Chris@16
|
258 return possible_end;
|
Chris@16
|
259 }
|
Chris@16
|
260
|
Chris@16
|
261 static node_ptr get_prev_to_first_in_group(const slist_node_ptr &bucket_node, const node_ptr &first_in_group)
|
Chris@16
|
262 {
|
Chris@16
|
263 //Just iterate using group links and obtain the node
|
Chris@16
|
264 //before "first_in_group)"
|
Chris@16
|
265 node_ptr prev_node = detail::dcast_bucket_ptr<node>(bucket_node);
|
Chris@16
|
266 node_ptr nxt(node_traits::get_next(prev_node));
|
Chris@16
|
267 while(nxt != first_in_group){
|
Chris@16
|
268 prev_node = group_traits::get_next(nxt);
|
Chris@16
|
269 nxt = node_traits::get_next(prev_node);
|
Chris@16
|
270 }
|
Chris@16
|
271 return prev_node;
|
Chris@16
|
272 }
|
Chris@16
|
273
|
Chris@16
|
274 static node_ptr get_first_in_group_of_last_in_group(const node_ptr &last_in_group)
|
Chris@16
|
275 {
|
Chris@16
|
276 //Just iterate using group links and obtain the node
|
Chris@16
|
277 //before "last_in_group"
|
Chris@16
|
278 node_ptr possible_first = group_traits::get_next(last_in_group);
|
Chris@16
|
279 node_ptr possible_first_prev = group_traits::get_next(possible_first);
|
Chris@16
|
280 // The deleted node is at the end of the group, so the
|
Chris@16
|
281 // node in the group pointing to it is at the beginning
|
Chris@16
|
282 // of the group. Find that to change its pointer.
|
Chris@16
|
283 while(possible_first_prev != last_in_group){
|
Chris@16
|
284 possible_first = possible_first_prev;
|
Chris@16
|
285 possible_first_prev = group_traits::get_next(possible_first);
|
Chris@16
|
286 }
|
Chris@16
|
287 return possible_first;
|
Chris@16
|
288 }
|
Chris@16
|
289
|
Chris@16
|
290 static void erase_from_group(const slist_node_ptr &end_ptr, const node_ptr &to_erase_ptr, detail::true_)
|
Chris@16
|
291 {
|
Chris@16
|
292 node_ptr nxt_ptr(node_traits::get_next(to_erase_ptr));
|
Chris@16
|
293 node_ptr prev_in_group_ptr(group_traits::get_next(to_erase_ptr));
|
Chris@16
|
294 bool last_in_group = (end_ptr == nxt_ptr) ||
|
Chris@16
|
295 (group_traits::get_next(nxt_ptr) != to_erase_ptr);
|
Chris@16
|
296 bool is_first_in_group = node_traits::get_next(prev_in_group_ptr) != to_erase_ptr;
|
Chris@16
|
297
|
Chris@16
|
298 if(is_first_in_group && last_in_group){
|
Chris@16
|
299 group_algorithms::init(to_erase_ptr);
|
Chris@16
|
300 }
|
Chris@16
|
301 else if(is_first_in_group){
|
Chris@16
|
302 group_algorithms::unlink_after(nxt_ptr);
|
Chris@16
|
303 }
|
Chris@16
|
304 else if(last_in_group){
|
Chris@16
|
305 node_ptr first_in_group =
|
Chris@16
|
306 get_first_in_group_of_last_in_group(to_erase_ptr);
|
Chris@16
|
307 group_algorithms::unlink_after(first_in_group);
|
Chris@16
|
308 }
|
Chris@16
|
309 else{
|
Chris@16
|
310 group_algorithms::unlink_after(nxt_ptr);
|
Chris@16
|
311 }
|
Chris@16
|
312 }
|
Chris@16
|
313
|
Chris@16
|
314 static void erase_from_group(const slist_node_ptr&, const node_ptr&, detail::false_)
|
Chris@16
|
315 {}
|
Chris@16
|
316
|
Chris@16
|
317 static node_ptr get_last_in_group(const node_ptr &first_in_group, detail::true_)
|
Chris@16
|
318 { return group_traits::get_next(first_in_group); }
|
Chris@16
|
319
|
Chris@16
|
320 static node_ptr get_last_in_group(const node_ptr &n, detail::false_)
|
Chris@16
|
321 { return n; }
|
Chris@16
|
322
|
Chris@16
|
323 static void init_group(const node_ptr &n, true_)
|
Chris@16
|
324 { group_algorithms::init(n); }
|
Chris@16
|
325
|
Chris@16
|
326 static void init_group(const node_ptr &, false_)
|
Chris@16
|
327 {}
|
Chris@16
|
328
|
Chris@16
|
329 static void insert_in_group(const node_ptr &first_in_group, const node_ptr &n, true_)
|
Chris@16
|
330 {
|
Chris@16
|
331 if(first_in_group){
|
Chris@16
|
332 if(group_algorithms::unique(first_in_group))
|
Chris@16
|
333 group_algorithms::link_after(first_in_group, n);
|
Chris@16
|
334 else{
|
Chris@101
|
335 group_algorithms::link_after(node_traits::get_next(first_in_group), n);
|
Chris@16
|
336 }
|
Chris@16
|
337 }
|
Chris@16
|
338 else{
|
Chris@16
|
339 group_algorithms::init_header(n);
|
Chris@16
|
340 }
|
Chris@16
|
341 }
|
Chris@16
|
342
|
Chris@16
|
343 static slist_node_ptr get_previous_and_next_in_group
|
Chris@16
|
344 ( const slist_node_ptr &i, node_ptr &nxt_in_group
|
Chris@16
|
345 //If first_end_ptr == last_end_ptr, then first_end_ptr is the bucket of i
|
Chris@16
|
346 //Otherwise first_end_ptr is the first bucket and last_end_ptr the last one.
|
Chris@16
|
347 , const slist_node_ptr &first_end_ptr, const slist_node_ptr &last_end_ptr)
|
Chris@16
|
348 {
|
Chris@16
|
349 slist_node_ptr prev;
|
Chris@16
|
350 node_ptr elem(detail::dcast_bucket_ptr<node>(i));
|
Chris@16
|
351
|
Chris@16
|
352 //It's the last in group if the next_node is a bucket
|
Chris@16
|
353 slist_node_ptr nxt(node_traits::get_next(elem));
|
Chris@101
|
354 bool last_in_group = (first_end_ptr <= nxt && nxt <= last_end_ptr) ||
|
Chris@101
|
355 (group_traits::get_next(detail::dcast_bucket_ptr<node>(nxt)) != elem);
|
Chris@16
|
356 //It's the first in group if group_previous's next_node is not
|
Chris@16
|
357 //itself, as group list does not link bucket
|
Chris@16
|
358 node_ptr prev_in_group(group_traits::get_next(elem));
|
Chris@16
|
359 bool first_in_group = node_traits::get_next(prev_in_group) != elem;
|
Chris@16
|
360
|
Chris@16
|
361 if(first_in_group){
|
Chris@16
|
362 node_ptr start_pos;
|
Chris@16
|
363 if(last_in_group){
|
Chris@16
|
364 start_pos = elem;
|
Chris@16
|
365 nxt_in_group = node_ptr();
|
Chris@16
|
366 }
|
Chris@16
|
367 else{
|
Chris@16
|
368 start_pos = prev_in_group;
|
Chris@16
|
369 nxt_in_group = node_traits::get_next(elem);
|
Chris@16
|
370 }
|
Chris@16
|
371 slist_node_ptr bucket_node;
|
Chris@16
|
372 if(first_end_ptr != last_end_ptr){
|
Chris@16
|
373 bucket_node = group_functions::get_bucket_before_begin
|
Chris@16
|
374 (first_end_ptr, last_end_ptr, start_pos);
|
Chris@16
|
375 }
|
Chris@16
|
376 else{
|
Chris@16
|
377 bucket_node = first_end_ptr;
|
Chris@16
|
378 }
|
Chris@16
|
379 prev = group_functions::get_prev_to_first_in_group(bucket_node, elem);
|
Chris@16
|
380 }
|
Chris@16
|
381 else{
|
Chris@16
|
382 if(last_in_group){
|
Chris@16
|
383 nxt_in_group = group_functions::get_first_in_group_of_last_in_group(elem);
|
Chris@16
|
384 }
|
Chris@16
|
385 else{
|
Chris@16
|
386 nxt_in_group = node_traits::get_next(elem);
|
Chris@16
|
387 }
|
Chris@16
|
388 prev = group_traits::get_next(elem);
|
Chris@16
|
389 }
|
Chris@16
|
390 return prev;
|
Chris@16
|
391 }
|
Chris@16
|
392
|
Chris@16
|
393 static void insert_in_group(const node_ptr&, const node_ptr&, false_)
|
Chris@16
|
394 {}
|
Chris@16
|
395 };
|
Chris@16
|
396
|
Chris@16
|
397 template<class BucketType, class SplitTraits>
|
Chris@16
|
398 class incremental_rehash_rollback
|
Chris@16
|
399 {
|
Chris@16
|
400 private:
|
Chris@16
|
401 typedef BucketType bucket_type;
|
Chris@16
|
402 typedef SplitTraits split_traits;
|
Chris@16
|
403
|
Chris@16
|
404 incremental_rehash_rollback();
|
Chris@16
|
405 incremental_rehash_rollback & operator=(const incremental_rehash_rollback &);
|
Chris@16
|
406 incremental_rehash_rollback (const incremental_rehash_rollback &);
|
Chris@16
|
407
|
Chris@16
|
408 public:
|
Chris@16
|
409 incremental_rehash_rollback
|
Chris@16
|
410 (bucket_type &source_bucket, bucket_type &destiny_bucket, split_traits &split_traits)
|
Chris@16
|
411 : source_bucket_(source_bucket), destiny_bucket_(destiny_bucket)
|
Chris@16
|
412 , split_traits_(split_traits), released_(false)
|
Chris@16
|
413 {}
|
Chris@16
|
414
|
Chris@16
|
415 void release()
|
Chris@16
|
416 { released_ = true; }
|
Chris@16
|
417
|
Chris@16
|
418 ~incremental_rehash_rollback()
|
Chris@16
|
419 {
|
Chris@16
|
420 if(!released_){
|
Chris@16
|
421 //If an exception is thrown, just put all moved nodes back in the old bucket
|
Chris@16
|
422 //and move back the split mark.
|
Chris@16
|
423 destiny_bucket_.splice_after(destiny_bucket_.before_begin(), source_bucket_);
|
Chris@16
|
424 split_traits_.decrement();
|
Chris@16
|
425 }
|
Chris@16
|
426 }
|
Chris@16
|
427
|
Chris@16
|
428 private:
|
Chris@16
|
429 bucket_type &source_bucket_;
|
Chris@16
|
430 bucket_type &destiny_bucket_;
|
Chris@16
|
431 split_traits &split_traits_;
|
Chris@16
|
432 bool released_;
|
Chris@16
|
433 };
|
Chris@16
|
434
|
Chris@16
|
435 template<class NodeTraits>
|
Chris@16
|
436 struct node_functions
|
Chris@16
|
437 {
|
Chris@16
|
438 static void store_hash(typename NodeTraits::node_ptr p, std::size_t h, true_)
|
Chris@16
|
439 { return NodeTraits::set_hash(p, h); }
|
Chris@16
|
440
|
Chris@16
|
441 static void store_hash(typename NodeTraits::node_ptr, std::size_t, false_)
|
Chris@16
|
442 {}
|
Chris@16
|
443 };
|
Chris@16
|
444
|
Chris@16
|
445 inline std::size_t hash_to_bucket(std::size_t hash_value, std::size_t bucket_cnt, detail::false_)
|
Chris@16
|
446 { return hash_value % bucket_cnt; }
|
Chris@16
|
447
|
Chris@16
|
448 inline std::size_t hash_to_bucket(std::size_t hash_value, std::size_t bucket_cnt, detail::true_)
|
Chris@16
|
449 { return hash_value & (bucket_cnt - 1); }
|
Chris@16
|
450
|
Chris@16
|
451 template<bool Power2Buckets, bool Incremental>
|
Chris@16
|
452 inline std::size_t hash_to_bucket_split(std::size_t hash_value, std::size_t bucket_cnt, std::size_t split)
|
Chris@16
|
453 {
|
Chris@16
|
454 std::size_t bucket_number = detail::hash_to_bucket(hash_value, bucket_cnt, detail::bool_<Power2Buckets>());
|
Chris@16
|
455 if(Incremental)
|
Chris@16
|
456 if(bucket_number >= split)
|
Chris@16
|
457 bucket_number -= bucket_cnt/2;
|
Chris@16
|
458 return bucket_number;
|
Chris@16
|
459 }
|
Chris@16
|
460
|
Chris@16
|
461 } //namespace detail {
|
Chris@16
|
462
|
Chris@16
|
463 //!This metafunction will obtain the type of a bucket
|
Chris@16
|
464 //!from the value_traits or hook option to be used with
|
Chris@16
|
465 //!a hash container.
|
Chris@16
|
466 template<class ValueTraitsOrHookOption>
|
Chris@16
|
467 struct unordered_bucket
|
Chris@16
|
468 : public detail::unordered_bucket_impl
|
Chris@16
|
469 <typename ValueTraitsOrHookOption::
|
Chris@101
|
470 template pack<empty>::proto_value_traits
|
Chris@16
|
471 >
|
Chris@16
|
472 {};
|
Chris@16
|
473
|
Chris@16
|
474 //!This metafunction will obtain the type of a bucket pointer
|
Chris@16
|
475 //!from the value_traits or hook option to be used with
|
Chris@16
|
476 //!a hash container.
|
Chris@16
|
477 template<class ValueTraitsOrHookOption>
|
Chris@16
|
478 struct unordered_bucket_ptr
|
Chris@101
|
479 : public detail::unordered_bucket_ptr_impl
|
Chris@101
|
480 <typename ValueTraitsOrHookOption::
|
Chris@101
|
481 template pack<empty>::proto_value_traits
|
Chris@101
|
482 >
|
Chris@16
|
483 {};
|
Chris@16
|
484
|
Chris@16
|
485 //!This metafunction will obtain the type of the default bucket traits
|
Chris@16
|
486 //!(when the user does not specify the bucket_traits<> option) from the
|
Chris@16
|
487 //!value_traits or hook option to be used with
|
Chris@16
|
488 //!a hash container.
|
Chris@16
|
489 template<class ValueTraitsOrHookOption>
|
Chris@16
|
490 struct unordered_default_bucket_traits
|
Chris@16
|
491 {
|
Chris@16
|
492 typedef typename ValueTraitsOrHookOption::
|
Chris@101
|
493 template pack<empty>::proto_value_traits supposed_value_traits;
|
Chris@16
|
494 typedef typename detail::
|
Chris@16
|
495 get_slist_impl_from_supposed_value_traits
|
Chris@16
|
496 <supposed_value_traits>::type slist_impl;
|
Chris@16
|
497 typedef detail::bucket_traits_impl
|
Chris@16
|
498 <slist_impl> implementation_defined;
|
Chris@16
|
499 typedef implementation_defined type;
|
Chris@16
|
500 };
|
Chris@16
|
501
|
Chris@16
|
502 struct default_bucket_traits;
|
Chris@16
|
503
|
Chris@101
|
504 //hashtable default hook traits
|
Chris@101
|
505 struct default_hashtable_hook_applier
|
Chris@101
|
506 { template <class T> struct apply{ typedef typename T::default_hashtable_hook type; }; };
|
Chris@101
|
507
|
Chris@101
|
508 template<>
|
Chris@101
|
509 struct is_default_hook_tag<default_hashtable_hook_applier>
|
Chris@101
|
510 { static const bool value = true; };
|
Chris@101
|
511
|
Chris@16
|
512 struct hashtable_defaults
|
Chris@16
|
513 {
|
Chris@101
|
514 typedef default_hashtable_hook_applier proto_value_traits;
|
Chris@16
|
515 typedef std::size_t size_type;
|
Chris@16
|
516 typedef void equal;
|
Chris@16
|
517 typedef void hash;
|
Chris@16
|
518 typedef default_bucket_traits bucket_traits;
|
Chris@16
|
519 static const bool constant_time_size = true;
|
Chris@16
|
520 static const bool power_2_buckets = false;
|
Chris@16
|
521 static const bool cache_begin = false;
|
Chris@16
|
522 static const bool compare_hash = false;
|
Chris@16
|
523 static const bool incremental = false;
|
Chris@16
|
524 };
|
Chris@16
|
525
|
Chris@101
|
526 template<class ValueTraits, bool IsConst>
|
Chris@16
|
527 struct downcast_node_to_value_t
|
Chris@101
|
528 : public detail::node_to_value<ValueTraits, IsConst>
|
Chris@16
|
529 {
|
Chris@101
|
530 typedef detail::node_to_value<ValueTraits, IsConst> base_t;
|
Chris@16
|
531 typedef typename base_t::result_type result_type;
|
Chris@101
|
532 typedef ValueTraits value_traits;
|
Chris@16
|
533 typedef typename detail::get_slist_impl
|
Chris@16
|
534 <typename detail::reduced_slist_node_traits
|
Chris@101
|
535 <typename value_traits::node_traits>::type
|
Chris@16
|
536 >::type slist_impl;
|
Chris@16
|
537 typedef typename detail::add_const_if_c
|
Chris@16
|
538 <typename slist_impl::node, IsConst>::type & first_argument_type;
|
Chris@16
|
539 typedef typename detail::add_const_if_c
|
Chris@101
|
540 < typename ValueTraits::node_traits::node
|
Chris@16
|
541 , IsConst>::type & intermediate_argument_type;
|
Chris@16
|
542 typedef typename pointer_traits
|
Chris@101
|
543 <typename ValueTraits::pointer>::
|
Chris@16
|
544 template rebind_pointer
|
Chris@101
|
545 <const ValueTraits>::type const_value_traits_ptr;
|
Chris@101
|
546
|
Chris@101
|
547 downcast_node_to_value_t(const const_value_traits_ptr &ptr)
|
Chris@16
|
548 : base_t(ptr)
|
Chris@16
|
549 {}
|
Chris@16
|
550
|
Chris@16
|
551 result_type operator()(first_argument_type arg) const
|
Chris@16
|
552 { return this->base_t::operator()(static_cast<intermediate_argument_type>(arg)); }
|
Chris@16
|
553 };
|
Chris@16
|
554
|
Chris@16
|
555 template<class F, class SlistNodePtr, class NodePtr>
|
Chris@16
|
556 struct node_cast_adaptor
|
Chris@101
|
557 //Use public inheritance to avoid MSVC bugs with closures
|
Chris@101
|
558 : public detail::ebo_functor_holder<F>
|
Chris@16
|
559 {
|
Chris@16
|
560 typedef detail::ebo_functor_holder<F> base_t;
|
Chris@16
|
561
|
Chris@16
|
562 typedef typename pointer_traits<SlistNodePtr>::element_type slist_node;
|
Chris@16
|
563 typedef typename pointer_traits<NodePtr>::element_type node;
|
Chris@16
|
564
|
Chris@16
|
565 template<class ConvertibleToF, class RealValuTraits>
|
Chris@16
|
566 node_cast_adaptor(const ConvertibleToF &c2f, const RealValuTraits *traits)
|
Chris@16
|
567 : base_t(base_t(c2f, traits))
|
Chris@16
|
568 {}
|
Chris@16
|
569
|
Chris@16
|
570 typename base_t::node_ptr operator()(const slist_node &to_clone)
|
Chris@16
|
571 { return base_t::operator()(static_cast<const node &>(to_clone)); }
|
Chris@16
|
572
|
Chris@16
|
573 void operator()(SlistNodePtr to_clone)
|
Chris@16
|
574 {
|
Chris@16
|
575 base_t::operator()(pointer_traits<NodePtr>::pointer_to(static_cast<node &>(*to_clone)));
|
Chris@16
|
576 }
|
Chris@16
|
577 };
|
Chris@16
|
578
|
Chris@16
|
579 static const std::size_t hashtable_data_bool_flags_mask =
|
Chris@16
|
580 ( hash_bool_flags::cache_begin_pos
|
Chris@16
|
581 | hash_bool_flags::constant_time_size_pos
|
Chris@16
|
582 | hash_bool_flags::incremental_pos
|
Chris@16
|
583 );
|
Chris@16
|
584
|
Chris@101
|
585 //bucket_plus_vtraits stores ValueTraits + BucketTraits
|
Chris@101
|
586 //this data is needed by iterators to obtain the
|
Chris@101
|
587 //value from the iterator and detect the bucket
|
Chris@16
|
588 template<class ValueTraits, class BucketTraits>
|
Chris@16
|
589 struct bucket_plus_vtraits : public ValueTraits
|
Chris@16
|
590 {
|
Chris@16
|
591 typedef BucketTraits bucket_traits;
|
Chris@16
|
592 typedef ValueTraits value_traits;
|
Chris@16
|
593
|
Chris@101
|
594 static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
|
Chris@101
|
595
|
Chris@16
|
596 typedef typename
|
Chris@16
|
597 detail::get_slist_impl_from_supposed_value_traits
|
Chris@101
|
598 <value_traits>::type slist_impl;
|
Chris@101
|
599 typedef typename value_traits::node_traits node_traits;
|
Chris@101
|
600 typedef unordered_group_adapter<node_traits> group_traits;
|
Chris@101
|
601 typedef typename slist_impl::iterator siterator;
|
Chris@101
|
602 typedef typename slist_impl::size_type size_type;
|
Chris@101
|
603 typedef detail::bucket_impl<slist_impl> bucket_type;
|
Chris@101
|
604 typedef detail::group_functions<node_traits> group_functions_t;
|
Chris@101
|
605 typedef typename slist_impl::node_algorithms node_algorithms;
|
Chris@101
|
606 typedef typename slist_impl::node_ptr slist_node_ptr;
|
Chris@101
|
607 typedef typename node_traits::node_ptr node_ptr;
|
Chris@101
|
608 typedef typename node_traits::node node;
|
Chris@101
|
609 typedef typename value_traits::value_type value_type;
|
Chris@101
|
610 typedef circular_slist_algorithms<group_traits> group_algorithms;
|
Chris@101
|
611 typedef typename pointer_traits
|
Chris@101
|
612 <typename value_traits::pointer>::
|
Chris@101
|
613 template rebind_pointer
|
Chris@101
|
614 <const value_traits>::type const_value_traits_ptr;
|
Chris@101
|
615 typedef typename pointer_traits
|
Chris@101
|
616 <typename value_traits::pointer>::
|
Chris@101
|
617 template rebind_pointer
|
Chris@101
|
618 <const bucket_plus_vtraits>::type const_bucket_value_traits_ptr;
|
Chris@101
|
619 typedef typename detail::unordered_bucket_ptr_impl
|
Chris@101
|
620 <value_traits>::type bucket_ptr;
|
Chris@101
|
621 typedef detail::bool_<detail::optimize_multikey_is_true
|
Chris@101
|
622 <node_traits>::value> optimize_multikey_t;
|
Chris@16
|
623
|
Chris@16
|
624 template<class BucketTraitsType>
|
Chris@16
|
625 bucket_plus_vtraits(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits)
|
Chris@16
|
626 : ValueTraits(val_traits), bucket_traits_(::boost::forward<BucketTraitsType>(b_traits))
|
Chris@16
|
627 {}
|
Chris@16
|
628
|
Chris@16
|
629 bucket_plus_vtraits & operator =(const bucket_plus_vtraits &x)
|
Chris@101
|
630 { bucket_traits_ = x.bucket_traits_; return *this; }
|
Chris@101
|
631
|
Chris@101
|
632 const_value_traits_ptr priv_value_traits_ptr() const
|
Chris@101
|
633 { return pointer_traits<const_value_traits_ptr>::pointer_to(this->priv_value_traits()); }
|
Chris@16
|
634
|
Chris@16
|
635 //bucket_value_traits
|
Chris@16
|
636 //
|
Chris@16
|
637 const bucket_plus_vtraits &get_bucket_value_traits() const
|
Chris@16
|
638 { return *this; }
|
Chris@16
|
639
|
Chris@16
|
640 bucket_plus_vtraits &get_bucket_value_traits()
|
Chris@16
|
641 { return *this; }
|
Chris@16
|
642
|
Chris@16
|
643 const_bucket_value_traits_ptr bucket_value_traits_ptr() const
|
Chris@16
|
644 { return pointer_traits<const_bucket_value_traits_ptr>::pointer_to(this->get_bucket_value_traits()); }
|
Chris@16
|
645
|
Chris@16
|
646 //value traits
|
Chris@16
|
647 //
|
Chris@16
|
648 const value_traits &priv_value_traits() const
|
Chris@16
|
649 { return *this; }
|
Chris@16
|
650
|
Chris@16
|
651 value_traits &priv_value_traits()
|
Chris@16
|
652 { return *this; }
|
Chris@16
|
653
|
Chris@16
|
654 //bucket_traits
|
Chris@16
|
655 //
|
Chris@16
|
656 const bucket_traits &priv_bucket_traits() const
|
Chris@16
|
657 { return this->bucket_traits_; }
|
Chris@16
|
658
|
Chris@16
|
659 bucket_traits &priv_bucket_traits()
|
Chris@16
|
660 { return this->bucket_traits_; }
|
Chris@16
|
661
|
Chris@101
|
662 //bucket operations
|
Chris@16
|
663 bucket_ptr priv_bucket_pointer() const
|
Chris@101
|
664 { return this->priv_bucket_traits().bucket_begin(); }
|
Chris@16
|
665
|
Chris@16
|
666 typename slist_impl::size_type priv_bucket_count() const
|
Chris@101
|
667 { return this->priv_bucket_traits().bucket_count(); }
|
Chris@16
|
668
|
Chris@16
|
669 bucket_ptr priv_invalid_bucket() const
|
Chris@16
|
670 {
|
Chris@101
|
671 const bucket_traits &rbt = this->priv_bucket_traits();
|
Chris@16
|
672 return rbt.bucket_begin() + rbt.bucket_count();
|
Chris@16
|
673 }
|
Chris@16
|
674 siterator priv_invalid_local_it() const
|
Chris@101
|
675 { return this->priv_bucket_traits().bucket_begin()->before_begin(); }
|
Chris@101
|
676
|
Chris@16
|
677 static siterator priv_get_last(bucket_type &b, detail::true_) //optimize multikey
|
Chris@16
|
678 {
|
Chris@16
|
679 //First find the last node of p's group.
|
Chris@16
|
680 //This requires checking the first node of the next group or
|
Chris@16
|
681 //the bucket node.
|
Chris@16
|
682 slist_node_ptr end_ptr(b.end().pointed_node());
|
Chris@16
|
683 node_ptr possible_end(node_traits::get_next( detail::dcast_bucket_ptr<node>(end_ptr)));
|
Chris@16
|
684 node_ptr last_node_group(possible_end);
|
Chris@16
|
685
|
Chris@16
|
686 while(end_ptr != possible_end){
|
Chris@16
|
687 last_node_group = group_traits::get_next(detail::dcast_bucket_ptr<node>(possible_end));
|
Chris@16
|
688 possible_end = node_traits::get_next(last_node_group);
|
Chris@16
|
689 }
|
Chris@16
|
690 return bucket_type::s_iterator_to(*last_node_group);
|
Chris@16
|
691 }
|
Chris@16
|
692
|
Chris@16
|
693 static siterator priv_get_last(bucket_type &b, detail::false_) //NOT optimize multikey
|
Chris@16
|
694 { return b.previous(b.end()); }
|
Chris@16
|
695
|
Chris@16
|
696 static siterator priv_get_previous(bucket_type &b, siterator i, detail::true_) //optimize multikey
|
Chris@16
|
697 {
|
Chris@16
|
698 node_ptr elem(detail::dcast_bucket_ptr<node>(i.pointed_node()));
|
Chris@16
|
699 node_ptr prev_in_group(group_traits::get_next(elem));
|
Chris@16
|
700 bool first_in_group = node_traits::get_next(prev_in_group) != elem;
|
Chris@16
|
701 typename bucket_type::node &n = first_in_group
|
Chris@16
|
702 ? *group_functions_t::get_prev_to_first_in_group(b.end().pointed_node(), elem)
|
Chris@16
|
703 : *group_traits::get_next(elem)
|
Chris@16
|
704 ;
|
Chris@16
|
705 return bucket_type::s_iterator_to(n);
|
Chris@16
|
706 }
|
Chris@16
|
707
|
Chris@16
|
708 static siterator priv_get_previous(bucket_type &b, siterator i, detail::false_) //NOT optimize multikey
|
Chris@16
|
709 { return b.previous(i); }
|
Chris@16
|
710
|
Chris@16
|
711 static void priv_clear_group_nodes(bucket_type &b, detail::true_) //optimize multikey
|
Chris@16
|
712 {
|
Chris@16
|
713 siterator it(b.begin()), itend(b.end());
|
Chris@16
|
714 while(it != itend){
|
Chris@16
|
715 node_ptr to_erase(detail::dcast_bucket_ptr<node>(it.pointed_node()));
|
Chris@16
|
716 ++it;
|
Chris@16
|
717 group_algorithms::init(to_erase);
|
Chris@16
|
718 }
|
Chris@16
|
719 }
|
Chris@16
|
720
|
Chris@16
|
721 static void priv_clear_group_nodes(bucket_type &, detail::false_) //NOT optimize multikey
|
Chris@16
|
722 {}
|
Chris@16
|
723
|
Chris@16
|
724 std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::true_) //optimize multikey
|
Chris@16
|
725 {
|
Chris@16
|
726 const bucket_ptr f(this->priv_bucket_pointer()), l(f + this->priv_bucket_count() - 1);
|
Chris@16
|
727 slist_node_ptr bb = group_functions_t::get_bucket_before_begin
|
Chris@16
|
728 ( f->end().pointed_node()
|
Chris@16
|
729 , l->end().pointed_node()
|
Chris@16
|
730 , detail::dcast_bucket_ptr<node>(it.pointed_node()));
|
Chris@16
|
731 //Now get the bucket_impl from the iterator
|
Chris@16
|
732 const bucket_type &b = static_cast<const bucket_type&>
|
Chris@16
|
733 (bucket_type::slist_type::container_from_end_iterator(bucket_type::s_iterator_to(*bb)));
|
Chris@16
|
734 //Now just calculate the index b has in the bucket array
|
Chris@16
|
735 return static_cast<size_type>(&b - &*f);
|
Chris@16
|
736 }
|
Chris@16
|
737
|
Chris@16
|
738 std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::false_) //NO optimize multikey
|
Chris@16
|
739 {
|
Chris@16
|
740 bucket_ptr f(this->priv_bucket_pointer()), l(f + this->priv_bucket_count() - 1);
|
Chris@16
|
741 slist_node_ptr first_ptr(f->cend().pointed_node())
|
Chris@16
|
742 , last_ptr(l->cend().pointed_node());
|
Chris@16
|
743
|
Chris@16
|
744 //The end node is embedded in the singly linked list:
|
Chris@16
|
745 //iterate until we reach it.
|
Chris@16
|
746 while(!(first_ptr <= it.pointed_node() && it.pointed_node() <= last_ptr)){
|
Chris@16
|
747 ++it;
|
Chris@16
|
748 }
|
Chris@16
|
749 //Now get the bucket_impl from the iterator
|
Chris@16
|
750 const bucket_type &b = static_cast<const bucket_type&>
|
Chris@16
|
751 (bucket_type::container_from_end_iterator(it));
|
Chris@16
|
752
|
Chris@16
|
753 //Now just calculate the index b has in the bucket array
|
Chris@16
|
754 return static_cast<std::size_t>(&b - &*f);
|
Chris@16
|
755 }
|
Chris@16
|
756
|
Chris@16
|
757 static std::size_t priv_stored_hash(slist_node_ptr n, detail::true_) //store_hash
|
Chris@16
|
758 { return node_traits::get_hash(detail::dcast_bucket_ptr<node>(n)); }
|
Chris@16
|
759
|
Chris@101
|
760 static std::size_t priv_stored_hash(slist_node_ptr, detail::false_) //NO store_hash (This should never be called)
|
Chris@101
|
761 { BOOST_INTRUSIVE_INVARIANT_ASSERT(0); return 0; }
|
Chris@101
|
762
|
Chris@101
|
763 node &priv_value_to_node(value_type &v)
|
Chris@101
|
764 { return *this->priv_value_traits().to_node_ptr(v); }
|
Chris@101
|
765
|
Chris@101
|
766 const node &priv_value_to_node(const value_type &v) const
|
Chris@101
|
767 { return *this->priv_value_traits().to_node_ptr(v); }
|
Chris@101
|
768
|
Chris@101
|
769 value_type &priv_value_from_slist_node(slist_node_ptr n)
|
Chris@101
|
770 { return *this->priv_value_traits().to_value_ptr(detail::dcast_bucket_ptr<node>(n)); }
|
Chris@101
|
771
|
Chris@101
|
772 const value_type &priv_value_from_slist_node(slist_node_ptr n) const
|
Chris@101
|
773 { return *this->priv_value_traits().to_value_ptr(detail::dcast_bucket_ptr<node>(n)); }
|
Chris@101
|
774
|
Chris@101
|
775 void priv_clear_buckets(const bucket_ptr buckets_ptr, const size_type bucket_cnt)
|
Chris@16
|
776 {
|
Chris@101
|
777 bucket_ptr buckets_it = buckets_ptr;
|
Chris@101
|
778 for(size_type bucket_i = 0; bucket_i != bucket_cnt; ++buckets_it, ++bucket_i){
|
Chris@101
|
779 if(safemode_or_autounlink){
|
Chris@101
|
780 bucket_plus_vtraits::priv_clear_group_nodes(*buckets_it, optimize_multikey_t());
|
Chris@101
|
781 buckets_it->clear_and_dispose(detail::init_disposer<node_algorithms>());
|
Chris@101
|
782 }
|
Chris@101
|
783 else{
|
Chris@101
|
784 buckets_it->clear();
|
Chris@101
|
785 }
|
Chris@101
|
786 }
|
Chris@16
|
787 }
|
Chris@16
|
788
|
Chris@16
|
789 bucket_traits bucket_traits_;
|
Chris@16
|
790 };
|
Chris@16
|
791
|
Chris@101
|
792 template<class Hash, class T>
|
Chris@101
|
793 struct get_hash
|
Chris@101
|
794 {
|
Chris@101
|
795 typedef Hash type;
|
Chris@101
|
796 };
|
Chris@101
|
797
|
Chris@101
|
798 template<class T>
|
Chris@101
|
799 struct get_hash<void, T>
|
Chris@101
|
800 {
|
Chris@101
|
801 typedef ::boost::hash<T> type;
|
Chris@101
|
802 };
|
Chris@101
|
803
|
Chris@101
|
804 //bucket_hash_t
|
Chris@101
|
805 //Stores bucket_plus_vtraits plust the hash function
|
Chris@16
|
806 template<class VoidOrKeyHash, class ValueTraits, class BucketTraits>
|
Chris@16
|
807 struct bucket_hash_t
|
Chris@101
|
808 //Use public inheritance to avoid MSVC bugs with closures
|
Chris@16
|
809 : public detail::ebo_functor_holder
|
Chris@16
|
810 <typename get_hash< VoidOrKeyHash
|
Chris@101
|
811 , typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits::value_type
|
Chris@16
|
812 >::type
|
Chris@16
|
813 >
|
Chris@16
|
814 {
|
Chris@101
|
815 typedef typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits value_traits;
|
Chris@101
|
816 typedef typename value_traits::value_type value_type;
|
Chris@101
|
817 typedef typename value_traits::node_traits node_traits;
|
Chris@101
|
818 typedef typename get_hash< VoidOrKeyHash, value_type>::type hasher;
|
Chris@16
|
819 typedef BucketTraits bucket_traits;
|
Chris@16
|
820 typedef bucket_plus_vtraits<ValueTraits, BucketTraits> bucket_plus_vtraits_t;
|
Chris@16
|
821
|
Chris@16
|
822 template<class BucketTraitsType>
|
Chris@16
|
823 bucket_hash_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h)
|
Chris@101
|
824 : detail::ebo_functor_holder<hasher>(h), internal(val_traits, ::boost::forward<BucketTraitsType>(b_traits))
|
Chris@16
|
825 {}
|
Chris@16
|
826
|
Chris@16
|
827 const hasher &priv_hasher() const
|
Chris@16
|
828 { return this->detail::ebo_functor_holder<hasher>::get(); }
|
Chris@16
|
829
|
Chris@16
|
830 hasher &priv_hasher()
|
Chris@16
|
831 { return this->detail::ebo_functor_holder<hasher>::get(); }
|
Chris@16
|
832
|
Chris@16
|
833 std::size_t priv_stored_or_compute_hash(const value_type &v, detail::true_) const //For store_hash == true
|
Chris@101
|
834 { return node_traits::get_hash(this->internal.priv_value_traits().to_node_ptr(v)); }
|
Chris@16
|
835
|
Chris@16
|
836 std::size_t priv_stored_or_compute_hash(const value_type &v, detail::false_) const //For store_hash == false
|
Chris@16
|
837 { return this->priv_hasher()(v); }
|
Chris@101
|
838
|
Chris@101
|
839 bucket_plus_vtraits_t internal; //4
|
Chris@16
|
840 };
|
Chris@16
|
841
|
Chris@101
|
842
|
Chris@101
|
843 template<class EqualTo, class T>
|
Chris@101
|
844 struct get_equal_to
|
Chris@101
|
845 {
|
Chris@101
|
846 typedef EqualTo type;
|
Chris@101
|
847 };
|
Chris@101
|
848
|
Chris@101
|
849 template<class T>
|
Chris@101
|
850 struct get_equal_to<void, T>
|
Chris@101
|
851 {
|
Chris@101
|
852 typedef ::std::equal_to<T> type;
|
Chris@101
|
853 };
|
Chris@101
|
854
|
Chris@101
|
855
|
Chris@101
|
856 //bucket_hash_equal_t
|
Chris@101
|
857 //Stores bucket_hash_t and the equality function when the first
|
Chris@101
|
858 //non-empty bucket shall not be cached.
|
Chris@16
|
859 template<class VoidOrKeyHash, class VoidOrKeyEqual, class ValueTraits, class BucketTraits, bool>
|
Chris@16
|
860 struct bucket_hash_equal_t
|
Chris@101
|
861 //Use public inheritance to avoid MSVC bugs with closures
|
Chris@16
|
862 : public detail::ebo_functor_holder //equal
|
Chris@16
|
863 <typename get_equal_to< VoidOrKeyEqual
|
Chris@101
|
864 , typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits::value_type
|
Chris@16
|
865 >::type
|
Chris@16
|
866 >
|
Chris@16
|
867 {
|
Chris@101
|
868 typedef bucket_hash_t<VoidOrKeyHash, ValueTraits, BucketTraits> bucket_hash_type;
|
Chris@101
|
869 typedef bucket_plus_vtraits<ValueTraits,BucketTraits> bucket_plus_vtraits_t;
|
Chris@101
|
870 typedef typename bucket_plus_vtraits_t::value_traits value_traits;
|
Chris@16
|
871 typedef typename get_equal_to< VoidOrKeyEqual
|
Chris@101
|
872 , typename value_traits::value_type
|
Chris@16
|
873 >::type value_equal;
|
Chris@16
|
874 typedef typename bucket_hash_type::hasher hasher;
|
Chris@16
|
875 typedef BucketTraits bucket_traits;
|
Chris@101
|
876 typedef typename bucket_plus_vtraits_t::slist_impl slist_impl;
|
Chris@101
|
877 typedef typename slist_impl::size_type size_type;
|
Chris@101
|
878 typedef typename slist_impl::iterator siterator;
|
Chris@101
|
879 typedef detail::bucket_impl<slist_impl> bucket_type;
|
Chris@101
|
880 typedef typename detail::unordered_bucket_ptr_impl<value_traits>::type bucket_ptr;
|
Chris@16
|
881
|
Chris@16
|
882 template<class BucketTraitsType>
|
Chris@16
|
883 bucket_hash_equal_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h, const value_equal &e)
|
Chris@16
|
884 : detail::ebo_functor_holder<value_equal>(e)
|
Chris@101
|
885 , internal(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h)
|
Chris@16
|
886 {}
|
Chris@16
|
887
|
Chris@16
|
888 bucket_ptr priv_get_cache()
|
Chris@101
|
889 { return this->internal.internal.priv_bucket_pointer(); }
|
Chris@16
|
890
|
Chris@16
|
891 void priv_set_cache(const bucket_ptr &)
|
Chris@16
|
892 {}
|
Chris@16
|
893
|
Chris@16
|
894 size_type priv_get_cache_bucket_num()
|
Chris@16
|
895 { return 0u; }
|
Chris@16
|
896
|
Chris@16
|
897 void priv_initialize_cache()
|
Chris@16
|
898 {}
|
Chris@16
|
899
|
Chris@16
|
900 void priv_swap_cache(bucket_hash_equal_t &)
|
Chris@16
|
901 {}
|
Chris@16
|
902
|
Chris@16
|
903 siterator priv_begin() const
|
Chris@16
|
904 {
|
Chris@16
|
905 size_type n = 0;
|
Chris@101
|
906 size_type bucket_cnt = this->internal.internal.priv_bucket_count();
|
Chris@16
|
907 for (n = 0; n < bucket_cnt; ++n){
|
Chris@101
|
908 bucket_type &b = this->internal.internal.priv_bucket_pointer()[n];
|
Chris@16
|
909 if(!b.empty()){
|
Chris@16
|
910 return b.begin();
|
Chris@16
|
911 }
|
Chris@16
|
912 }
|
Chris@101
|
913 return this->internal.internal.priv_invalid_local_it();
|
Chris@16
|
914 }
|
Chris@16
|
915
|
Chris@16
|
916 void priv_insertion_update_cache(size_type)
|
Chris@16
|
917 {}
|
Chris@16
|
918
|
Chris@16
|
919 void priv_erasure_update_cache_range(size_type, size_type)
|
Chris@16
|
920 {}
|
Chris@16
|
921
|
Chris@16
|
922 void priv_erasure_update_cache()
|
Chris@16
|
923 {}
|
Chris@16
|
924
|
Chris@16
|
925 const value_equal &priv_equal() const
|
Chris@16
|
926 { return this->detail::ebo_functor_holder<value_equal>::get(); }
|
Chris@16
|
927
|
Chris@16
|
928 value_equal &priv_equal()
|
Chris@16
|
929 { return this->detail::ebo_functor_holder<value_equal>::get(); }
|
Chris@101
|
930
|
Chris@101
|
931 bucket_hash_t<VoidOrKeyHash, ValueTraits, BucketTraits> internal; //3
|
Chris@16
|
932 };
|
Chris@16
|
933
|
Chris@101
|
934 //bucket_hash_equal_t
|
Chris@101
|
935 //Stores bucket_hash_t and the equality function when the first
|
Chris@101
|
936 //non-empty bucket shall be cached.
|
Chris@16
|
937 template<class VoidOrKeyHash, class VoidOrKeyEqual, class ValueTraits, class BucketTraits> //cache_begin == true version
|
Chris@16
|
938 struct bucket_hash_equal_t<VoidOrKeyHash, VoidOrKeyEqual, ValueTraits, BucketTraits, true>
|
Chris@101
|
939 //Use public inheritance to avoid MSVC bugs with closures
|
Chris@16
|
940 : public detail::ebo_functor_holder //equal
|
Chris@101
|
941 <typename get_equal_to< VoidOrKeyEqual
|
Chris@101
|
942 , typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits::value_type
|
Chris@16
|
943 >::type
|
Chris@101
|
944 >
|
Chris@16
|
945 {
|
Chris@101
|
946 typedef bucket_plus_vtraits<ValueTraits, BucketTraits> bucket_plus_vtraits_t;
|
Chris@101
|
947 typedef bucket_hash_t<VoidOrKeyHash, ValueTraits, BucketTraits> bucket_hash_type;
|
Chris@101
|
948 typedef typename bucket_plus_vtraits
|
Chris@101
|
949 <ValueTraits,BucketTraits>::value_traits value_traits;
|
Chris@101
|
950 typedef typename get_equal_to
|
Chris@101
|
951 < VoidOrKeyEqual
|
Chris@101
|
952 , typename value_traits::value_type>::type value_equal;
|
Chris@101
|
953 typedef typename bucket_hash_type::hasher hasher;
|
Chris@101
|
954 typedef BucketTraits bucket_traits;
|
Chris@101
|
955 typedef typename bucket_plus_vtraits_t::slist_impl::size_type size_type;
|
Chris@101
|
956 typedef typename bucket_plus_vtraits_t::slist_impl::iterator siterator;
|
Chris@16
|
957
|
Chris@16
|
958 template<class BucketTraitsType>
|
Chris@16
|
959 bucket_hash_equal_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h, const value_equal &e)
|
Chris@16
|
960 : detail::ebo_functor_holder<value_equal>(e)
|
Chris@101
|
961 , internal(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h)
|
Chris@16
|
962 {}
|
Chris@16
|
963
|
Chris@16
|
964 typedef typename detail::unordered_bucket_ptr_impl
|
Chris@101
|
965 <typename bucket_hash_type::value_traits>::type bucket_ptr;
|
Chris@16
|
966
|
Chris@16
|
967 bucket_ptr &priv_get_cache()
|
Chris@16
|
968 { return cached_begin_; }
|
Chris@16
|
969
|
Chris@16
|
970 const bucket_ptr &priv_get_cache() const
|
Chris@16
|
971 { return cached_begin_; }
|
Chris@16
|
972
|
Chris@16
|
973 void priv_set_cache(const bucket_ptr &p)
|
Chris@16
|
974 { cached_begin_ = p; }
|
Chris@16
|
975
|
Chris@16
|
976 std::size_t priv_get_cache_bucket_num()
|
Chris@101
|
977 { return this->cached_begin_ - this->internal.internal.priv_bucket_pointer(); }
|
Chris@16
|
978
|
Chris@16
|
979 void priv_initialize_cache()
|
Chris@101
|
980 { this->cached_begin_ = this->internal.internal.priv_invalid_bucket(); }
|
Chris@16
|
981
|
Chris@16
|
982 void priv_swap_cache(bucket_hash_equal_t &other)
|
Chris@16
|
983 {
|
Chris@101
|
984 ::boost::adl_move_swap(this->cached_begin_, other.cached_begin_);
|
Chris@16
|
985 }
|
Chris@16
|
986
|
Chris@16
|
987 siterator priv_begin() const
|
Chris@16
|
988 {
|
Chris@101
|
989 if(this->cached_begin_ == this->internal.internal.priv_invalid_bucket()){
|
Chris@101
|
990 return this->internal.internal.priv_invalid_local_it();
|
Chris@16
|
991 }
|
Chris@16
|
992 else{
|
Chris@16
|
993 return this->cached_begin_->begin();
|
Chris@16
|
994 }
|
Chris@16
|
995 }
|
Chris@16
|
996
|
Chris@16
|
997 void priv_insertion_update_cache(size_type insertion_bucket)
|
Chris@16
|
998 {
|
Chris@101
|
999 bucket_ptr p = this->internal.internal.priv_bucket_pointer() + insertion_bucket;
|
Chris@16
|
1000 if(p < this->cached_begin_){
|
Chris@16
|
1001 this->cached_begin_ = p;
|
Chris@16
|
1002 }
|
Chris@16
|
1003 }
|
Chris@16
|
1004
|
Chris@16
|
1005 const value_equal &priv_equal() const
|
Chris@16
|
1006 { return this->detail::ebo_functor_holder<value_equal>::get(); }
|
Chris@16
|
1007
|
Chris@16
|
1008 value_equal &priv_equal()
|
Chris@16
|
1009 { return this->detail::ebo_functor_holder<value_equal>::get(); }
|
Chris@16
|
1010
|
Chris@16
|
1011 void priv_erasure_update_cache_range(size_type first_bucket_num, size_type last_bucket_num)
|
Chris@16
|
1012 {
|
Chris@16
|
1013 //If the last bucket is the end, the cache must be updated
|
Chris@16
|
1014 //to the last position if all
|
Chris@16
|
1015 if(this->priv_get_cache_bucket_num() == first_bucket_num &&
|
Chris@101
|
1016 this->internal.internal.priv_bucket_pointer()[first_bucket_num].empty() ){
|
Chris@101
|
1017 this->priv_set_cache(this->internal.internal.priv_bucket_pointer() + last_bucket_num);
|
Chris@16
|
1018 this->priv_erasure_update_cache();
|
Chris@16
|
1019 }
|
Chris@16
|
1020 }
|
Chris@16
|
1021
|
Chris@16
|
1022 void priv_erasure_update_cache()
|
Chris@16
|
1023 {
|
Chris@101
|
1024 if(this->cached_begin_ != this->internal.internal.priv_invalid_bucket()){
|
Chris@101
|
1025 size_type current_n = this->priv_get_cache() - this->internal.internal.priv_bucket_pointer();
|
Chris@101
|
1026 for( const size_type num_buckets = this->internal.internal.priv_bucket_count()
|
Chris@16
|
1027 ; current_n < num_buckets
|
Chris@16
|
1028 ; ++current_n, ++this->priv_get_cache()){
|
Chris@16
|
1029 if(!this->priv_get_cache()->empty()){
|
Chris@16
|
1030 return;
|
Chris@16
|
1031 }
|
Chris@16
|
1032 }
|
Chris@16
|
1033 this->priv_initialize_cache();
|
Chris@16
|
1034 }
|
Chris@16
|
1035 }
|
Chris@16
|
1036
|
Chris@16
|
1037 bucket_ptr cached_begin_;
|
Chris@101
|
1038 bucket_hash_t<VoidOrKeyHash, ValueTraits, BucketTraits> internal; //2
|
Chris@16
|
1039 };
|
Chris@16
|
1040
|
Chris@101
|
1041 //hashdata_internal
|
Chris@101
|
1042 //Stores bucket_hash_equal_t and split_traits
|
Chris@16
|
1043 template<class SizeType, std::size_t BoolFlags, class VoidOrKeyHash, class VoidOrKeyEqual, class ValueTraits, class BucketTraits>
|
Chris@16
|
1044 struct hashdata_internal
|
Chris@16
|
1045 : public detail::size_holder< 0 != (BoolFlags & hash_bool_flags::incremental_pos), SizeType, int> //split_traits
|
Chris@16
|
1046 {
|
Chris@16
|
1047 typedef bucket_hash_equal_t
|
Chris@101
|
1048 < VoidOrKeyHash, VoidOrKeyEqual
|
Chris@101
|
1049 , ValueTraits, BucketTraits
|
Chris@16
|
1050 , 0 != (BoolFlags & hash_bool_flags::cache_begin_pos)
|
Chris@101
|
1051 > internal_type;
|
Chris@101
|
1052 typedef typename internal_type::value_equal value_equal;
|
Chris@101
|
1053 typedef typename internal_type::hasher hasher;
|
Chris@101
|
1054 typedef bucket_plus_vtraits<ValueTraits,BucketTraits> bucket_plus_vtraits_t;
|
Chris@101
|
1055 typedef typename bucket_plus_vtraits_t::size_type size_type;
|
Chris@101
|
1056 typedef typename bucket_plus_vtraits_t::bucket_ptr bucket_ptr;
|
Chris@101
|
1057 typedef detail::size_holder
|
Chris@101
|
1058 <0 != (BoolFlags & hash_bool_flags::incremental_pos)
|
Chris@101
|
1059 , SizeType, int> split_traits;
|
Chris@101
|
1060 typedef typename bucket_plus_vtraits_t::
|
Chris@101
|
1061 value_traits::node_traits node_traits;
|
Chris@101
|
1062 typedef detail::bool_<detail::optimize_multikey_is_true
|
Chris@101
|
1063 <node_traits>::value> optimize_multikey_t;
|
Chris@16
|
1064
|
Chris@16
|
1065 template<class BucketTraitsType>
|
Chris@101
|
1066 hashdata_internal( const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits
|
Chris@101
|
1067 , const hasher & h, const value_equal &e)
|
Chris@101
|
1068 : internal(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h, e)
|
Chris@16
|
1069 {}
|
Chris@16
|
1070
|
Chris@16
|
1071 split_traits &priv_split_traits()
|
Chris@16
|
1072 { return *this; }
|
Chris@16
|
1073
|
Chris@16
|
1074 const split_traits &priv_split_traits() const
|
Chris@16
|
1075 { return *this; }
|
Chris@101
|
1076
|
Chris@101
|
1077 ~hashdata_internal()
|
Chris@101
|
1078 { this->priv_clear_buckets(); }
|
Chris@101
|
1079
|
Chris@101
|
1080 void priv_clear_buckets()
|
Chris@101
|
1081 {
|
Chris@101
|
1082 this->internal.internal.internal.priv_clear_buckets
|
Chris@101
|
1083 ( this->internal.priv_get_cache()
|
Chris@101
|
1084 , this->internal.internal.internal.priv_bucket_count()
|
Chris@101
|
1085 - (this->internal.priv_get_cache()
|
Chris@101
|
1086 - this->internal.internal.internal.priv_bucket_pointer()));
|
Chris@101
|
1087 }
|
Chris@101
|
1088
|
Chris@101
|
1089 void priv_clear_buckets_and_cache()
|
Chris@101
|
1090 {
|
Chris@101
|
1091 this->priv_clear_buckets();
|
Chris@101
|
1092 this->internal.priv_initialize_cache();
|
Chris@101
|
1093 }
|
Chris@101
|
1094
|
Chris@101
|
1095 void priv_initialize_buckets_and_cache()
|
Chris@101
|
1096 {
|
Chris@101
|
1097 this->internal.internal.internal.priv_clear_buckets
|
Chris@101
|
1098 ( this->internal.internal.internal.priv_bucket_pointer()
|
Chris@101
|
1099 , this->internal.internal.internal.priv_bucket_count());
|
Chris@101
|
1100 this->internal.priv_initialize_cache();
|
Chris@101
|
1101 }
|
Chris@101
|
1102
|
Chris@101
|
1103 internal_type internal; //2
|
Chris@16
|
1104 };
|
Chris@16
|
1105
|
Chris@101
|
1106 //hashtable_data_t
|
Chris@101
|
1107 //Stores hashdata_internal and size_traits
|
Chris@16
|
1108 template<class SizeType, std::size_t BoolFlags, class VoidOrKeyHash, class VoidOrKeyEqual, class ValueTraits, class BucketTraits>
|
Chris@16
|
1109 struct hashtable_data_t
|
Chris@101
|
1110 : public detail::size_holder
|
Chris@101
|
1111 < 0 != (BoolFlags & hash_bool_flags::constant_time_size_pos), SizeType> //size_traits
|
Chris@16
|
1112 {
|
Chris@16
|
1113 typedef detail::size_holder
|
Chris@16
|
1114 < 0 != (BoolFlags & hash_bool_flags::constant_time_size_pos)
|
Chris@101
|
1115 , SizeType> size_traits;
|
Chris@16
|
1116 typedef hashdata_internal
|
Chris@101
|
1117 < SizeType
|
Chris@101
|
1118 , BoolFlags & (hash_bool_flags::incremental_pos | hash_bool_flags::cache_begin_pos)
|
Chris@101
|
1119 , VoidOrKeyHash, VoidOrKeyEqual
|
Chris@101
|
1120 , ValueTraits, BucketTraits> internal_type;
|
Chris@101
|
1121 typedef ValueTraits value_traits;
|
Chris@101
|
1122 typedef typename internal_type::value_equal value_equal;
|
Chris@101
|
1123 typedef typename internal_type::hasher hasher;
|
Chris@101
|
1124 typedef BucketTraits bucket_traits;
|
Chris@16
|
1125 typedef bucket_plus_vtraits
|
Chris@101
|
1126 <ValueTraits,BucketTraits> bucket_plus_vtraits_t;
|
Chris@16
|
1127
|
Chris@16
|
1128 template<class BucketTraitsType>
|
Chris@16
|
1129 hashtable_data_t( BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h
|
Chris@16
|
1130 , const value_equal &e, const value_traits &val_traits)
|
Chris@101
|
1131 : internal(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h, e)
|
Chris@16
|
1132 {}
|
Chris@101
|
1133
|
Chris@101
|
1134 internal_type internal; //1
|
Chris@16
|
1135 };
|
Chris@16
|
1136
|
Chris@16
|
1137 /// @endcond
|
Chris@16
|
1138
|
Chris@16
|
1139 //! The class template hashtable is an intrusive hash table container, that
|
Chris@16
|
1140 //! is used to construct intrusive unordered_set and unordered_multiset containers. The
|
Chris@16
|
1141 //! no-throw guarantee holds only, if the VoidOrKeyEqual object and Hasher don't throw.
|
Chris@16
|
1142 //!
|
Chris@16
|
1143 //! hashtable is a semi-intrusive container: each object to be stored in the
|
Chris@16
|
1144 //! container must contain a proper hook, but the container also needs
|
Chris@16
|
1145 //! additional auxiliary memory to work: hashtable needs a pointer to an array
|
Chris@16
|
1146 //! of type `bucket_type` to be passed in the constructor. This bucket array must
|
Chris@16
|
1147 //! have at least the same lifetime as the container. This makes the use of
|
Chris@16
|
1148 //! hashtable more complicated than purely intrusive containers.
|
Chris@16
|
1149 //! `bucket_type` is default-constructible, copyable and assignable
|
Chris@16
|
1150 //!
|
Chris@16
|
1151 //! The template parameter \c T is the type to be managed by the container.
|
Chris@16
|
1152 //! The user can specify additional options and if no options are provided
|
Chris@16
|
1153 //! default options are used.
|
Chris@16
|
1154 //!
|
Chris@16
|
1155 //! The container supports the following options:
|
Chris@16
|
1156 //! \c base_hook<>/member_hook<>/value_traits<>,
|
Chris@16
|
1157 //! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<>
|
Chris@16
|
1158 //! \c bucket_traits<>, power_2_buckets<>, cache_begin<> and incremental<>.
|
Chris@16
|
1159 //!
|
Chris@16
|
1160 //! hashtable only provides forward iterators but it provides 4 iterator types:
|
Chris@16
|
1161 //! iterator and const_iterator to navigate through the whole container and
|
Chris@16
|
1162 //! local_iterator and const_local_iterator to navigate through the values
|
Chris@16
|
1163 //! stored in a single bucket. Local iterators are faster and smaller.
|
Chris@16
|
1164 //!
|
Chris@16
|
1165 //! It's not recommended to use non constant-time size hashtables because several
|
Chris@16
|
1166 //! key functions, like "empty()", become non-constant time functions. Non
|
Chris@16
|
1167 //! constant_time size hashtables are mainly provided to support auto-unlink hooks.
|
Chris@16
|
1168 //!
|
Chris@16
|
1169 //! hashtables, does not make automatic rehashings nor
|
Chris@16
|
1170 //! offers functions related to a load factor. Rehashing can be explicitly requested
|
Chris@16
|
1171 //! and the user must provide a new bucket array that will be used from that moment.
|
Chris@16
|
1172 //!
|
Chris@16
|
1173 //! Since no automatic rehashing is done, iterators are never invalidated when
|
Chris@16
|
1174 //! inserting or erasing elements. Iterators are only invalidated when rehashing.
|
Chris@16
|
1175 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1176 template<class T, class ...Options>
|
Chris@16
|
1177 #else
|
Chris@16
|
1178 template<class ValueTraits, class VoidOrKeyHash, class VoidOrKeyEqual, class SizeType, class BucketTraits, std::size_t BoolFlags>
|
Chris@16
|
1179 #endif
|
Chris@16
|
1180 class hashtable_impl
|
Chris@101
|
1181 : private hashtable_data_t
|
Chris@16
|
1182 < SizeType
|
Chris@16
|
1183 , BoolFlags & hashtable_data_bool_flags_mask
|
Chris@16
|
1184 , VoidOrKeyHash, VoidOrKeyEqual, ValueTraits, BucketTraits>
|
Chris@16
|
1185 {
|
Chris@16
|
1186 typedef hashtable_data_t
|
Chris@16
|
1187 < SizeType
|
Chris@16
|
1188 , BoolFlags & hashtable_data_bool_flags_mask
|
Chris@101
|
1189 , VoidOrKeyHash, VoidOrKeyEqual, ValueTraits, BucketTraits> data_type;
|
Chris@101
|
1190
|
Chris@101
|
1191 public:
|
Chris@101
|
1192 typedef ValueTraits value_traits;
|
Chris@16
|
1193
|
Chris@16
|
1194 /// @cond
|
Chris@16
|
1195 typedef BucketTraits bucket_traits;
|
Chris@16
|
1196
|
Chris@16
|
1197 typedef typename detail::get_slist_impl
|
Chris@16
|
1198 <typename detail::reduced_slist_node_traits
|
Chris@101
|
1199 <typename value_traits::node_traits>::type
|
Chris@101
|
1200 >::type slist_impl;
|
Chris@101
|
1201 typedef bucket_plus_vtraits<ValueTraits, BucketTraits> bucket_plus_vtraits_t;
|
Chris@101
|
1202 typedef typename bucket_plus_vtraits_t::const_value_traits_ptr const_value_traits_ptr;
|
Chris@16
|
1203
|
Chris@16
|
1204
|
Chris@16
|
1205 /// @endcond
|
Chris@16
|
1206
|
Chris@101
|
1207 typedef typename value_traits::pointer pointer;
|
Chris@101
|
1208 typedef typename value_traits::const_pointer const_pointer;
|
Chris@101
|
1209 typedef typename value_traits::value_type value_type;
|
Chris@16
|
1210 typedef typename pointer_traits<pointer>::reference reference;
|
Chris@16
|
1211 typedef typename pointer_traits<const_pointer>::reference const_reference;
|
Chris@16
|
1212 typedef typename pointer_traits<pointer>::difference_type difference_type;
|
Chris@16
|
1213 typedef SizeType size_type;
|
Chris@16
|
1214 typedef value_type key_type;
|
Chris@16
|
1215 typedef typename data_type::value_equal key_equal;
|
Chris@101
|
1216 typedef typename data_type::value_equal value_equal;
|
Chris@16
|
1217 typedef typename data_type::hasher hasher;
|
Chris@16
|
1218 typedef detail::bucket_impl<slist_impl> bucket_type;
|
Chris@16
|
1219 typedef typename pointer_traits
|
Chris@16
|
1220 <pointer>::template rebind_pointer
|
Chris@16
|
1221 < bucket_type >::type bucket_ptr;
|
Chris@101
|
1222 typedef typename pointer_traits
|
Chris@101
|
1223 <pointer>::template rebind_pointer
|
Chris@101
|
1224 < const bucket_type >::type const_bucket_ptr;
|
Chris@101
|
1225 typedef typename pointer_traits
|
Chris@101
|
1226 <bucket_ptr>::reference bucket_reference;
|
Chris@101
|
1227 typedef typename pointer_traits
|
Chris@101
|
1228 <bucket_ptr>::reference const_bucket_reference;
|
Chris@16
|
1229 typedef typename slist_impl::iterator siterator;
|
Chris@16
|
1230 typedef typename slist_impl::const_iterator const_siterator;
|
Chris@16
|
1231 typedef hashtable_iterator<bucket_plus_vtraits_t, false> iterator;
|
Chris@16
|
1232 typedef hashtable_iterator<bucket_plus_vtraits_t, true> const_iterator;
|
Chris@101
|
1233 typedef typename value_traits::node_traits node_traits;
|
Chris@16
|
1234 typedef typename node_traits::node node;
|
Chris@16
|
1235 typedef typename pointer_traits
|
Chris@16
|
1236 <pointer>::template rebind_pointer
|
Chris@16
|
1237 < node >::type node_ptr;
|
Chris@16
|
1238 typedef typename pointer_traits
|
Chris@16
|
1239 <pointer>::template rebind_pointer
|
Chris@16
|
1240 < const node >::type const_node_ptr;
|
Chris@101
|
1241 typedef typename pointer_traits
|
Chris@101
|
1242 <node_ptr>::reference node_reference;
|
Chris@101
|
1243 typedef typename pointer_traits
|
Chris@101
|
1244 <const_node_ptr>::reference const_node_reference;
|
Chris@16
|
1245 typedef typename slist_impl::node_algorithms node_algorithms;
|
Chris@16
|
1246
|
Chris@101
|
1247 static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value;
|
Chris@16
|
1248 static const bool store_hash = detail::store_hash_is_true<node_traits>::value;
|
Chris@16
|
1249
|
Chris@16
|
1250 static const bool unique_keys = 0 != (BoolFlags & hash_bool_flags::unique_keys_pos);
|
Chris@16
|
1251 static const bool constant_time_size = 0 != (BoolFlags & hash_bool_flags::constant_time_size_pos);
|
Chris@16
|
1252 static const bool cache_begin = 0 != (BoolFlags & hash_bool_flags::cache_begin_pos);
|
Chris@16
|
1253 static const bool compare_hash = 0 != (BoolFlags & hash_bool_flags::compare_hash_pos);
|
Chris@16
|
1254 static const bool incremental = 0 != (BoolFlags & hash_bool_flags::incremental_pos);
|
Chris@16
|
1255 static const bool power_2_buckets = incremental || (0 != (BoolFlags & hash_bool_flags::power_2_buckets_pos));
|
Chris@16
|
1256
|
Chris@16
|
1257 static const bool optimize_multikey
|
Chris@16
|
1258 = detail::optimize_multikey_is_true<node_traits>::value && !unique_keys;
|
Chris@16
|
1259
|
Chris@16
|
1260 /// @cond
|
Chris@16
|
1261 private:
|
Chris@16
|
1262
|
Chris@16
|
1263 //Configuration error: compare_hash<> can't be specified without store_hash<>
|
Chris@16
|
1264 //See documentation for more explanations
|
Chris@16
|
1265 BOOST_STATIC_ASSERT((!compare_hash || store_hash));
|
Chris@16
|
1266
|
Chris@16
|
1267 typedef typename slist_impl::node_ptr slist_node_ptr;
|
Chris@16
|
1268 typedef typename pointer_traits
|
Chris@16
|
1269 <slist_node_ptr>::template rebind_pointer
|
Chris@16
|
1270 < void >::type void_pointer;
|
Chris@16
|
1271 //We'll define group traits, but these won't be instantiated if
|
Chris@16
|
1272 //optimize_multikey is not true
|
Chris@16
|
1273 typedef unordered_group_adapter<node_traits> group_traits;
|
Chris@16
|
1274 typedef circular_slist_algorithms<group_traits> group_algorithms;
|
Chris@16
|
1275 typedef detail::bool_<store_hash> store_hash_t;
|
Chris@16
|
1276 typedef detail::bool_<optimize_multikey> optimize_multikey_t;
|
Chris@16
|
1277 typedef detail::bool_<cache_begin> cache_begin_t;
|
Chris@16
|
1278 typedef detail::bool_<power_2_buckets> power_2_buckets_t;
|
Chris@16
|
1279 typedef detail::size_holder<constant_time_size, size_type> size_traits;
|
Chris@16
|
1280 typedef detail::size_holder<incremental, size_type, int> split_traits;
|
Chris@16
|
1281 typedef detail::group_functions<node_traits> group_functions_t;
|
Chris@16
|
1282 typedef detail::node_functions<node_traits> node_functions_t;
|
Chris@16
|
1283
|
Chris@16
|
1284 private:
|
Chris@16
|
1285 //noncopyable, movable
|
Chris@16
|
1286 BOOST_MOVABLE_BUT_NOT_COPYABLE(hashtable_impl)
|
Chris@16
|
1287
|
Chris@101
|
1288 static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
|
Chris@16
|
1289
|
Chris@16
|
1290 //Constant-time size is incompatible with auto-unlink hooks!
|
Chris@101
|
1291 BOOST_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink)));
|
Chris@16
|
1292 //Cache begin is incompatible with auto-unlink hooks!
|
Chris@101
|
1293 BOOST_STATIC_ASSERT(!(cache_begin && ((int)value_traits::link_mode == (int)auto_unlink)));
|
Chris@16
|
1294
|
Chris@16
|
1295 template<class Disposer>
|
Chris@101
|
1296 node_cast_adaptor< detail::node_disposer<Disposer, value_traits, CircularSListAlgorithms>
|
Chris@16
|
1297 , slist_node_ptr, node_ptr >
|
Chris@16
|
1298 make_node_disposer(const Disposer &disposer) const
|
Chris@16
|
1299 {
|
Chris@16
|
1300 return node_cast_adaptor
|
Chris@101
|
1301 < detail::node_disposer<Disposer, value_traits, CircularSListAlgorithms>
|
Chris@16
|
1302 , slist_node_ptr, node_ptr >
|
Chris@101
|
1303 (disposer, &this->priv_value_traits());
|
Chris@16
|
1304 }
|
Chris@16
|
1305
|
Chris@16
|
1306 /// @endcond
|
Chris@16
|
1307
|
Chris@16
|
1308 public:
|
Chris@16
|
1309 typedef detail::insert_commit_data_impl insert_commit_data;
|
Chris@16
|
1310
|
Chris@16
|
1311 typedef detail::transform_iterator
|
Chris@16
|
1312 < typename slist_impl::iterator
|
Chris@16
|
1313 , downcast_node_to_value_t
|
Chris@101
|
1314 < value_traits
|
Chris@16
|
1315 , false> > local_iterator;
|
Chris@16
|
1316
|
Chris@16
|
1317 typedef detail::transform_iterator
|
Chris@16
|
1318 < typename slist_impl::iterator
|
Chris@101
|
1319 , downcast_node_to_value_t
|
Chris@101
|
1320 < value_traits
|
Chris@16
|
1321 , true> > const_local_iterator;
|
Chris@16
|
1322
|
Chris@16
|
1323 public:
|
Chris@16
|
1324
|
Chris@16
|
1325 //! <b>Requires</b>: buckets must not be being used by any other resource.
|
Chris@16
|
1326 //!
|
Chris@16
|
1327 //! <b>Effects</b>: Constructs an empty unordered_set, storing a reference
|
Chris@16
|
1328 //! to the bucket array and copies of the key_hasher and equal_func functors.
|
Chris@16
|
1329 //!
|
Chris@16
|
1330 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1331 //!
|
Chris@16
|
1332 //! <b>Throws</b>: If value_traits::node_traits::node
|
Chris@16
|
1333 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
|
Chris@16
|
1334 //! or the copy constructor or invocation of hash_func or equal_func throws.
|
Chris@16
|
1335 //!
|
Chris@16
|
1336 //! <b>Notes</b>: buckets array must be disposed only after
|
Chris@16
|
1337 //! *this is disposed.
|
Chris@16
|
1338 explicit hashtable_impl ( const bucket_traits &b_traits
|
Chris@16
|
1339 , const hasher & hash_func = hasher()
|
Chris@16
|
1340 , const key_equal &equal_func = key_equal()
|
Chris@16
|
1341 , const value_traits &v_traits = value_traits())
|
Chris@16
|
1342 : data_type(b_traits, hash_func, equal_func, v_traits)
|
Chris@16
|
1343 {
|
Chris@101
|
1344 this->data_type::internal.priv_initialize_buckets_and_cache();
|
Chris@16
|
1345 this->priv_size_traits().set_size(size_type(0));
|
Chris@16
|
1346 size_type bucket_sz = this->priv_bucket_count();
|
Chris@16
|
1347 BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_sz != 0);
|
Chris@16
|
1348 //Check power of two bucket array if the option is activated
|
Chris@16
|
1349 BOOST_INTRUSIVE_INVARIANT_ASSERT
|
Chris@16
|
1350 (!power_2_buckets || (0 == (bucket_sz & (bucket_sz-1))));
|
Chris@16
|
1351 this->priv_split_traits().set_size(bucket_sz>>1);
|
Chris@16
|
1352 }
|
Chris@16
|
1353
|
Chris@16
|
1354 //! <b>Effects</b>: to-do
|
Chris@16
|
1355 //!
|
Chris@16
|
1356 hashtable_impl(BOOST_RV_REF(hashtable_impl) x)
|
Chris@16
|
1357 : data_type( ::boost::move(x.priv_bucket_traits())
|
Chris@16
|
1358 , ::boost::move(x.priv_hasher())
|
Chris@16
|
1359 , ::boost::move(x.priv_equal())
|
Chris@16
|
1360 , ::boost::move(x.priv_value_traits())
|
Chris@16
|
1361 )
|
Chris@16
|
1362 {
|
Chris@16
|
1363 this->priv_swap_cache(x);
|
Chris@16
|
1364 x.priv_initialize_cache();
|
Chris@16
|
1365 if(constant_time_size){
|
Chris@16
|
1366 this->priv_size_traits().set_size(size_type(0));
|
Chris@16
|
1367 this->priv_size_traits().set_size(x.priv_size_traits().get_size());
|
Chris@16
|
1368 x.priv_size_traits().set_size(size_type(0));
|
Chris@16
|
1369 }
|
Chris@16
|
1370 if(incremental){
|
Chris@16
|
1371 this->priv_split_traits().set_size(x.priv_split_traits().get_size());
|
Chris@16
|
1372 x.priv_split_traits().set_size(size_type(0));
|
Chris@16
|
1373 }
|
Chris@16
|
1374 }
|
Chris@16
|
1375
|
Chris@16
|
1376 //! <b>Effects</b>: to-do
|
Chris@16
|
1377 //!
|
Chris@16
|
1378 hashtable_impl& operator=(BOOST_RV_REF(hashtable_impl) x)
|
Chris@16
|
1379 { this->swap(x); return *this; }
|
Chris@16
|
1380
|
Chris@16
|
1381 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
1382 //! <b>Effects</b>: Detaches all elements from this. The objects in the unordered_set
|
Chris@16
|
1383 //! are not deleted (i.e. no destructors are called).
|
Chris@16
|
1384 //!
|
Chris@16
|
1385 //! <b>Complexity</b>: Linear to the number of elements in the unordered_set, if
|
Chris@16
|
1386 //! it's a safe-mode or auto-unlink value. Otherwise constant.
|
Chris@16
|
1387 //!
|
Chris@16
|
1388 //! <b>Throws</b>: Nothing.
|
Chris@101
|
1389 ~hashtable_impl();
|
Chris@16
|
1390 #endif
|
Chris@16
|
1391
|
Chris@16
|
1392 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the unordered_set.
|
Chris@16
|
1393 //!
|
Chris@16
|
1394 //! <b>Complexity</b>: Amortized constant time.
|
Chris@16
|
1395 //! Worst case (empty unordered_set): O(this->bucket_count())
|
Chris@16
|
1396 //!
|
Chris@16
|
1397 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1398 iterator begin()
|
Chris@16
|
1399 { return iterator(this->priv_begin(), &this->get_bucket_value_traits()); }
|
Chris@16
|
1400
|
Chris@16
|
1401 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
|
Chris@16
|
1402 //! of the unordered_set.
|
Chris@16
|
1403 //!
|
Chris@16
|
1404 //! <b>Complexity</b>: Amortized constant time.
|
Chris@16
|
1405 //! Worst case (empty unordered_set): O(this->bucket_count())
|
Chris@16
|
1406 //!
|
Chris@16
|
1407 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1408 const_iterator begin() const
|
Chris@16
|
1409 { return this->cbegin(); }
|
Chris@16
|
1410
|
Chris@16
|
1411 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
|
Chris@16
|
1412 //! of the unordered_set.
|
Chris@16
|
1413 //!
|
Chris@16
|
1414 //! <b>Complexity</b>: Amortized constant time.
|
Chris@16
|
1415 //! Worst case (empty unordered_set): O(this->bucket_count())
|
Chris@16
|
1416 //!
|
Chris@16
|
1417 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1418 const_iterator cbegin() const
|
Chris@16
|
1419 { return const_iterator(this->priv_begin(), &this->get_bucket_value_traits()); }
|
Chris@16
|
1420
|
Chris@16
|
1421 //! <b>Effects</b>: Returns an iterator pointing to the end of the unordered_set.
|
Chris@16
|
1422 //!
|
Chris@16
|
1423 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1424 //!
|
Chris@16
|
1425 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1426 iterator end()
|
Chris@16
|
1427 { return iterator(this->priv_invalid_local_it(), 0); }
|
Chris@16
|
1428
|
Chris@16
|
1429 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set.
|
Chris@16
|
1430 //!
|
Chris@16
|
1431 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1432 //!
|
Chris@16
|
1433 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1434 const_iterator end() const
|
Chris@16
|
1435 { return this->cend(); }
|
Chris@16
|
1436
|
Chris@16
|
1437 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set.
|
Chris@16
|
1438 //!
|
Chris@16
|
1439 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1440 //!
|
Chris@16
|
1441 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1442 const_iterator cend() const
|
Chris@16
|
1443 { return const_iterator(this->priv_invalid_local_it(), 0); }
|
Chris@16
|
1444
|
Chris@16
|
1445 //! <b>Effects</b>: Returns the hasher object used by the unordered_set.
|
Chris@16
|
1446 //!
|
Chris@16
|
1447 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1448 //!
|
Chris@16
|
1449 //! <b>Throws</b>: If hasher copy-constructor throws.
|
Chris@16
|
1450 hasher hash_function() const
|
Chris@16
|
1451 { return this->priv_hasher(); }
|
Chris@16
|
1452
|
Chris@16
|
1453 //! <b>Effects</b>: Returns the key_equal object used by the unordered_set.
|
Chris@16
|
1454 //!
|
Chris@16
|
1455 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1456 //!
|
Chris@16
|
1457 //! <b>Throws</b>: If key_equal copy-constructor throws.
|
Chris@16
|
1458 key_equal key_eq() const
|
Chris@16
|
1459 { return this->priv_equal(); }
|
Chris@16
|
1460
|
Chris@16
|
1461 //! <b>Effects</b>: Returns true if the container is empty.
|
Chris@16
|
1462 //!
|
Chris@16
|
1463 //! <b>Complexity</b>: if constant-time size and cache_begin options are disabled,
|
Chris@16
|
1464 //! average constant time (worst case, with empty() == true: O(this->bucket_count()).
|
Chris@16
|
1465 //! Otherwise constant.
|
Chris@16
|
1466 //!
|
Chris@16
|
1467 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1468 bool empty() const
|
Chris@16
|
1469 {
|
Chris@16
|
1470 if(constant_time_size){
|
Chris@16
|
1471 return !this->size();
|
Chris@16
|
1472 }
|
Chris@16
|
1473 else if(cache_begin){
|
Chris@16
|
1474 return this->begin() == this->end();
|
Chris@16
|
1475 }
|
Chris@16
|
1476 else{
|
Chris@16
|
1477 size_type bucket_cnt = this->priv_bucket_count();
|
Chris@16
|
1478 const bucket_type *b = boost::intrusive::detail::to_raw_pointer(this->priv_bucket_pointer());
|
Chris@16
|
1479 for (size_type n = 0; n < bucket_cnt; ++n, ++b){
|
Chris@16
|
1480 if(!b->empty()){
|
Chris@16
|
1481 return false;
|
Chris@16
|
1482 }
|
Chris@16
|
1483 }
|
Chris@16
|
1484 return true;
|
Chris@16
|
1485 }
|
Chris@16
|
1486 }
|
Chris@16
|
1487
|
Chris@16
|
1488 //! <b>Effects</b>: Returns the number of elements stored in the unordered_set.
|
Chris@16
|
1489 //!
|
Chris@16
|
1490 //! <b>Complexity</b>: Linear to elements contained in *this if
|
Chris@16
|
1491 //! constant_time_size is false. Constant-time otherwise.
|
Chris@16
|
1492 //!
|
Chris@16
|
1493 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1494 size_type size() const
|
Chris@16
|
1495 {
|
Chris@16
|
1496 if(constant_time_size)
|
Chris@16
|
1497 return this->priv_size_traits().get_size();
|
Chris@16
|
1498 else{
|
Chris@16
|
1499 size_type len = 0;
|
Chris@16
|
1500 size_type bucket_cnt = this->priv_bucket_count();
|
Chris@16
|
1501 const bucket_type *b = boost::intrusive::detail::to_raw_pointer(this->priv_bucket_pointer());
|
Chris@16
|
1502 for (size_type n = 0; n < bucket_cnt; ++n, ++b){
|
Chris@16
|
1503 len += b->size();
|
Chris@16
|
1504 }
|
Chris@16
|
1505 return len;
|
Chris@16
|
1506 }
|
Chris@16
|
1507 }
|
Chris@16
|
1508
|
Chris@16
|
1509 //! <b>Requires</b>: the hasher and the equality function unqualified swap
|
Chris@16
|
1510 //! call should not throw.
|
Chris@16
|
1511 //!
|
Chris@16
|
1512 //! <b>Effects</b>: Swaps the contents of two unordered_sets.
|
Chris@16
|
1513 //! Swaps also the contained bucket array and equality and hasher functors.
|
Chris@16
|
1514 //!
|
Chris@16
|
1515 //! <b>Complexity</b>: Constant.
|
Chris@16
|
1516 //!
|
Chris@16
|
1517 //! <b>Throws</b>: If the swap() call for the comparison or hash functors
|
Chris@16
|
1518 //! found using ADL throw. Basic guarantee.
|
Chris@16
|
1519 void swap(hashtable_impl& other)
|
Chris@16
|
1520 {
|
Chris@16
|
1521 //These can throw
|
Chris@101
|
1522 ::boost::adl_move_swap(this->priv_equal(), other.priv_equal());
|
Chris@101
|
1523 ::boost::adl_move_swap(this->priv_hasher(), other.priv_hasher());
|
Chris@16
|
1524 //These can't throw
|
Chris@101
|
1525 ::boost::adl_move_swap(this->priv_bucket_traits(), other.priv_bucket_traits());
|
Chris@101
|
1526 ::boost::adl_move_swap(this->priv_value_traits(), other.priv_value_traits());
|
Chris@16
|
1527 this->priv_swap_cache(other);
|
Chris@16
|
1528 if(constant_time_size){
|
Chris@16
|
1529 size_type backup = this->priv_size_traits().get_size();
|
Chris@16
|
1530 this->priv_size_traits().set_size(other.priv_size_traits().get_size());
|
Chris@16
|
1531 other.priv_size_traits().set_size(backup);
|
Chris@16
|
1532 }
|
Chris@16
|
1533 if(incremental){
|
Chris@16
|
1534 size_type backup = this->priv_split_traits().get_size();
|
Chris@16
|
1535 this->priv_split_traits().set_size(other.priv_split_traits().get_size());
|
Chris@16
|
1536 other.priv_split_traits().set_size(backup);
|
Chris@16
|
1537 }
|
Chris@16
|
1538 }
|
Chris@16
|
1539
|
Chris@16
|
1540 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw
|
Chris@16
|
1541 //! Cloner should yield to nodes that compare equal and produce the same
|
Chris@16
|
1542 //! hash than the original node.
|
Chris@16
|
1543 //!
|
Chris@16
|
1544 //! <b>Effects</b>: Erases all the elements from *this
|
Chris@16
|
1545 //! calling Disposer::operator()(pointer), clones all the
|
Chris@16
|
1546 //! elements from src calling Cloner::operator()(const_reference )
|
Chris@16
|
1547 //! and inserts them on *this. The hash function and the equality
|
Chris@16
|
1548 //! predicate are copied from the source.
|
Chris@16
|
1549 //!
|
Chris@16
|
1550 //! If store_hash option is true, this method does not use the hash function.
|
Chris@16
|
1551 //!
|
Chris@16
|
1552 //! If any operation throws, all cloned elements are unlinked and disposed
|
Chris@16
|
1553 //! calling Disposer::operator()(pointer).
|
Chris@16
|
1554 //!
|
Chris@16
|
1555 //! <b>Complexity</b>: Linear to erased plus inserted elements.
|
Chris@16
|
1556 //!
|
Chris@16
|
1557 //! <b>Throws</b>: If cloner or hasher throw or hash or equality predicate copying
|
Chris@16
|
1558 //! throws. Basic guarantee.
|
Chris@16
|
1559 template <class Cloner, class Disposer>
|
Chris@16
|
1560 void clone_from(const hashtable_impl &src, Cloner cloner, Disposer disposer)
|
Chris@16
|
1561 {
|
Chris@16
|
1562 this->clear_and_dispose(disposer);
|
Chris@16
|
1563 if(!constant_time_size || !src.empty()){
|
Chris@16
|
1564 const size_type src_bucket_count = src.bucket_count();
|
Chris@16
|
1565 const size_type dst_bucket_count = this->bucket_count();
|
Chris@16
|
1566 //Check power of two bucket array if the option is activated
|
Chris@16
|
1567 BOOST_INTRUSIVE_INVARIANT_ASSERT
|
Chris@16
|
1568 (!power_2_buckets || (0 == (src_bucket_count & (src_bucket_count-1))));
|
Chris@16
|
1569 BOOST_INTRUSIVE_INVARIANT_ASSERT
|
Chris@16
|
1570 (!power_2_buckets || (0 == (dst_bucket_count & (dst_bucket_count-1))));
|
Chris@16
|
1571
|
Chris@16
|
1572 //If src bucket count is bigger or equal, structural copy is possible
|
Chris@16
|
1573 if(!incremental && (src_bucket_count >= dst_bucket_count)){
|
Chris@16
|
1574 //First clone the first ones
|
Chris@16
|
1575 const bucket_ptr src_buckets = src.priv_bucket_pointer();
|
Chris@16
|
1576 const bucket_ptr dst_buckets = this->priv_bucket_pointer();
|
Chris@16
|
1577 size_type constructed;
|
Chris@101
|
1578
|
Chris@101
|
1579 typedef node_cast_adaptor< detail::node_disposer<Disposer, value_traits, CircularSListAlgorithms>
|
Chris@16
|
1580 , slist_node_ptr, node_ptr > NodeDisposer;
|
Chris@101
|
1581 typedef node_cast_adaptor< detail::node_cloner <Cloner, value_traits, CircularSListAlgorithms>
|
Chris@16
|
1582 , slist_node_ptr, node_ptr > NodeCloner;
|
Chris@101
|
1583 NodeDisposer node_disp(disposer, &this->priv_value_traits());
|
Chris@16
|
1584
|
Chris@16
|
1585 detail::exception_array_disposer<bucket_type, NodeDisposer, size_type>
|
Chris@16
|
1586 rollback(dst_buckets[0], node_disp, constructed);
|
Chris@16
|
1587 for( constructed = 0
|
Chris@16
|
1588 ; constructed < dst_bucket_count
|
Chris@16
|
1589 ; ++constructed){
|
Chris@16
|
1590 dst_buckets[constructed].clone_from
|
Chris@16
|
1591 ( src_buckets[constructed]
|
Chris@101
|
1592 , NodeCloner(cloner, &this->priv_value_traits()), node_disp);
|
Chris@16
|
1593 }
|
Chris@16
|
1594 if(src_bucket_count != dst_bucket_count){
|
Chris@16
|
1595 //Now insert the remaining ones using the modulo trick
|
Chris@16
|
1596 for(//"constructed" comes from the previous loop
|
Chris@16
|
1597 ; constructed < src_bucket_count
|
Chris@16
|
1598 ; ++constructed){
|
Chris@16
|
1599 bucket_type &dst_b =
|
Chris@16
|
1600 dst_buckets[detail::hash_to_bucket_split<power_2_buckets, incremental>(constructed, dst_bucket_count, dst_bucket_count)];
|
Chris@16
|
1601 bucket_type &src_b = src_buckets[constructed];
|
Chris@16
|
1602 for( siterator b(src_b.begin()), e(src_b.end())
|
Chris@16
|
1603 ; b != e
|
Chris@16
|
1604 ; ++b){
|
Chris@101
|
1605 dst_b.push_front(*(NodeCloner(cloner, &this->priv_value_traits())(*b.pointed_node())));
|
Chris@16
|
1606 }
|
Chris@16
|
1607 }
|
Chris@16
|
1608 }
|
Chris@16
|
1609 this->priv_hasher() = src.priv_hasher();
|
Chris@16
|
1610 this->priv_equal() = src.priv_equal();
|
Chris@16
|
1611 rollback.release();
|
Chris@16
|
1612 this->priv_size_traits().set_size(src.priv_size_traits().get_size());
|
Chris@16
|
1613 this->priv_split_traits().set_size(dst_bucket_count);
|
Chris@16
|
1614 this->priv_insertion_update_cache(0u);
|
Chris@16
|
1615 this->priv_erasure_update_cache();
|
Chris@16
|
1616 }
|
Chris@16
|
1617 else if(store_hash){
|
Chris@16
|
1618 //Unlike previous cloning algorithm, this can throw
|
Chris@16
|
1619 //if cloner, hasher or comparison functor throw
|
Chris@101
|
1620 const_iterator b(src.cbegin()), e(src.cend());
|
Chris@16
|
1621 detail::exception_disposer<hashtable_impl, Disposer>
|
Chris@16
|
1622 rollback(*this, disposer);
|
Chris@16
|
1623 for(; b != e; ++b){
|
Chris@16
|
1624 std::size_t hash_value = this->priv_stored_or_compute_hash(*b, store_hash_t());;
|
Chris@16
|
1625 this->priv_insert_equal_with_hash(*cloner(*b), hash_value);
|
Chris@16
|
1626 }
|
Chris@16
|
1627 rollback.release();
|
Chris@16
|
1628 }
|
Chris@16
|
1629 else{
|
Chris@16
|
1630 //Unlike previous cloning algorithm, this can throw
|
Chris@16
|
1631 //if cloner, hasher or comparison functor throw
|
Chris@101
|
1632 const_iterator b(src.cbegin()), e(src.cend());
|
Chris@16
|
1633 detail::exception_disposer<hashtable_impl, Disposer>
|
Chris@16
|
1634 rollback(*this, disposer);
|
Chris@16
|
1635 for(; b != e; ++b){
|
Chris@16
|
1636 this->insert_equal(*cloner(*b));
|
Chris@16
|
1637 }
|
Chris@16
|
1638 rollback.release();
|
Chris@16
|
1639 }
|
Chris@16
|
1640 }
|
Chris@16
|
1641 }
|
Chris@16
|
1642
|
Chris@16
|
1643 //! <b>Requires</b>: value must be an lvalue
|
Chris@16
|
1644 //!
|
Chris@16
|
1645 //! <b>Effects</b>: Inserts the value into the unordered_set.
|
Chris@16
|
1646 //!
|
Chris@16
|
1647 //! <b>Returns</b>: An iterator to the inserted value.
|
Chris@16
|
1648 //!
|
Chris@16
|
1649 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
|
Chris@16
|
1650 //!
|
Chris@16
|
1651 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Strong guarantee.
|
Chris@16
|
1652 //!
|
Chris@16
|
1653 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
1654 //! No copy-constructors are called.
|
Chris@16
|
1655 iterator insert_equal(reference value)
|
Chris@16
|
1656 {
|
Chris@16
|
1657 size_type bucket_num;
|
Chris@16
|
1658 std::size_t hash_value;
|
Chris@16
|
1659 siterator prev;
|
Chris@16
|
1660 siterator it = this->priv_find
|
Chris@16
|
1661 (value, this->priv_hasher(), this->priv_equal(), bucket_num, hash_value, prev);
|
Chris@16
|
1662 return this->priv_insert_equal_find(value, bucket_num, hash_value, it);
|
Chris@16
|
1663 }
|
Chris@16
|
1664
|
Chris@16
|
1665 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
|
Chris@16
|
1666 //! of type value_type.
|
Chris@16
|
1667 //!
|
Chris@16
|
1668 //! <b>Effects</b>: Equivalent to this->insert_equal(t) for each element in [b, e).
|
Chris@16
|
1669 //!
|
Chris@101
|
1670 //! <b>Complexity</b>: Average case O(N), where N is distance(b, e).
|
Chris@16
|
1671 //! Worst case O(N*this->size()).
|
Chris@16
|
1672 //!
|
Chris@16
|
1673 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
|
Chris@16
|
1674 //!
|
Chris@16
|
1675 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
1676 //! No copy-constructors are called.
|
Chris@16
|
1677 template<class Iterator>
|
Chris@16
|
1678 void insert_equal(Iterator b, Iterator e)
|
Chris@16
|
1679 {
|
Chris@16
|
1680 for (; b != e; ++b)
|
Chris@16
|
1681 this->insert_equal(*b);
|
Chris@16
|
1682 }
|
Chris@16
|
1683
|
Chris@16
|
1684 //! <b>Requires</b>: value must be an lvalue
|
Chris@16
|
1685 //!
|
Chris@16
|
1686 //! <b>Effects</b>: Tries to inserts value into the unordered_set.
|
Chris@16
|
1687 //!
|
Chris@16
|
1688 //! <b>Returns</b>: If the value
|
Chris@16
|
1689 //! is not already present inserts it and returns a pair containing the
|
Chris@16
|
1690 //! iterator to the new value and true. If there is an equivalent value
|
Chris@16
|
1691 //! returns a pair containing an iterator to the already present value
|
Chris@16
|
1692 //! and false.
|
Chris@16
|
1693 //!
|
Chris@16
|
1694 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
|
Chris@16
|
1695 //!
|
Chris@16
|
1696 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Strong guarantee.
|
Chris@16
|
1697 //!
|
Chris@16
|
1698 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
1699 //! No copy-constructors are called.
|
Chris@16
|
1700 std::pair<iterator, bool> insert_unique(reference value)
|
Chris@16
|
1701 {
|
Chris@16
|
1702 insert_commit_data commit_data;
|
Chris@16
|
1703 std::pair<iterator, bool> ret = this->insert_unique_check
|
Chris@16
|
1704 (value, this->priv_hasher(), this->priv_equal(), commit_data);
|
Chris@16
|
1705 if(!ret.second)
|
Chris@16
|
1706 return ret;
|
Chris@16
|
1707 return std::pair<iterator, bool>
|
Chris@16
|
1708 (this->insert_unique_commit(value, commit_data), true);
|
Chris@16
|
1709 }
|
Chris@16
|
1710
|
Chris@16
|
1711 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
|
Chris@16
|
1712 //! of type value_type.
|
Chris@16
|
1713 //!
|
Chris@16
|
1714 //! <b>Effects</b>: Equivalent to this->insert_unique(t) for each element in [b, e).
|
Chris@16
|
1715 //!
|
Chris@101
|
1716 //! <b>Complexity</b>: Average case O(N), where N is distance(b, e).
|
Chris@16
|
1717 //! Worst case O(N*this->size()).
|
Chris@16
|
1718 //!
|
Chris@16
|
1719 //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
|
Chris@16
|
1720 //!
|
Chris@16
|
1721 //! <b>Note</b>: Does not affect the validity of iterators and references.
|
Chris@16
|
1722 //! No copy-constructors are called.
|
Chris@16
|
1723 template<class Iterator>
|
Chris@16
|
1724 void insert_unique(Iterator b, Iterator e)
|
Chris@16
|
1725 {
|
Chris@16
|
1726 for (; b != e; ++b)
|
Chris@16
|
1727 this->insert_unique(*b);
|
Chris@16
|
1728 }
|
Chris@16
|
1729
|
Chris@16
|
1730 //! <b>Requires</b>: "hash_func" must be a hash function that induces
|
Chris@16
|
1731 //! the same hash values as the stored hasher. The difference is that
|
Chris@16
|
1732 //! "hash_func" hashes the given key instead of the value_type.
|
Chris@16
|
1733 //!
|
Chris@16
|
1734 //! "equal_func" must be a equality function that induces
|
Chris@16
|
1735 //! the same equality as key_equal. The difference is that
|
Chris@16
|
1736 //! "equal_func" compares an arbitrary key with the contained values.
|
Chris@16
|
1737 //!
|
Chris@16
|
1738 //! <b>Effects</b>: Checks if a value can be inserted in the unordered_set, using
|
Chris@16
|
1739 //! a user provided key instead of the value itself.
|
Chris@16
|
1740 //!
|
Chris@16
|
1741 //! <b>Returns</b>: If there is an equivalent value
|
Chris@16
|
1742 //! returns a pair containing an iterator to the already present value
|
Chris@16
|
1743 //! and false. If the value can be inserted returns true in the returned
|
Chris@16
|
1744 //! pair boolean and fills "commit_data" that is meant to be used with
|
Chris@16
|
1745 //! the "insert_commit" function.
|
Chris@16
|
1746 //!
|
Chris@16
|
1747 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
|
Chris@16
|
1748 //!
|
Chris@16
|
1749 //! <b>Throws</b>: If hash_func or equal_func throw. Strong guarantee.
|
Chris@16
|
1750 //!
|
Chris@16
|
1751 //! <b>Notes</b>: This function is used to improve performance when constructing
|
Chris@16
|
1752 //! a value_type is expensive: if there is an equivalent value
|
Chris@16
|
1753 //! the constructed object must be discarded. Many times, the part of the
|
Chris@16
|
1754 //! node that is used to impose the hash or the equality is much cheaper to
|
Chris@16
|
1755 //! construct than the value_type and this function offers the possibility to
|
Chris@16
|
1756 //! use that the part to check if the insertion will be successful.
|
Chris@16
|
1757 //!
|
Chris@16
|
1758 //! If the check is successful, the user can construct the value_type and use
|
Chris@16
|
1759 //! "insert_commit" to insert the object in constant-time.
|
Chris@16
|
1760 //!
|
Chris@16
|
1761 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
|
Chris@16
|
1762 //! objects are inserted or erased from the unordered_set.
|
Chris@16
|
1763 //!
|
Chris@16
|
1764 //! After a successful rehashing insert_commit_data remains valid.
|
Chris@16
|
1765 template<class KeyType, class KeyHasher, class KeyValueEqual>
|
Chris@16
|
1766 std::pair<iterator, bool> insert_unique_check
|
Chris@16
|
1767 ( const KeyType &key
|
Chris@16
|
1768 , KeyHasher hash_func
|
Chris@16
|
1769 , KeyValueEqual equal_func
|
Chris@16
|
1770 , insert_commit_data &commit_data)
|
Chris@16
|
1771 {
|
Chris@16
|
1772 size_type bucket_num;
|
Chris@16
|
1773 siterator prev;
|
Chris@16
|
1774 siterator prev_pos =
|
Chris@16
|
1775 this->priv_find(key, hash_func, equal_func, bucket_num, commit_data.hash, prev);
|
Chris@16
|
1776 bool success = prev_pos == this->priv_invalid_local_it();
|
Chris@16
|
1777 if(success){
|
Chris@16
|
1778 prev_pos = prev;
|
Chris@16
|
1779 }
|
Chris@16
|
1780 return std::pair<iterator, bool>(iterator(prev_pos, &this->get_bucket_value_traits()),success);
|
Chris@16
|
1781 }
|
Chris@16
|
1782
|
Chris@16
|
1783 //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
|
Chris@16
|
1784 //! must have been obtained from a previous call to "insert_check".
|
Chris@16
|
1785 //! No objects should have been inserted or erased from the unordered_set between
|
Chris@16
|
1786 //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
|
Chris@16
|
1787 //!
|
Chris@16
|
1788 //! <b>Effects</b>: Inserts the value in the unordered_set using the information obtained
|
Chris@16
|
1789 //! from the "commit_data" that a previous "insert_check" filled.
|
Chris@16
|
1790 //!
|
Chris@16
|
1791 //! <b>Returns</b>: An iterator to the newly inserted object.
|
Chris@16
|
1792 //!
|
Chris@16
|
1793 //! <b>Complexity</b>: Constant time.
|
Chris@16
|
1794 //!
|
Chris@16
|
1795 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1796 //!
|
Chris@16
|
1797 //! <b>Notes</b>: This function has only sense if a "insert_check" has been
|
Chris@16
|
1798 //! previously executed to fill "commit_data". No value should be inserted or
|
Chris@16
|
1799 //! erased between the "insert_check" and "insert_commit" calls.
|
Chris@16
|
1800 //!
|
Chris@16
|
1801 //! After a successful rehashing insert_commit_data remains valid.
|
Chris@16
|
1802 iterator insert_unique_commit(reference value, const insert_commit_data &commit_data)
|
Chris@16
|
1803 {
|
Chris@16
|
1804 size_type bucket_num = this->priv_hash_to_bucket(commit_data.hash);
|
Chris@16
|
1805 bucket_type &b = this->priv_bucket_pointer()[bucket_num];
|
Chris@16
|
1806 this->priv_size_traits().increment();
|
Chris@16
|
1807 node_ptr n = pointer_traits<node_ptr>::pointer_to(this->priv_value_to_node(value));
|
Chris@16
|
1808 node_functions_t::store_hash(n, commit_data.hash, store_hash_t());
|
Chris@16
|
1809 if(safemode_or_autounlink)
|
Chris@16
|
1810 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n));
|
Chris@16
|
1811 this->priv_insertion_update_cache(bucket_num);
|
Chris@16
|
1812 group_functions_t::insert_in_group(node_ptr(), n, optimize_multikey_t());
|
Chris@16
|
1813 return iterator(b.insert_after(b.before_begin(), *n), &this->get_bucket_value_traits());
|
Chris@16
|
1814 }
|
Chris@16
|
1815
|
Chris@16
|
1816 //! <b>Effects</b>: Erases the element pointed to by i.
|
Chris@16
|
1817 //!
|
Chris@16
|
1818 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
|
Chris@16
|
1819 //!
|
Chris@16
|
1820 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1821 //!
|
Chris@16
|
1822 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1823 //! to the erased element. No destructors are called.
|
Chris@16
|
1824 void erase(const_iterator i)
|
Chris@16
|
1825 { this->erase_and_dispose(i, detail::null_disposer()); }
|
Chris@16
|
1826
|
Chris@16
|
1827 //! <b>Effects</b>: Erases the range pointed to by b end e.
|
Chris@16
|
1828 //!
|
Chris@101
|
1829 //! <b>Complexity</b>: Average case O(distance(b, e)),
|
Chris@16
|
1830 //! worst case O(this->size()).
|
Chris@16
|
1831 //!
|
Chris@16
|
1832 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1833 //!
|
Chris@16
|
1834 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1835 //! to the erased elements. No destructors are called.
|
Chris@16
|
1836 void erase(const_iterator b, const_iterator e)
|
Chris@16
|
1837 { this->erase_and_dispose(b, e, detail::null_disposer()); }
|
Chris@16
|
1838
|
Chris@16
|
1839 //! <b>Effects</b>: Erases all the elements with the given value.
|
Chris@16
|
1840 //!
|
Chris@16
|
1841 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
1842 //!
|
Chris@16
|
1843 //! <b>Complexity</b>: Average case O(this->count(value)).
|
Chris@16
|
1844 //! Worst case O(this->size()).
|
Chris@16
|
1845 //!
|
Chris@16
|
1846 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
|
Chris@16
|
1847 //! Basic guarantee.
|
Chris@16
|
1848 //!
|
Chris@16
|
1849 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1850 //! to the erased elements. No destructors are called.
|
Chris@16
|
1851 size_type erase(const_reference value)
|
Chris@16
|
1852 { return this->erase(value, this->priv_hasher(), this->priv_equal()); }
|
Chris@16
|
1853
|
Chris@16
|
1854 //! <b>Requires</b>: "hash_func" must be a hash function that induces
|
Chris@16
|
1855 //! the same hash values as the stored hasher. The difference is that
|
Chris@16
|
1856 //! "hash_func" hashes the given key instead of the value_type.
|
Chris@16
|
1857 //!
|
Chris@16
|
1858 //! "equal_func" must be a equality function that induces
|
Chris@16
|
1859 //! the same equality as key_equal. The difference is that
|
Chris@16
|
1860 //! "equal_func" compares an arbitrary key with the contained values.
|
Chris@16
|
1861 //!
|
Chris@16
|
1862 //! <b>Effects</b>: Erases all the elements that have the same hash and
|
Chris@16
|
1863 //! compare equal with the given key.
|
Chris@16
|
1864 //!
|
Chris@16
|
1865 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
1866 //!
|
Chris@16
|
1867 //! <b>Complexity</b>: Average case O(this->count(value)).
|
Chris@16
|
1868 //! Worst case O(this->size()).
|
Chris@16
|
1869 //!
|
Chris@16
|
1870 //! <b>Throws</b>: If hash_func or equal_func throw. Basic guarantee.
|
Chris@16
|
1871 //!
|
Chris@16
|
1872 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1873 //! to the erased elements. No destructors are called.
|
Chris@16
|
1874 template<class KeyType, class KeyHasher, class KeyValueEqual>
|
Chris@16
|
1875 size_type erase(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func)
|
Chris@16
|
1876 { return this->erase_and_dispose(key, hash_func, equal_func, detail::null_disposer()); }
|
Chris@16
|
1877
|
Chris@16
|
1878 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
1879 //!
|
Chris@16
|
1880 //! <b>Effects</b>: Erases the element pointed to by i.
|
Chris@16
|
1881 //! Disposer::operator()(pointer) is called for the removed element.
|
Chris@16
|
1882 //!
|
Chris@16
|
1883 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
|
Chris@16
|
1884 //!
|
Chris@16
|
1885 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1886 //!
|
Chris@16
|
1887 //! <b>Note</b>: Invalidates the iterators
|
Chris@16
|
1888 //! to the erased elements.
|
Chris@16
|
1889 template<class Disposer>
|
Chris@16
|
1890 void erase_and_dispose(const_iterator i, Disposer disposer
|
Chris@16
|
1891 /// @cond
|
Chris@16
|
1892 , typename detail::enable_if_c<!detail::is_convertible<Disposer, const_iterator>::value >::type * = 0
|
Chris@16
|
1893 /// @endcond
|
Chris@16
|
1894 )
|
Chris@16
|
1895 {
|
Chris@16
|
1896 this->priv_erase(i, disposer, optimize_multikey_t());
|
Chris@16
|
1897 this->priv_size_traits().decrement();
|
Chris@16
|
1898 this->priv_erasure_update_cache();
|
Chris@16
|
1899 }
|
Chris@16
|
1900
|
Chris@16
|
1901 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
1902 //!
|
Chris@16
|
1903 //! <b>Effects</b>: Erases the range pointed to by b end e.
|
Chris@16
|
1904 //! Disposer::operator()(pointer) is called for the removed elements.
|
Chris@16
|
1905 //!
|
Chris@101
|
1906 //! <b>Complexity</b>: Average case O(distance(b, e)),
|
Chris@16
|
1907 //! worst case O(this->size()).
|
Chris@16
|
1908 //!
|
Chris@16
|
1909 //! <b>Throws</b>: Nothing.
|
Chris@16
|
1910 //!
|
Chris@16
|
1911 //! <b>Note</b>: Invalidates the iterators
|
Chris@16
|
1912 //! to the erased elements.
|
Chris@16
|
1913 template<class Disposer>
|
Chris@16
|
1914 void erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
|
Chris@16
|
1915 {
|
Chris@16
|
1916 if(b != e){
|
Chris@16
|
1917 //Get the bucket number and local iterator for both iterators
|
Chris@16
|
1918 siterator first_local_it(b.slist_it());
|
Chris@16
|
1919 size_type first_bucket_num = this->priv_get_bucket_num(first_local_it);
|
Chris@16
|
1920
|
Chris@16
|
1921 const bucket_ptr buck_ptr = this->priv_bucket_pointer();
|
Chris@16
|
1922 siterator before_first_local_it
|
Chris@16
|
1923 = this->priv_get_previous(buck_ptr[first_bucket_num], first_local_it);
|
Chris@16
|
1924 size_type last_bucket_num;
|
Chris@16
|
1925 siterator last_local_it;
|
Chris@16
|
1926
|
Chris@16
|
1927 //For the end iterator, we will assign the end iterator
|
Chris@16
|
1928 //of the last bucket
|
Chris@16
|
1929 if(e == this->end()){
|
Chris@16
|
1930 last_bucket_num = this->bucket_count() - 1;
|
Chris@16
|
1931 last_local_it = buck_ptr[last_bucket_num].end();
|
Chris@16
|
1932 }
|
Chris@16
|
1933 else{
|
Chris@16
|
1934 last_local_it = e.slist_it();
|
Chris@16
|
1935 last_bucket_num = this->priv_get_bucket_num(last_local_it);
|
Chris@16
|
1936 }
|
Chris@16
|
1937 this->priv_erase_range(before_first_local_it, first_bucket_num, last_local_it, last_bucket_num, disposer);
|
Chris@16
|
1938 this->priv_erasure_update_cache_range(first_bucket_num, last_bucket_num);
|
Chris@16
|
1939 }
|
Chris@16
|
1940 }
|
Chris@16
|
1941
|
Chris@16
|
1942 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
1943 //!
|
Chris@16
|
1944 //! <b>Effects</b>: Erases all the elements with the given value.
|
Chris@16
|
1945 //! Disposer::operator()(pointer) is called for the removed elements.
|
Chris@16
|
1946 //!
|
Chris@16
|
1947 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
1948 //!
|
Chris@16
|
1949 //! <b>Complexity</b>: Average case O(this->count(value)).
|
Chris@16
|
1950 //! Worst case O(this->size()).
|
Chris@16
|
1951 //!
|
Chris@16
|
1952 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
|
Chris@16
|
1953 //! Basic guarantee.
|
Chris@16
|
1954 //!
|
Chris@16
|
1955 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
1956 //! to the erased elements. No destructors are called.
|
Chris@16
|
1957 template<class Disposer>
|
Chris@16
|
1958 size_type erase_and_dispose(const_reference value, Disposer disposer)
|
Chris@16
|
1959 { return this->erase_and_dispose(value, this->priv_hasher(), this->priv_equal(), disposer); }
|
Chris@16
|
1960
|
Chris@16
|
1961 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
1962 //!
|
Chris@16
|
1963 //! <b>Effects</b>: Erases all the elements with the given key.
|
Chris@16
|
1964 //! according to the comparison functor "equal_func".
|
Chris@16
|
1965 //! Disposer::operator()(pointer) is called for the removed elements.
|
Chris@16
|
1966 //!
|
Chris@16
|
1967 //! <b>Returns</b>: The number of erased elements.
|
Chris@16
|
1968 //!
|
Chris@16
|
1969 //! <b>Complexity</b>: Average case O(this->count(value)).
|
Chris@16
|
1970 //! Worst case O(this->size()).
|
Chris@16
|
1971 //!
|
Chris@16
|
1972 //! <b>Throws</b>: If hash_func or equal_func throw. Basic guarantee.
|
Chris@16
|
1973 //!
|
Chris@16
|
1974 //! <b>Note</b>: Invalidates the iterators
|
Chris@16
|
1975 //! to the erased elements.
|
Chris@16
|
1976 template<class KeyType, class KeyHasher, class KeyValueEqual, class Disposer>
|
Chris@16
|
1977 size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func
|
Chris@16
|
1978 ,KeyValueEqual equal_func, Disposer disposer)
|
Chris@16
|
1979 {
|
Chris@16
|
1980 size_type bucket_num;
|
Chris@16
|
1981 std::size_t h;
|
Chris@16
|
1982 siterator prev;
|
Chris@16
|
1983 siterator it = this->priv_find(key, hash_func, equal_func, bucket_num, h, prev);
|
Chris@16
|
1984 bool success = it != this->priv_invalid_local_it();
|
Chris@16
|
1985 size_type cnt(0);
|
Chris@16
|
1986 if(!success){
|
Chris@16
|
1987 return 0;
|
Chris@16
|
1988 }
|
Chris@16
|
1989 else if(optimize_multikey){
|
Chris@16
|
1990 siterator last = bucket_type::s_iterator_to
|
Chris@16
|
1991 (*node_traits::get_next(group_functions_t::get_last_in_group
|
Chris@16
|
1992 (detail::dcast_bucket_ptr<node>(it.pointed_node()), optimize_multikey_t())));
|
Chris@16
|
1993 this->priv_erase_range_impl(bucket_num, prev, last, disposer, cnt);
|
Chris@16
|
1994 }
|
Chris@16
|
1995 else{
|
Chris@16
|
1996 //If found erase all equal values
|
Chris@16
|
1997 bucket_type &b = this->priv_bucket_pointer()[bucket_num];
|
Chris@16
|
1998 for(siterator end_sit = b.end(); it != end_sit; ++cnt, ++it){
|
Chris@16
|
1999 slist_node_ptr n(it.pointed_node());
|
Chris@16
|
2000 const value_type &v = this->priv_value_from_slist_node(n);
|
Chris@16
|
2001 if(compare_hash){
|
Chris@16
|
2002 std::size_t vh = this->priv_stored_or_compute_hash(v, store_hash_t());
|
Chris@16
|
2003 if(h != vh || !equal_func(key, v)){
|
Chris@16
|
2004 break;
|
Chris@16
|
2005 }
|
Chris@16
|
2006 }
|
Chris@16
|
2007 else if(!equal_func(key, v)){
|
Chris@16
|
2008 break;
|
Chris@16
|
2009 }
|
Chris@16
|
2010 this->priv_size_traits().decrement();
|
Chris@16
|
2011 }
|
Chris@16
|
2012 b.erase_after_and_dispose(prev, it, make_node_disposer(disposer));
|
Chris@16
|
2013 }
|
Chris@16
|
2014 this->priv_erasure_update_cache();
|
Chris@16
|
2015 return cnt;
|
Chris@16
|
2016 }
|
Chris@16
|
2017
|
Chris@16
|
2018 //! <b>Effects</b>: Erases all of the elements.
|
Chris@16
|
2019 //!
|
Chris@16
|
2020 //! <b>Complexity</b>: Linear to the number of elements on the container.
|
Chris@16
|
2021 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
|
Chris@16
|
2022 //!
|
Chris@16
|
2023 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2024 //!
|
Chris@16
|
2025 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
2026 //! to the erased elements. No destructors are called.
|
Chris@16
|
2027 void clear()
|
Chris@16
|
2028 {
|
Chris@101
|
2029 this->data_type::internal.priv_clear_buckets_and_cache();
|
Chris@16
|
2030 this->priv_size_traits().set_size(size_type(0));
|
Chris@16
|
2031 }
|
Chris@16
|
2032
|
Chris@16
|
2033 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
|
Chris@16
|
2034 //!
|
Chris@16
|
2035 //! <b>Effects</b>: Erases all of the elements.
|
Chris@16
|
2036 //!
|
Chris@16
|
2037 //! <b>Complexity</b>: Linear to the number of elements on the container.
|
Chris@16
|
2038 //! Disposer::operator()(pointer) is called for the removed elements.
|
Chris@16
|
2039 //!
|
Chris@16
|
2040 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2041 //!
|
Chris@16
|
2042 //! <b>Note</b>: Invalidates the iterators (but not the references)
|
Chris@16
|
2043 //! to the erased elements. No destructors are called.
|
Chris@16
|
2044 template<class Disposer>
|
Chris@16
|
2045 void clear_and_dispose(Disposer disposer)
|
Chris@16
|
2046 {
|
Chris@16
|
2047 if(!constant_time_size || !this->empty()){
|
Chris@16
|
2048 size_type num_buckets = this->bucket_count();
|
Chris@16
|
2049 bucket_ptr b = this->priv_bucket_pointer();
|
Chris@16
|
2050 for(; num_buckets--; ++b){
|
Chris@16
|
2051 b->clear_and_dispose(make_node_disposer(disposer));
|
Chris@16
|
2052 }
|
Chris@16
|
2053 this->priv_size_traits().set_size(size_type(0));
|
Chris@16
|
2054 }
|
Chris@16
|
2055 this->priv_initialize_cache();
|
Chris@16
|
2056 }
|
Chris@16
|
2057
|
Chris@16
|
2058 //! <b>Effects</b>: Returns the number of contained elements with the given value
|
Chris@16
|
2059 //!
|
Chris@16
|
2060 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
|
Chris@16
|
2061 //!
|
Chris@16
|
2062 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
|
Chris@16
|
2063 size_type count(const_reference value) const
|
Chris@16
|
2064 { return this->count(value, this->priv_hasher(), this->priv_equal()); }
|
Chris@16
|
2065
|
Chris@16
|
2066 //! <b>Requires</b>: "hash_func" must be a hash function that induces
|
Chris@16
|
2067 //! the same hash values as the stored hasher. The difference is that
|
Chris@16
|
2068 //! "hash_func" hashes the given key instead of the value_type.
|
Chris@16
|
2069 //!
|
Chris@16
|
2070 //! "equal_func" must be a equality function that induces
|
Chris@16
|
2071 //! the same equality as key_equal. The difference is that
|
Chris@16
|
2072 //! "equal_func" compares an arbitrary key with the contained values.
|
Chris@16
|
2073 //!
|
Chris@16
|
2074 //! <b>Effects</b>: Returns the number of contained elements with the given key
|
Chris@16
|
2075 //!
|
Chris@16
|
2076 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
|
Chris@16
|
2077 //!
|
Chris@16
|
2078 //! <b>Throws</b>: If hash_func or equal throw.
|
Chris@16
|
2079 template<class KeyType, class KeyHasher, class KeyValueEqual>
|
Chris@16
|
2080 size_type count(const KeyType &key, const KeyHasher &hash_func, const KeyValueEqual &equal_func) const
|
Chris@16
|
2081 {
|
Chris@16
|
2082 size_type bucket_n1, bucket_n2, cnt;
|
Chris@16
|
2083 this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, cnt);
|
Chris@16
|
2084 return cnt;
|
Chris@16
|
2085 }
|
Chris@16
|
2086
|
Chris@16
|
2087 //! <b>Effects</b>: Finds an iterator to the first element is equal to
|
Chris@16
|
2088 //! "value" or end() if that element does not exist.
|
Chris@16
|
2089 //!
|
Chris@16
|
2090 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
|
Chris@16
|
2091 //!
|
Chris@16
|
2092 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
|
Chris@16
|
2093 iterator find(const_reference value)
|
Chris@16
|
2094 { return this->find(value, this->priv_hasher(), this->priv_equal()); }
|
Chris@16
|
2095
|
Chris@16
|
2096 //! <b>Requires</b>: "hash_func" must be a hash function that induces
|
Chris@16
|
2097 //! the same hash values as the stored hasher. The difference is that
|
Chris@16
|
2098 //! "hash_func" hashes the given key instead of the value_type.
|
Chris@16
|
2099 //!
|
Chris@16
|
2100 //! "equal_func" must be a equality function that induces
|
Chris@16
|
2101 //! the same equality as key_equal. The difference is that
|
Chris@16
|
2102 //! "equal_func" compares an arbitrary key with the contained values.
|
Chris@16
|
2103 //!
|
Chris@16
|
2104 //! <b>Effects</b>: Finds an iterator to the first element whose key is
|
Chris@16
|
2105 //! "key" according to the given hash and equality functor or end() if
|
Chris@16
|
2106 //! that element does not exist.
|
Chris@16
|
2107 //!
|
Chris@16
|
2108 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
|
Chris@16
|
2109 //!
|
Chris@16
|
2110 //! <b>Throws</b>: If hash_func or equal_func throw.
|
Chris@16
|
2111 //!
|
Chris@16
|
2112 //! <b>Note</b>: This function is used when constructing a value_type
|
Chris@16
|
2113 //! is expensive and the value_type can be compared with a cheaper
|
Chris@16
|
2114 //! key type. Usually this key is part of the value_type.
|
Chris@16
|
2115 template<class KeyType, class KeyHasher, class KeyValueEqual>
|
Chris@16
|
2116 iterator find(const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func)
|
Chris@16
|
2117 {
|
Chris@16
|
2118 size_type bucket_n;
|
Chris@16
|
2119 std::size_t hash;
|
Chris@16
|
2120 siterator prev;
|
Chris@16
|
2121 siterator local_it = this->priv_find(key, hash_func, equal_func, bucket_n, hash, prev);
|
Chris@16
|
2122 return iterator(local_it, &this->get_bucket_value_traits());
|
Chris@16
|
2123 }
|
Chris@16
|
2124
|
Chris@16
|
2125 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
|
Chris@16
|
2126 //! "key" or end() if that element does not exist.
|
Chris@16
|
2127 //!
|
Chris@16
|
2128 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
|
Chris@16
|
2129 //!
|
Chris@16
|
2130 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
|
Chris@16
|
2131 const_iterator find(const_reference value) const
|
Chris@16
|
2132 { return this->find(value, this->priv_hasher(), this->priv_equal()); }
|
Chris@16
|
2133
|
Chris@16
|
2134 //! <b>Requires</b>: "hash_func" must be a hash function that induces
|
Chris@16
|
2135 //! the same hash values as the stored hasher. The difference is that
|
Chris@16
|
2136 //! "hash_func" hashes the given key instead of the value_type.
|
Chris@16
|
2137 //!
|
Chris@16
|
2138 //! "equal_func" must be a equality function that induces
|
Chris@16
|
2139 //! the same equality as key_equal. The difference is that
|
Chris@16
|
2140 //! "equal_func" compares an arbitrary key with the contained values.
|
Chris@16
|
2141 //!
|
Chris@16
|
2142 //! <b>Effects</b>: Finds an iterator to the first element whose key is
|
Chris@16
|
2143 //! "key" according to the given hasher and equality functor or end() if
|
Chris@16
|
2144 //! that element does not exist.
|
Chris@16
|
2145 //!
|
Chris@16
|
2146 //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
|
Chris@16
|
2147 //!
|
Chris@16
|
2148 //! <b>Throws</b>: If hash_func or equal_func throw.
|
Chris@16
|
2149 //!
|
Chris@16
|
2150 //! <b>Note</b>: This function is used when constructing a value_type
|
Chris@16
|
2151 //! is expensive and the value_type can be compared with a cheaper
|
Chris@16
|
2152 //! key type. Usually this key is part of the value_type.
|
Chris@16
|
2153 template<class KeyType, class KeyHasher, class KeyValueEqual>
|
Chris@16
|
2154 const_iterator find
|
Chris@16
|
2155 (const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func) const
|
Chris@16
|
2156 {
|
Chris@16
|
2157 size_type bucket_n;
|
Chris@16
|
2158 std::size_t hash_value;
|
Chris@16
|
2159 siterator prev;
|
Chris@16
|
2160 siterator sit = this->priv_find(key, hash_func, equal_func, bucket_n, hash_value, prev);
|
Chris@16
|
2161 return const_iterator(sit, &this->get_bucket_value_traits());
|
Chris@16
|
2162 }
|
Chris@16
|
2163
|
Chris@16
|
2164 //! <b>Effects</b>: Returns a range containing all elements with values equivalent
|
Chris@16
|
2165 //! to value. Returns std::make_pair(this->end(), this->end()) if no such
|
Chris@16
|
2166 //! elements exist.
|
Chris@16
|
2167 //!
|
Chris@16
|
2168 //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
|
Chris@16
|
2169 //!
|
Chris@16
|
2170 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
|
Chris@16
|
2171 std::pair<iterator,iterator> equal_range(const_reference value)
|
Chris@16
|
2172 { return this->equal_range(value, this->priv_hasher(), this->priv_equal()); }
|
Chris@16
|
2173
|
Chris@16
|
2174 //! <b>Requires</b>: "hash_func" must be a hash function that induces
|
Chris@16
|
2175 //! the same hash values as the stored hasher. The difference is that
|
Chris@16
|
2176 //! "hash_func" hashes the given key instead of the value_type.
|
Chris@16
|
2177 //!
|
Chris@16
|
2178 //! "equal_func" must be a equality function that induces
|
Chris@16
|
2179 //! the same equality as key_equal. The difference is that
|
Chris@16
|
2180 //! "equal_func" compares an arbitrary key with the contained values.
|
Chris@16
|
2181 //!
|
Chris@16
|
2182 //! <b>Effects</b>: Returns a range containing all elements with equivalent
|
Chris@16
|
2183 //! keys. Returns std::make_pair(this->end(), this->end()) if no such
|
Chris@16
|
2184 //! elements exist.
|
Chris@16
|
2185 //!
|
Chris@16
|
2186 //! <b>Complexity</b>: Average case O(this->count(key, hash_func, equal_func)).
|
Chris@16
|
2187 //! Worst case O(this->size()).
|
Chris@16
|
2188 //!
|
Chris@16
|
2189 //! <b>Throws</b>: If hash_func or the equal_func throw.
|
Chris@16
|
2190 //!
|
Chris@16
|
2191 //! <b>Note</b>: This function is used when constructing a value_type
|
Chris@16
|
2192 //! is expensive and the value_type can be compared with a cheaper
|
Chris@16
|
2193 //! key type. Usually this key is part of the value_type.
|
Chris@16
|
2194 template<class KeyType, class KeyHasher, class KeyValueEqual>
|
Chris@16
|
2195 std::pair<iterator,iterator> equal_range
|
Chris@16
|
2196 (const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func)
|
Chris@16
|
2197 {
|
Chris@16
|
2198 size_type bucket_n1, bucket_n2, cnt;
|
Chris@16
|
2199 std::pair<siterator, siterator> ret = this->priv_equal_range
|
Chris@16
|
2200 (key, hash_func, equal_func, bucket_n1, bucket_n2, cnt);
|
Chris@16
|
2201 return std::pair<iterator, iterator>
|
Chris@16
|
2202 (iterator(ret.first, &this->get_bucket_value_traits()), iterator(ret.second, &this->get_bucket_value_traits()));
|
Chris@16
|
2203 }
|
Chris@16
|
2204
|
Chris@16
|
2205 //! <b>Effects</b>: Returns a range containing all elements with values equivalent
|
Chris@16
|
2206 //! to value. Returns std::make_pair(this->end(), this->end()) if no such
|
Chris@16
|
2207 //! elements exist.
|
Chris@16
|
2208 //!
|
Chris@16
|
2209 //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
|
Chris@16
|
2210 //!
|
Chris@16
|
2211 //! <b>Throws</b>: If the internal hasher or the equality functor throws.
|
Chris@16
|
2212 std::pair<const_iterator, const_iterator>
|
Chris@16
|
2213 equal_range(const_reference value) const
|
Chris@16
|
2214 { return this->equal_range(value, this->priv_hasher(), this->priv_equal()); }
|
Chris@16
|
2215
|
Chris@16
|
2216 //! <b>Requires</b>: "hash_func" must be a hash function that induces
|
Chris@16
|
2217 //! the same hash values as the stored hasher. The difference is that
|
Chris@16
|
2218 //! "hash_func" hashes the given key instead of the value_type.
|
Chris@16
|
2219 //!
|
Chris@16
|
2220 //! "equal_func" must be a equality function that induces
|
Chris@16
|
2221 //! the same equality as key_equal. The difference is that
|
Chris@16
|
2222 //! "equal_func" compares an arbitrary key with the contained values.
|
Chris@16
|
2223 //!
|
Chris@16
|
2224 //! <b>Effects</b>: Returns a range containing all elements with equivalent
|
Chris@16
|
2225 //! keys. Returns std::make_pair(this->end(), this->end()) if no such
|
Chris@16
|
2226 //! elements exist.
|
Chris@16
|
2227 //!
|
Chris@16
|
2228 //! <b>Complexity</b>: Average case O(this->count(key, hash_func, equal_func)).
|
Chris@16
|
2229 //! Worst case O(this->size()).
|
Chris@16
|
2230 //!
|
Chris@16
|
2231 //! <b>Throws</b>: If the hasher or equal_func throw.
|
Chris@16
|
2232 //!
|
Chris@16
|
2233 //! <b>Note</b>: This function is used when constructing a value_type
|
Chris@16
|
2234 //! is expensive and the value_type can be compared with a cheaper
|
Chris@16
|
2235 //! key type. Usually this key is part of the value_type.
|
Chris@16
|
2236 template<class KeyType, class KeyHasher, class KeyValueEqual>
|
Chris@16
|
2237 std::pair<const_iterator,const_iterator> equal_range
|
Chris@16
|
2238 (const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func) const
|
Chris@16
|
2239 {
|
Chris@16
|
2240 size_type bucket_n1, bucket_n2, cnt;
|
Chris@16
|
2241 std::pair<siterator, siterator> ret =
|
Chris@16
|
2242 this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, cnt);
|
Chris@16
|
2243 return std::pair<const_iterator, const_iterator>
|
Chris@101
|
2244 ( const_iterator(ret.first, &this->get_bucket_value_traits())
|
Chris@101
|
2245 , const_iterator(ret.second, &this->get_bucket_value_traits()));
|
Chris@16
|
2246 }
|
Chris@16
|
2247
|
Chris@16
|
2248 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
|
Chris@16
|
2249 //! appropriate type. Otherwise the behavior is undefined.
|
Chris@16
|
2250 //!
|
Chris@16
|
2251 //! <b>Effects</b>: Returns: a valid iterator belonging to the unordered_set
|
Chris@16
|
2252 //! that points to the value
|
Chris@16
|
2253 //!
|
Chris@16
|
2254 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2255 //!
|
Chris@16
|
2256 //! <b>Throws</b>: If the internal hash function throws.
|
Chris@16
|
2257 iterator iterator_to(reference value)
|
Chris@16
|
2258 {
|
Chris@101
|
2259 return iterator(bucket_type::s_iterator_to
|
Chris@101
|
2260 (this->priv_value_to_node(value)), &this->get_bucket_value_traits());
|
Chris@16
|
2261 }
|
Chris@16
|
2262
|
Chris@16
|
2263 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
|
Chris@16
|
2264 //! appropriate type. Otherwise the behavior is undefined.
|
Chris@16
|
2265 //!
|
Chris@16
|
2266 //! <b>Effects</b>: Returns: a valid const_iterator belonging to the
|
Chris@16
|
2267 //! unordered_set that points to the value
|
Chris@16
|
2268 //!
|
Chris@16
|
2269 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2270 //!
|
Chris@16
|
2271 //! <b>Throws</b>: If the internal hash function throws.
|
Chris@16
|
2272 const_iterator iterator_to(const_reference value) const
|
Chris@16
|
2273 {
|
Chris@101
|
2274 node_reference r = *pointer_traits<node_ptr>::const_cast_from
|
Chris@101
|
2275 (pointer_traits<const_node_ptr>::pointer_to(this->priv_value_to_node(value)));
|
Chris@101
|
2276 siterator sit = bucket_type::s_iterator_to(r);
|
Chris@16
|
2277 return const_iterator(sit, &this->get_bucket_value_traits());
|
Chris@16
|
2278 }
|
Chris@16
|
2279
|
Chris@16
|
2280 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
|
Chris@16
|
2281 //! appropriate type. Otherwise the behavior is undefined.
|
Chris@16
|
2282 //!
|
Chris@16
|
2283 //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_set
|
Chris@16
|
2284 //! that points to the value
|
Chris@16
|
2285 //!
|
Chris@16
|
2286 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2287 //!
|
Chris@16
|
2288 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2289 //!
|
Chris@16
|
2290 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
|
Chris@16
|
2291 //! is stateless.
|
Chris@16
|
2292 static local_iterator s_local_iterator_to(reference value)
|
Chris@16
|
2293 {
|
Chris@16
|
2294 BOOST_STATIC_ASSERT((!stateful_value_traits));
|
Chris@101
|
2295 siterator sit = bucket_type::s_iterator_to(*value_traits::to_node_ptr(value));
|
Chris@101
|
2296 return local_iterator(sit, const_value_traits_ptr());
|
Chris@16
|
2297 }
|
Chris@16
|
2298
|
Chris@16
|
2299 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
|
Chris@16
|
2300 //! appropriate type. Otherwise the behavior is undefined.
|
Chris@16
|
2301 //!
|
Chris@16
|
2302 //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
|
Chris@16
|
2303 //! the unordered_set that points to the value
|
Chris@16
|
2304 //!
|
Chris@16
|
2305 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2306 //!
|
Chris@16
|
2307 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2308 //!
|
Chris@16
|
2309 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
|
Chris@16
|
2310 //! is stateless.
|
Chris@16
|
2311 static const_local_iterator s_local_iterator_to(const_reference value)
|
Chris@16
|
2312 {
|
Chris@16
|
2313 BOOST_STATIC_ASSERT((!stateful_value_traits));
|
Chris@101
|
2314 node_reference r = *pointer_traits<node_ptr>::const_cast_from
|
Chris@101
|
2315 (value_traits::to_node_ptr(value));
|
Chris@101
|
2316 siterator sit = bucket_type::s_iterator_to(r);
|
Chris@101
|
2317 return const_local_iterator(sit, const_value_traits_ptr());
|
Chris@16
|
2318 }
|
Chris@16
|
2319
|
Chris@16
|
2320 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
|
Chris@16
|
2321 //! appropriate type. Otherwise the behavior is undefined.
|
Chris@16
|
2322 //!
|
Chris@16
|
2323 //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_set
|
Chris@16
|
2324 //! that points to the value
|
Chris@16
|
2325 //!
|
Chris@16
|
2326 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2327 //!
|
Chris@16
|
2328 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2329 local_iterator local_iterator_to(reference value)
|
Chris@16
|
2330 {
|
Chris@16
|
2331 siterator sit = bucket_type::s_iterator_to(this->priv_value_to_node(value));
|
Chris@101
|
2332 return local_iterator(sit, this->priv_value_traits_ptr());
|
Chris@16
|
2333 }
|
Chris@16
|
2334
|
Chris@16
|
2335 //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
|
Chris@16
|
2336 //! appropriate type. Otherwise the behavior is undefined.
|
Chris@16
|
2337 //!
|
Chris@16
|
2338 //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
|
Chris@16
|
2339 //! the unordered_set that points to the value
|
Chris@16
|
2340 //!
|
Chris@16
|
2341 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2342 //!
|
Chris@16
|
2343 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2344 const_local_iterator local_iterator_to(const_reference value) const
|
Chris@16
|
2345 {
|
Chris@101
|
2346 node_reference r = *pointer_traits<node_ptr>::const_cast_from
|
Chris@101
|
2347 (pointer_traits<const_node_ptr>::pointer_to(this->priv_value_to_node(value)));
|
Chris@101
|
2348 siterator sit = bucket_type::s_iterator_to(r);
|
Chris@101
|
2349 return const_local_iterator(sit, this->priv_value_traits_ptr());
|
Chris@16
|
2350 }
|
Chris@16
|
2351
|
Chris@16
|
2352 //! <b>Effects</b>: Returns the number of buckets passed in the constructor
|
Chris@16
|
2353 //! or the last rehash function.
|
Chris@16
|
2354 //!
|
Chris@16
|
2355 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2356 //!
|
Chris@16
|
2357 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2358 size_type bucket_count() const
|
Chris@16
|
2359 { return this->priv_bucket_count(); }
|
Chris@16
|
2360
|
Chris@16
|
2361 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
|
Chris@16
|
2362 //!
|
Chris@16
|
2363 //! <b>Effects</b>: Returns the number of elements in the nth bucket.
|
Chris@16
|
2364 //!
|
Chris@16
|
2365 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2366 //!
|
Chris@16
|
2367 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2368 size_type bucket_size(size_type n) const
|
Chris@16
|
2369 { return this->priv_bucket_pointer()[n].size(); }
|
Chris@16
|
2370
|
Chris@16
|
2371 //! <b>Effects</b>: Returns the index of the bucket in which elements
|
Chris@16
|
2372 //! with keys equivalent to k would be found, if any such element existed.
|
Chris@16
|
2373 //!
|
Chris@16
|
2374 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2375 //!
|
Chris@16
|
2376 //! <b>Throws</b>: If the hash functor throws.
|
Chris@16
|
2377 //!
|
Chris@16
|
2378 //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
|
Chris@16
|
2379 size_type bucket(const key_type& k) const
|
Chris@16
|
2380 { return this->bucket(k, this->priv_hasher()); }
|
Chris@16
|
2381
|
Chris@16
|
2382 //! <b>Requires</b>: "hash_func" must be a hash function that induces
|
Chris@16
|
2383 //! the same hash values as the stored hasher. The difference is that
|
Chris@16
|
2384 //! "hash_func" hashes the given key instead of the value_type.
|
Chris@16
|
2385 //!
|
Chris@16
|
2386 //! <b>Effects</b>: Returns the index of the bucket in which elements
|
Chris@16
|
2387 //! with keys equivalent to k would be found, if any such element existed.
|
Chris@16
|
2388 //!
|
Chris@16
|
2389 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2390 //!
|
Chris@16
|
2391 //! <b>Throws</b>: If hash_func throws.
|
Chris@16
|
2392 //!
|
Chris@16
|
2393 //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
|
Chris@16
|
2394 template<class KeyType, class KeyHasher>
|
Chris@16
|
2395 size_type bucket(const KeyType& k, const KeyHasher &hash_func) const
|
Chris@16
|
2396 { return this->priv_hash_to_bucket(hash_func(k)); }
|
Chris@16
|
2397
|
Chris@16
|
2398 //! <b>Effects</b>: Returns the bucket array pointer passed in the constructor
|
Chris@16
|
2399 //! or the last rehash function.
|
Chris@16
|
2400 //!
|
Chris@16
|
2401 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2402 //!
|
Chris@16
|
2403 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2404 bucket_ptr bucket_pointer() const
|
Chris@16
|
2405 { return this->priv_bucket_pointer(); }
|
Chris@16
|
2406
|
Chris@16
|
2407 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
|
Chris@16
|
2408 //!
|
Chris@16
|
2409 //! <b>Effects</b>: Returns a local_iterator pointing to the beginning
|
Chris@16
|
2410 //! of the sequence stored in the bucket n.
|
Chris@16
|
2411 //!
|
Chris@16
|
2412 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2413 //!
|
Chris@16
|
2414 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2415 //!
|
Chris@16
|
2416 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
|
Chris@16
|
2417 //! containing all of the elements in the nth bucket.
|
Chris@16
|
2418 local_iterator begin(size_type n)
|
Chris@101
|
2419 { return local_iterator(this->priv_bucket_pointer()[n].begin(), this->priv_value_traits_ptr()); }
|
Chris@16
|
2420
|
Chris@16
|
2421 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
|
Chris@16
|
2422 //!
|
Chris@16
|
2423 //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
|
Chris@16
|
2424 //! of the sequence stored in the bucket n.
|
Chris@16
|
2425 //!
|
Chris@16
|
2426 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2427 //!
|
Chris@16
|
2428 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2429 //!
|
Chris@16
|
2430 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
|
Chris@16
|
2431 //! containing all of the elements in the nth bucket.
|
Chris@16
|
2432 const_local_iterator begin(size_type n) const
|
Chris@16
|
2433 { return this->cbegin(n); }
|
Chris@16
|
2434
|
Chris@16
|
2435 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
|
Chris@16
|
2436 //!
|
Chris@16
|
2437 //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
|
Chris@16
|
2438 //! of the sequence stored in the bucket n.
|
Chris@16
|
2439 //!
|
Chris@16
|
2440 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2441 //!
|
Chris@16
|
2442 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2443 //!
|
Chris@16
|
2444 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
|
Chris@16
|
2445 //! containing all of the elements in the nth bucket.
|
Chris@16
|
2446 const_local_iterator cbegin(size_type n) const
|
Chris@16
|
2447 {
|
Chris@101
|
2448 bucket_reference br = pointer_traits<bucket_ptr>::const_cast_from(this->priv_bucket_pointer())[n];
|
Chris@101
|
2449 return const_local_iterator(br.begin(), this->priv_value_traits_ptr());
|
Chris@16
|
2450 }
|
Chris@16
|
2451
|
Chris@16
|
2452 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
|
Chris@16
|
2453 //!
|
Chris@16
|
2454 //! <b>Effects</b>: Returns a local_iterator pointing to the end
|
Chris@16
|
2455 //! of the sequence stored in the bucket n.
|
Chris@16
|
2456 //!
|
Chris@16
|
2457 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2458 //!
|
Chris@16
|
2459 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2460 //!
|
Chris@16
|
2461 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
|
Chris@16
|
2462 //! containing all of the elements in the nth bucket.
|
Chris@16
|
2463 local_iterator end(size_type n)
|
Chris@101
|
2464 { return local_iterator(this->priv_bucket_pointer()[n].end(), this->priv_value_traits_ptr()); }
|
Chris@16
|
2465
|
Chris@16
|
2466 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
|
Chris@16
|
2467 //!
|
Chris@16
|
2468 //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
|
Chris@16
|
2469 //! of the sequence stored in the bucket n.
|
Chris@16
|
2470 //!
|
Chris@16
|
2471 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2472 //!
|
Chris@16
|
2473 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2474 //!
|
Chris@16
|
2475 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
|
Chris@16
|
2476 //! containing all of the elements in the nth bucket.
|
Chris@16
|
2477 const_local_iterator end(size_type n) const
|
Chris@16
|
2478 { return this->cend(n); }
|
Chris@16
|
2479
|
Chris@16
|
2480 //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
|
Chris@16
|
2481 //!
|
Chris@16
|
2482 //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
|
Chris@16
|
2483 //! of the sequence stored in the bucket n.
|
Chris@16
|
2484 //!
|
Chris@16
|
2485 //! <b>Complexity</b>: Constant.
|
Chris@16
|
2486 //!
|
Chris@16
|
2487 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2488 //!
|
Chris@16
|
2489 //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
|
Chris@16
|
2490 //! containing all of the elements in the nth bucket.
|
Chris@16
|
2491 const_local_iterator cend(size_type n) const
|
Chris@16
|
2492 {
|
Chris@101
|
2493 bucket_reference br = pointer_traits<bucket_ptr>::const_cast_from(this->priv_bucket_pointer())[n];
|
Chris@101
|
2494 return const_local_iterator ( br.end(), this->priv_value_traits_ptr());
|
Chris@16
|
2495 }
|
Chris@16
|
2496
|
Chris@16
|
2497 //! <b>Requires</b>: new_bucket_traits can hold a pointer to a new bucket array
|
Chris@16
|
2498 //! or the same as the old bucket array with a different length. new_size is the length of the
|
Chris@16
|
2499 //! the array pointed by new_buckets. If new_bucket_traits.bucket_begin() == this->bucket_pointer()
|
Chris@16
|
2500 //! new_bucket_traits.bucket_count() can be bigger or smaller than this->bucket_count().
|
Chris@16
|
2501 //! 'new_bucket_traits' copy constructor should not throw.
|
Chris@16
|
2502 //!
|
Chris@16
|
2503 //! <b>Effects</b>: Updates the internal reference with the new bucket, erases
|
Chris@16
|
2504 //! the values from the old bucket and inserts then in the new one.
|
Chris@16
|
2505 //! Bucket traits hold by *this is assigned from new_bucket_traits.
|
Chris@16
|
2506 //! If the container is configured as incremental<>, the split bucket is set
|
Chris@16
|
2507 //! to the new bucket_count().
|
Chris@16
|
2508 //!
|
Chris@16
|
2509 //! If store_hash option is true, this method does not use the hash function.
|
Chris@16
|
2510 //!
|
Chris@16
|
2511 //! <b>Complexity</b>: Average case linear in this->size(), worst case quadratic.
|
Chris@16
|
2512 //!
|
Chris@16
|
2513 //! <b>Throws</b>: If the hasher functor throws. Basic guarantee.
|
Chris@16
|
2514 void rehash(const bucket_traits &new_bucket_traits)
|
Chris@16
|
2515 {
|
Chris@16
|
2516 const bucket_ptr new_buckets = new_bucket_traits.bucket_begin();
|
Chris@16
|
2517 size_type new_bucket_count = new_bucket_traits.bucket_count();
|
Chris@16
|
2518 const bucket_ptr old_buckets = this->priv_bucket_pointer();
|
Chris@16
|
2519 size_type old_bucket_count = this->priv_bucket_count();
|
Chris@16
|
2520
|
Chris@16
|
2521 //Check power of two bucket array if the option is activated
|
Chris@16
|
2522 BOOST_INTRUSIVE_INVARIANT_ASSERT
|
Chris@16
|
2523 (!power_2_buckets || (0 == (new_bucket_count & (new_bucket_count-1u))));
|
Chris@16
|
2524
|
Chris@16
|
2525 size_type n = this->priv_get_cache_bucket_num();
|
Chris@16
|
2526 const bool same_buffer = old_buckets == new_buckets;
|
Chris@16
|
2527 //If the new bucket length is a common factor
|
Chris@16
|
2528 //of the old one we can avoid hash calculations.
|
Chris@16
|
2529 const bool fast_shrink = (!incremental) && (old_bucket_count > new_bucket_count) &&
|
Chris@16
|
2530 (power_2_buckets ||(old_bucket_count % new_bucket_count) == 0);
|
Chris@16
|
2531 //If we are shrinking the same bucket array and it's
|
Chris@16
|
2532 //is a fast shrink, just rehash the last nodes
|
Chris@16
|
2533 size_type new_first_bucket_num = new_bucket_count;
|
Chris@16
|
2534 if(same_buffer && fast_shrink && (n < new_bucket_count)){
|
Chris@16
|
2535 n = new_bucket_count;
|
Chris@16
|
2536 new_first_bucket_num = this->priv_get_cache_bucket_num();
|
Chris@16
|
2537 }
|
Chris@16
|
2538
|
Chris@16
|
2539 //Anti-exception stuff: they destroy the elements if something goes wrong.
|
Chris@16
|
2540 //If the source and destination buckets are the same, the second rollback function
|
Chris@16
|
2541 //is harmless, because all elements have been already unlinked and destroyed
|
Chris@16
|
2542 typedef detail::init_disposer<node_algorithms> NodeDisposer;
|
Chris@16
|
2543 NodeDisposer node_disp;
|
Chris@16
|
2544 bucket_type & newbuck = new_buckets[0];
|
Chris@16
|
2545 bucket_type & oldbuck = old_buckets[0];
|
Chris@16
|
2546 detail::exception_array_disposer<bucket_type, NodeDisposer, size_type>
|
Chris@16
|
2547 rollback1(newbuck, node_disp, new_bucket_count);
|
Chris@16
|
2548 detail::exception_array_disposer<bucket_type, NodeDisposer, size_type>
|
Chris@16
|
2549 rollback2(oldbuck, node_disp, old_bucket_count);
|
Chris@16
|
2550
|
Chris@16
|
2551 //Put size in a safe value for rollback exception
|
Chris@16
|
2552 size_type size_backup = this->priv_size_traits().get_size();
|
Chris@16
|
2553 this->priv_size_traits().set_size(0);
|
Chris@16
|
2554 //Put cache to safe position
|
Chris@16
|
2555 this->priv_initialize_cache();
|
Chris@16
|
2556 this->priv_insertion_update_cache(size_type(0u));
|
Chris@16
|
2557
|
Chris@16
|
2558 //Iterate through nodes
|
Chris@16
|
2559 for(; n < old_bucket_count; ++n){
|
Chris@16
|
2560 bucket_type &old_bucket = old_buckets[n];
|
Chris@16
|
2561
|
Chris@16
|
2562 if(!fast_shrink){
|
Chris@16
|
2563 siterator before_i(old_bucket.before_begin());
|
Chris@16
|
2564 siterator end_sit(old_bucket.end());
|
Chris@16
|
2565 siterator i(old_bucket.begin());
|
Chris@16
|
2566 for(;i != end_sit; ++i){
|
Chris@16
|
2567 const value_type &v = this->priv_value_from_slist_node(i.pointed_node());
|
Chris@16
|
2568 const std::size_t hash_value = this->priv_stored_or_compute_hash(v, store_hash_t());
|
Chris@16
|
2569 const size_type new_n = detail::hash_to_bucket_split<power_2_buckets, incremental>(hash_value, new_bucket_count, new_bucket_count);
|
Chris@16
|
2570 if(cache_begin && new_n < new_first_bucket_num)
|
Chris@16
|
2571 new_first_bucket_num = new_n;
|
Chris@16
|
2572 siterator last = bucket_type::s_iterator_to
|
Chris@16
|
2573 (*group_functions_t::get_last_in_group
|
Chris@16
|
2574 (detail::dcast_bucket_ptr<node>(i.pointed_node()), optimize_multikey_t()));
|
Chris@16
|
2575 if(same_buffer && new_n == n){
|
Chris@16
|
2576 before_i = last;
|
Chris@16
|
2577 }
|
Chris@16
|
2578 else{
|
Chris@16
|
2579 bucket_type &new_b = new_buckets[new_n];
|
Chris@16
|
2580 new_b.splice_after(new_b.before_begin(), old_bucket, before_i, last);
|
Chris@16
|
2581 }
|
Chris@16
|
2582 i = before_i;
|
Chris@16
|
2583 }
|
Chris@16
|
2584 }
|
Chris@16
|
2585 else{
|
Chris@16
|
2586 const size_type new_n = detail::hash_to_bucket_split<power_2_buckets, incremental>(n, new_bucket_count, new_bucket_count);
|
Chris@16
|
2587 if(cache_begin && new_n < new_first_bucket_num)
|
Chris@16
|
2588 new_first_bucket_num = new_n;
|
Chris@16
|
2589 bucket_type &new_b = new_buckets[new_n];
|
Chris@16
|
2590 if(!old_bucket.empty()){
|
Chris@16
|
2591 new_b.splice_after( new_b.before_begin()
|
Chris@16
|
2592 , old_bucket
|
Chris@16
|
2593 , old_bucket.before_begin()
|
Chris@16
|
2594 , hashtable_impl::priv_get_last(old_bucket));
|
Chris@16
|
2595 }
|
Chris@16
|
2596 }
|
Chris@16
|
2597 }
|
Chris@16
|
2598
|
Chris@16
|
2599 this->priv_size_traits().set_size(size_backup);
|
Chris@16
|
2600 this->priv_split_traits().set_size(new_bucket_count);
|
Chris@101
|
2601 this->priv_bucket_traits() = new_bucket_traits;
|
Chris@16
|
2602 this->priv_initialize_cache();
|
Chris@16
|
2603 this->priv_insertion_update_cache(new_first_bucket_num);
|
Chris@16
|
2604 rollback1.release();
|
Chris@16
|
2605 rollback2.release();
|
Chris@16
|
2606 }
|
Chris@16
|
2607
|
Chris@16
|
2608 //! <b>Requires</b>:
|
Chris@16
|
2609 //!
|
Chris@16
|
2610 //! <b>Effects</b>:
|
Chris@16
|
2611 //!
|
Chris@16
|
2612 //! <b>Complexity</b>:
|
Chris@16
|
2613 //!
|
Chris@16
|
2614 //! <b>Throws</b>:
|
Chris@16
|
2615 //!
|
Chris@16
|
2616 //! <b>Note</b>: this method is only available if incremental<true> option is activated.
|
Chris@16
|
2617 bool incremental_rehash(bool grow = true)
|
Chris@16
|
2618 {
|
Chris@16
|
2619 //This function is only available for containers with incremental hashing
|
Chris@16
|
2620 BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
|
Chris@16
|
2621 const size_type split_idx = this->priv_split_traits().get_size();
|
Chris@16
|
2622 const size_type bucket_cnt = this->priv_bucket_count();
|
Chris@16
|
2623 const bucket_ptr buck_ptr = this->priv_bucket_pointer();
|
Chris@16
|
2624
|
Chris@16
|
2625 if(grow){
|
Chris@16
|
2626 //Test if the split variable can be changed
|
Chris@16
|
2627 if(split_idx >= bucket_cnt)
|
Chris@16
|
2628 return false;
|
Chris@16
|
2629
|
Chris@16
|
2630 const size_type bucket_to_rehash = split_idx - bucket_cnt/2;
|
Chris@16
|
2631 bucket_type &old_bucket = buck_ptr[bucket_to_rehash];
|
Chris@16
|
2632 siterator before_i(old_bucket.before_begin());
|
Chris@16
|
2633 const siterator end_sit(old_bucket.end());
|
Chris@16
|
2634 siterator i(old_bucket.begin());
|
Chris@16
|
2635 this->priv_split_traits().increment();
|
Chris@16
|
2636
|
Chris@16
|
2637 //Anti-exception stuff: if an exception is thrown while
|
Chris@16
|
2638 //moving elements from old_bucket to the target bucket, all moved
|
Chris@16
|
2639 //elements are moved back to the original one.
|
Chris@16
|
2640 detail::incremental_rehash_rollback<bucket_type, split_traits> rollback
|
Chris@16
|
2641 ( buck_ptr[split_idx], old_bucket, this->priv_split_traits());
|
Chris@16
|
2642 for(;i != end_sit; ++i){
|
Chris@16
|
2643 const value_type &v = this->priv_value_from_slist_node(i.pointed_node());
|
Chris@16
|
2644 const std::size_t hash_value = this->priv_stored_or_compute_hash(v, store_hash_t());
|
Chris@16
|
2645 const size_type new_n = this->priv_hash_to_bucket(hash_value);
|
Chris@16
|
2646 siterator last = bucket_type::s_iterator_to
|
Chris@16
|
2647 (*group_functions_t::get_last_in_group
|
Chris@16
|
2648 (detail::dcast_bucket_ptr<node>(i.pointed_node()), optimize_multikey_t()));
|
Chris@16
|
2649 if(new_n == bucket_to_rehash){
|
Chris@16
|
2650 before_i = last;
|
Chris@16
|
2651 }
|
Chris@16
|
2652 else{
|
Chris@16
|
2653 bucket_type &new_b = buck_ptr[new_n];
|
Chris@16
|
2654 new_b.splice_after(new_b.before_begin(), old_bucket, before_i, last);
|
Chris@16
|
2655 }
|
Chris@16
|
2656 i = before_i;
|
Chris@16
|
2657 }
|
Chris@16
|
2658 rollback.release();
|
Chris@16
|
2659 this->priv_erasure_update_cache();
|
Chris@16
|
2660 return true;
|
Chris@16
|
2661 }
|
Chris@16
|
2662 else{
|
Chris@16
|
2663 //Test if the split variable can be changed
|
Chris@16
|
2664 if(split_idx <= bucket_cnt/2)
|
Chris@16
|
2665 return false;
|
Chris@16
|
2666 const size_type target_bucket_num = split_idx - 1 - bucket_cnt/2;
|
Chris@16
|
2667 bucket_type &target_bucket = buck_ptr[target_bucket_num];
|
Chris@16
|
2668 bucket_type &source_bucket = buck_ptr[split_idx-1];
|
Chris@16
|
2669 target_bucket.splice_after(target_bucket.cbefore_begin(), source_bucket);
|
Chris@16
|
2670 this->priv_split_traits().decrement();
|
Chris@16
|
2671 this->priv_insertion_update_cache(target_bucket_num);
|
Chris@16
|
2672 return true;
|
Chris@16
|
2673 }
|
Chris@16
|
2674 }
|
Chris@16
|
2675
|
Chris@16
|
2676 //! <b>Effects</b>: If new_bucket_traits.bucket_count() is not
|
Chris@16
|
2677 //! this->bucket_count()/2 or this->bucket_count()*2, or
|
Chris@16
|
2678 //! this->split_bucket() != new_bucket_traits.bucket_count() returns false
|
Chris@16
|
2679 //! and does nothing.
|
Chris@16
|
2680 //!
|
Chris@16
|
2681 //! Otherwise, copy assigns new_bucket_traits to the internal bucket_traits
|
Chris@16
|
2682 //! and transfers all the objects from old buckets to the new ones.
|
Chris@16
|
2683 //!
|
Chris@16
|
2684 //! <b>Complexity</b>: Linear to size().
|
Chris@16
|
2685 //!
|
Chris@16
|
2686 //! <b>Throws</b>: Nothing
|
Chris@16
|
2687 //!
|
Chris@16
|
2688 //! <b>Note</b>: this method is only available if incremental<true> option is activated.
|
Chris@16
|
2689 bool incremental_rehash(const bucket_traits &new_bucket_traits)
|
Chris@16
|
2690 {
|
Chris@16
|
2691 //This function is only available for containers with incremental hashing
|
Chris@16
|
2692 BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
|
Chris@16
|
2693 size_type new_bucket_traits_size = new_bucket_traits.bucket_count();
|
Chris@16
|
2694 size_type cur_bucket_traits = this->priv_bucket_count();
|
Chris@16
|
2695 if(new_bucket_traits_size/2 != cur_bucket_traits && new_bucket_traits_size != cur_bucket_traits/2){
|
Chris@16
|
2696 return false;
|
Chris@16
|
2697 }
|
Chris@16
|
2698
|
Chris@16
|
2699 const size_type split_idx = this->split_count();
|
Chris@16
|
2700
|
Chris@16
|
2701 if(new_bucket_traits_size/2 == cur_bucket_traits){
|
Chris@16
|
2702 //Test if the split variable can be changed
|
Chris@16
|
2703 if(!(split_idx >= cur_bucket_traits))
|
Chris@16
|
2704 return false;
|
Chris@16
|
2705 }
|
Chris@16
|
2706 else{
|
Chris@16
|
2707 //Test if the split variable can be changed
|
Chris@16
|
2708 if(!(split_idx <= cur_bucket_traits/2))
|
Chris@16
|
2709 return false;
|
Chris@16
|
2710 }
|
Chris@16
|
2711
|
Chris@16
|
2712 const size_type ini_n = this->priv_get_cache_bucket_num();
|
Chris@16
|
2713 const bucket_ptr old_buckets = this->priv_bucket_pointer();
|
Chris@101
|
2714 this->priv_bucket_traits() = new_bucket_traits;
|
Chris@16
|
2715 if(new_bucket_traits.bucket_begin() != old_buckets){
|
Chris@16
|
2716 for(size_type n = ini_n; n < split_idx; ++n){
|
Chris@16
|
2717 bucket_type &new_bucket = new_bucket_traits.bucket_begin()[n];
|
Chris@16
|
2718 bucket_type &old_bucket = old_buckets[n];
|
Chris@16
|
2719 new_bucket.splice_after(new_bucket.cbefore_begin(), old_bucket);
|
Chris@16
|
2720 }
|
Chris@16
|
2721 //Put cache to safe position
|
Chris@16
|
2722 this->priv_initialize_cache();
|
Chris@16
|
2723 this->priv_insertion_update_cache(ini_n);
|
Chris@16
|
2724 }
|
Chris@16
|
2725 return true;
|
Chris@16
|
2726 }
|
Chris@16
|
2727
|
Chris@16
|
2728 //! <b>Requires</b>:
|
Chris@16
|
2729 //!
|
Chris@16
|
2730 //! <b>Effects</b>:
|
Chris@16
|
2731 //!
|
Chris@16
|
2732 //! <b>Complexity</b>:
|
Chris@16
|
2733 //!
|
Chris@16
|
2734 //! <b>Throws</b>:
|
Chris@16
|
2735 size_type split_count() const
|
Chris@16
|
2736 {
|
Chris@16
|
2737 //This function is only available if incremental hashing is activated
|
Chris@16
|
2738 BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
|
Chris@16
|
2739 return this->priv_split_traits().get_size();
|
Chris@16
|
2740 }
|
Chris@16
|
2741
|
Chris@16
|
2742 //! <b>Effects</b>: Returns the nearest new bucket count optimized for
|
Chris@16
|
2743 //! the container that is bigger or equal than n. This suggestion can be
|
Chris@16
|
2744 //! used to create bucket arrays with a size that will usually improve
|
Chris@16
|
2745 //! container's performance. If such value does not exist, the
|
Chris@16
|
2746 //! higher possible value is returned.
|
Chris@16
|
2747 //!
|
Chris@16
|
2748 //! <b>Complexity</b>: Amortized constant time.
|
Chris@16
|
2749 //!
|
Chris@16
|
2750 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2751 static size_type suggested_upper_bucket_count(size_type n)
|
Chris@16
|
2752 {
|
Chris@101
|
2753 const std::size_t *primes = &prime_list_holder<0>::prime_list[0];
|
Chris@101
|
2754 const std::size_t *primes_end = primes + prime_list_holder<0>::prime_list_size;
|
Chris@16
|
2755 std::size_t const* bound = std::lower_bound(primes, primes_end, n);
|
Chris@101
|
2756 bound -= (bound == primes_end);
|
Chris@16
|
2757 return size_type(*bound);
|
Chris@16
|
2758 }
|
Chris@16
|
2759
|
Chris@16
|
2760 //! <b>Effects</b>: Returns the nearest new bucket count optimized for
|
Chris@16
|
2761 //! the container that is smaller or equal than n. This suggestion can be
|
Chris@16
|
2762 //! used to create bucket arrays with a size that will usually improve
|
Chris@16
|
2763 //! container's performance. If such value does not exist, the
|
Chris@16
|
2764 //! lowest possible value is returned.
|
Chris@16
|
2765 //!
|
Chris@16
|
2766 //! <b>Complexity</b>: Amortized constant time.
|
Chris@16
|
2767 //!
|
Chris@16
|
2768 //! <b>Throws</b>: Nothing.
|
Chris@16
|
2769 static size_type suggested_lower_bucket_count(size_type n)
|
Chris@16
|
2770 {
|
Chris@101
|
2771 const std::size_t *primes = &prime_list_holder<0>::prime_list[0];
|
Chris@101
|
2772 const std::size_t *primes_end = primes + prime_list_holder<0>::prime_list_size;
|
Chris@16
|
2773 size_type const* bound = std::upper_bound(primes, primes_end, n);
|
Chris@101
|
2774 bound -= (bound != primes);
|
Chris@16
|
2775 return size_type(*bound);
|
Chris@16
|
2776 }
|
Chris@16
|
2777 /// @cond
|
Chris@101
|
2778 void check() const {}
|
Chris@16
|
2779 private:
|
Chris@101
|
2780 size_traits &priv_size_traits()
|
Chris@101
|
2781 { return static_cast<size_traits&>(static_cast<data_type&>(*this)); }
|
Chris@101
|
2782
|
Chris@101
|
2783 const size_traits &priv_size_traits() const
|
Chris@101
|
2784 { return static_cast<const size_traits&>(static_cast<const data_type&>(*this)); }
|
Chris@101
|
2785
|
Chris@101
|
2786 bucket_ptr priv_bucket_pointer() const
|
Chris@101
|
2787 { return this->data_type::internal.internal.internal.internal.priv_bucket_pointer(); }
|
Chris@101
|
2788
|
Chris@101
|
2789 SizeType priv_bucket_count() const
|
Chris@101
|
2790 { return this->data_type::internal.internal.internal.internal.priv_bucket_count(); }
|
Chris@101
|
2791
|
Chris@101
|
2792 const bucket_plus_vtraits<ValueTraits, BucketTraits> &get_bucket_value_traits() const
|
Chris@101
|
2793 { return this->data_type::internal.internal.internal.internal.get_bucket_value_traits(); }
|
Chris@101
|
2794
|
Chris@101
|
2795 bucket_plus_vtraits<ValueTraits, BucketTraits> &get_bucket_value_traits()
|
Chris@101
|
2796 { return this->data_type::internal.internal.internal.internal.get_bucket_value_traits(); }
|
Chris@101
|
2797
|
Chris@101
|
2798 bucket_traits &priv_bucket_traits()
|
Chris@101
|
2799 { return this->data_type::internal.internal.internal.internal.priv_bucket_traits(); }
|
Chris@101
|
2800
|
Chris@101
|
2801 const bucket_traits &priv_bucket_traits() const
|
Chris@101
|
2802 { return this->data_type::internal.internal.internal.internal.priv_bucket_traits(); }
|
Chris@101
|
2803
|
Chris@101
|
2804 value_traits &priv_value_traits()
|
Chris@101
|
2805 { return this->data_type::internal.internal.internal.internal.priv_value_traits(); }
|
Chris@101
|
2806
|
Chris@101
|
2807 const value_traits &priv_value_traits() const
|
Chris@101
|
2808 { return this->data_type::internal.internal.internal.internal.priv_value_traits(); }
|
Chris@101
|
2809
|
Chris@101
|
2810 const_value_traits_ptr priv_value_traits_ptr() const
|
Chris@101
|
2811 { return this->data_type::internal.internal.internal.internal.priv_value_traits_ptr(); }
|
Chris@101
|
2812
|
Chris@101
|
2813 siterator priv_invalid_local_it() const
|
Chris@101
|
2814 { return this->data_type::internal.internal.internal.internal.priv_invalid_local_it(); }
|
Chris@101
|
2815
|
Chris@101
|
2816 split_traits &priv_split_traits()
|
Chris@101
|
2817 { return this->data_type::internal.priv_split_traits(); }
|
Chris@101
|
2818
|
Chris@101
|
2819 const split_traits &priv_split_traits() const
|
Chris@101
|
2820 { return this->data_type::internal.priv_split_traits(); }
|
Chris@101
|
2821
|
Chris@101
|
2822 bucket_ptr priv_get_cache()
|
Chris@101
|
2823 { return this->data_type::internal.internal.priv_get_cache(); }
|
Chris@101
|
2824
|
Chris@101
|
2825 void priv_initialize_cache()
|
Chris@101
|
2826 { return this->data_type::internal.internal.priv_initialize_cache(); }
|
Chris@101
|
2827
|
Chris@101
|
2828 siterator priv_begin() const
|
Chris@101
|
2829 { return this->data_type::internal.internal.priv_begin(); }
|
Chris@101
|
2830
|
Chris@101
|
2831 const value_equal &priv_equal() const
|
Chris@101
|
2832 { return this->data_type::internal.internal.priv_equal(); }
|
Chris@101
|
2833
|
Chris@101
|
2834 value_equal &priv_equal()
|
Chris@101
|
2835 { return this->data_type::internal.internal.priv_equal(); }
|
Chris@101
|
2836
|
Chris@101
|
2837 const hasher &priv_hasher() const
|
Chris@101
|
2838 { return this->data_type::internal.internal.internal.priv_hasher(); }
|
Chris@101
|
2839
|
Chris@101
|
2840 hasher &priv_hasher()
|
Chris@101
|
2841 { return this->data_type::internal.internal.internal.priv_hasher(); }
|
Chris@101
|
2842
|
Chris@101
|
2843 void priv_swap_cache(hashtable_impl &h)
|
Chris@101
|
2844 { this->data_type::internal.internal.priv_swap_cache(h.data_type::internal.internal); }
|
Chris@101
|
2845
|
Chris@101
|
2846 node &priv_value_to_node(value_type &v)
|
Chris@101
|
2847 { return this->data_type::internal.internal.internal.internal.priv_value_to_node(v); }
|
Chris@101
|
2848
|
Chris@101
|
2849 const node &priv_value_to_node(const value_type &v) const
|
Chris@101
|
2850 { return this->data_type::internal.internal.internal.internal.priv_value_to_node(v); }
|
Chris@101
|
2851
|
Chris@101
|
2852 SizeType priv_get_cache_bucket_num()
|
Chris@101
|
2853 { return this->data_type::internal.internal.priv_get_cache_bucket_num(); }
|
Chris@101
|
2854
|
Chris@101
|
2855 void priv_insertion_update_cache(SizeType n)
|
Chris@101
|
2856 { return this->data_type::internal.internal.priv_insertion_update_cache(n); }
|
Chris@101
|
2857
|
Chris@101
|
2858 template<bool Boolean>
|
Chris@101
|
2859 std::size_t priv_stored_or_compute_hash(const value_type &v, detail::bool_<Boolean> b) const
|
Chris@101
|
2860 { return this->data_type::internal.internal.internal.priv_stored_or_compute_hash(v, b); }
|
Chris@101
|
2861
|
Chris@101
|
2862 value_type &priv_value_from_slist_node(slist_node_ptr n)
|
Chris@101
|
2863 { return this->data_type::internal.internal.internal.internal.priv_value_from_slist_node(n); }
|
Chris@101
|
2864
|
Chris@101
|
2865 const value_type &priv_value_from_slist_node(slist_node_ptr n) const
|
Chris@101
|
2866 { return this->data_type::internal.internal.internal.internal.priv_value_from_slist_node(n); }
|
Chris@101
|
2867
|
Chris@101
|
2868 void priv_erasure_update_cache_range(SizeType first_bucket_num, SizeType last_bucket_num)
|
Chris@101
|
2869 { return this->data_type::internal.internal.priv_erasure_update_cache_range(first_bucket_num, last_bucket_num); }
|
Chris@101
|
2870
|
Chris@101
|
2871 void priv_erasure_update_cache()
|
Chris@101
|
2872 { return this->data_type::internal.internal.priv_erasure_update_cache(); }
|
Chris@101
|
2873
|
Chris@101
|
2874 static std::size_t priv_stored_hash(slist_node_ptr n, detail::true_ true_value)
|
Chris@101
|
2875 { return bucket_plus_vtraits<ValueTraits, BucketTraits>::priv_stored_hash(n, true_value); }
|
Chris@101
|
2876
|
Chris@101
|
2877 static std::size_t priv_stored_hash(slist_node_ptr n, detail::false_ false_value)
|
Chris@101
|
2878 { return bucket_plus_vtraits<ValueTraits, BucketTraits>::priv_stored_hash(n, false_value); }
|
Chris@16
|
2879
|
Chris@16
|
2880 std::size_t priv_hash_to_bucket(std::size_t hash_value) const
|
Chris@16
|
2881 {
|
Chris@16
|
2882 return detail::hash_to_bucket_split<power_2_buckets, incremental>
|
Chris@101
|
2883 (hash_value, this->priv_bucket_traits().bucket_count(), this->priv_split_traits().get_size());
|
Chris@16
|
2884 }
|
Chris@16
|
2885
|
Chris@16
|
2886 template<class Disposer>
|
Chris@16
|
2887 void priv_erase_range_impl
|
Chris@16
|
2888 (size_type bucket_num, siterator before_first_it, siterator end_sit, Disposer disposer, size_type &num_erased)
|
Chris@16
|
2889 {
|
Chris@16
|
2890 const bucket_ptr buckets = this->priv_bucket_pointer();
|
Chris@16
|
2891 bucket_type &b = buckets[bucket_num];
|
Chris@16
|
2892
|
Chris@16
|
2893 if(before_first_it == b.before_begin() && end_sit == b.end()){
|
Chris@16
|
2894 this->priv_erase_range_impl(bucket_num, 1, disposer, num_erased);
|
Chris@16
|
2895 }
|
Chris@16
|
2896 else{
|
Chris@16
|
2897 num_erased = 0;
|
Chris@16
|
2898 siterator to_erase(before_first_it);
|
Chris@16
|
2899 ++to_erase;
|
Chris@16
|
2900 slist_node_ptr end_ptr = end_sit.pointed_node();
|
Chris@16
|
2901 while(to_erase != end_sit){
|
Chris@16
|
2902 group_functions_t::erase_from_group(end_ptr, detail::dcast_bucket_ptr<node>(to_erase.pointed_node()), optimize_multikey_t());
|
Chris@16
|
2903 to_erase = b.erase_after_and_dispose(before_first_it, make_node_disposer(disposer));
|
Chris@16
|
2904 ++num_erased;
|
Chris@16
|
2905 }
|
Chris@16
|
2906 this->priv_size_traits().set_size(this->priv_size_traits().get_size()-num_erased);
|
Chris@16
|
2907 }
|
Chris@16
|
2908 }
|
Chris@16
|
2909
|
Chris@16
|
2910 template<class Disposer>
|
Chris@16
|
2911 void priv_erase_range_impl
|
Chris@16
|
2912 (size_type first_bucket_num, size_type num_buckets, Disposer disposer, size_type &num_erased)
|
Chris@16
|
2913 {
|
Chris@16
|
2914 //Now fully clear the intermediate buckets
|
Chris@16
|
2915 const bucket_ptr buckets = this->priv_bucket_pointer();
|
Chris@16
|
2916 num_erased = 0;
|
Chris@16
|
2917 for(size_type i = first_bucket_num; i < (num_buckets + first_bucket_num); ++i){
|
Chris@16
|
2918 bucket_type &b = buckets[i];
|
Chris@16
|
2919 siterator b_begin(b.before_begin());
|
Chris@16
|
2920 siterator nxt(b_begin);
|
Chris@16
|
2921 ++nxt;
|
Chris@16
|
2922 siterator end_sit(b.end());
|
Chris@16
|
2923 while(nxt != end_sit){
|
Chris@16
|
2924 group_functions_t::init_group(detail::dcast_bucket_ptr<node>(nxt.pointed_node()), optimize_multikey_t());
|
Chris@16
|
2925 nxt = b.erase_after_and_dispose
|
Chris@16
|
2926 (b_begin, make_node_disposer(disposer));
|
Chris@16
|
2927 this->priv_size_traits().decrement();
|
Chris@16
|
2928 ++num_erased;
|
Chris@16
|
2929 }
|
Chris@16
|
2930 }
|
Chris@16
|
2931 }
|
Chris@16
|
2932
|
Chris@16
|
2933 template<class Disposer>
|
Chris@16
|
2934 void priv_erase_range( siterator before_first_it, size_type first_bucket
|
Chris@16
|
2935 , siterator last_it, size_type last_bucket
|
Chris@16
|
2936 , Disposer disposer)
|
Chris@16
|
2937 {
|
Chris@16
|
2938 size_type num_erased;
|
Chris@16
|
2939 if (first_bucket == last_bucket){
|
Chris@16
|
2940 this->priv_erase_range_impl(first_bucket, before_first_it, last_it, disposer, num_erased);
|
Chris@16
|
2941 }
|
Chris@16
|
2942 else {
|
Chris@16
|
2943 bucket_type *b = (&this->priv_bucket_pointer()[0]);
|
Chris@16
|
2944 this->priv_erase_range_impl(first_bucket, before_first_it, b[first_bucket].end(), disposer, num_erased);
|
Chris@16
|
2945 if(size_type n = (last_bucket - first_bucket - 1))
|
Chris@16
|
2946 this->priv_erase_range_impl(first_bucket + 1, n, disposer, num_erased);
|
Chris@16
|
2947 this->priv_erase_range_impl(last_bucket, b[last_bucket].before_begin(), last_it, disposer, num_erased);
|
Chris@16
|
2948 }
|
Chris@16
|
2949 }
|
Chris@16
|
2950
|
Chris@16
|
2951 std::size_t priv_get_bucket_num(siterator it)
|
Chris@16
|
2952 { return this->priv_get_bucket_num_hash_dispatch(it, store_hash_t()); }
|
Chris@16
|
2953
|
Chris@16
|
2954 std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::true_) //store_hash
|
Chris@16
|
2955 {
|
Chris@16
|
2956 return this->priv_hash_to_bucket
|
Chris@16
|
2957 (this->priv_stored_hash(it.pointed_node(), store_hash_t()));
|
Chris@16
|
2958 }
|
Chris@16
|
2959
|
Chris@16
|
2960 std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::false_) //NO store_hash
|
Chris@101
|
2961 { return this->data_type::internal.internal.internal.internal.priv_get_bucket_num_no_hash_store(it, optimize_multikey_t()); }
|
Chris@16
|
2962
|
Chris@16
|
2963 static siterator priv_get_previous(bucket_type &b, siterator i)
|
Chris@16
|
2964 { return bucket_plus_vtraits_t::priv_get_previous(b, i, optimize_multikey_t()); }
|
Chris@16
|
2965
|
Chris@16
|
2966 static siterator priv_get_last(bucket_type &b)
|
Chris@16
|
2967 { return bucket_plus_vtraits_t::priv_get_last(b, optimize_multikey_t()); }
|
Chris@16
|
2968
|
Chris@16
|
2969 template<class Disposer>
|
Chris@16
|
2970 void priv_erase(const_iterator i, Disposer disposer, detail::true_)
|
Chris@16
|
2971 {
|
Chris@16
|
2972 slist_node_ptr elem(i.slist_it().pointed_node());
|
Chris@16
|
2973 slist_node_ptr f_bucket_end, l_bucket_end;
|
Chris@16
|
2974 if(store_hash){
|
Chris@16
|
2975 f_bucket_end = l_bucket_end =
|
Chris@16
|
2976 (this->priv_bucket_pointer()
|
Chris@16
|
2977 [this->priv_hash_to_bucket
|
Chris@16
|
2978 (this->priv_stored_hash(elem, store_hash_t()))
|
Chris@16
|
2979 ]).before_begin().pointed_node();
|
Chris@16
|
2980 }
|
Chris@16
|
2981 else{
|
Chris@16
|
2982 f_bucket_end = this->priv_bucket_pointer()->cend().pointed_node();
|
Chris@16
|
2983 l_bucket_end = f_bucket_end + this->priv_bucket_count() - 1;
|
Chris@16
|
2984 }
|
Chris@16
|
2985 node_ptr nxt_in_group;
|
Chris@16
|
2986 siterator prev = bucket_type::s_iterator_to
|
Chris@16
|
2987 (*group_functions_t::get_previous_and_next_in_group
|
Chris@16
|
2988 ( elem, nxt_in_group, f_bucket_end, l_bucket_end)
|
Chris@16
|
2989 );
|
Chris@16
|
2990 bucket_type::s_erase_after_and_dispose(prev, make_node_disposer(disposer));
|
Chris@16
|
2991 if(nxt_in_group)
|
Chris@16
|
2992 group_algorithms::unlink_after(nxt_in_group);
|
Chris@16
|
2993 if(safemode_or_autounlink)
|
Chris@16
|
2994 group_algorithms::init(detail::dcast_bucket_ptr<node>(elem));
|
Chris@16
|
2995 }
|
Chris@16
|
2996
|
Chris@16
|
2997 template <class Disposer>
|
Chris@16
|
2998 void priv_erase(const_iterator i, Disposer disposer, detail::false_)
|
Chris@16
|
2999 {
|
Chris@16
|
3000 siterator to_erase(i.slist_it());
|
Chris@16
|
3001 bucket_type &b = this->priv_bucket_pointer()[this->priv_get_bucket_num(to_erase)];
|
Chris@16
|
3002 siterator prev(this->priv_get_previous(b, to_erase));
|
Chris@16
|
3003 b.erase_after_and_dispose(prev, make_node_disposer(disposer));
|
Chris@16
|
3004 }
|
Chris@16
|
3005
|
Chris@16
|
3006 template<class KeyType, class KeyHasher, class KeyValueEqual>
|
Chris@16
|
3007 siterator priv_find
|
Chris@16
|
3008 ( const KeyType &key, KeyHasher hash_func
|
Chris@16
|
3009 , KeyValueEqual equal_func, size_type &bucket_number, std::size_t &h, siterator &previt) const
|
Chris@16
|
3010 {
|
Chris@16
|
3011 h = hash_func(key);
|
Chris@16
|
3012 return this->priv_find_with_hash(key, equal_func, bucket_number, h, previt);
|
Chris@16
|
3013 }
|
Chris@16
|
3014
|
Chris@16
|
3015 template<class KeyType, class KeyValueEqual>
|
Chris@16
|
3016 siterator priv_find_with_hash
|
Chris@16
|
3017 ( const KeyType &key, KeyValueEqual equal_func, size_type &bucket_number, const std::size_t h, siterator &previt) const
|
Chris@16
|
3018 {
|
Chris@16
|
3019 bucket_number = this->priv_hash_to_bucket(h);
|
Chris@16
|
3020 bucket_type &b = this->priv_bucket_pointer()[bucket_number];
|
Chris@16
|
3021 previt = b.before_begin();
|
Chris@16
|
3022 if(constant_time_size && this->empty()){
|
Chris@16
|
3023 return this->priv_invalid_local_it();
|
Chris@16
|
3024 }
|
Chris@16
|
3025
|
Chris@16
|
3026 siterator it = previt;
|
Chris@16
|
3027 ++it;
|
Chris@16
|
3028
|
Chris@16
|
3029 while(it != b.end()){
|
Chris@16
|
3030 const value_type &v = this->priv_value_from_slist_node(it.pointed_node());
|
Chris@16
|
3031 if(compare_hash){
|
Chris@16
|
3032 std::size_t vh = this->priv_stored_or_compute_hash(v, store_hash_t());
|
Chris@16
|
3033 if(h == vh && equal_func(key, v)){
|
Chris@16
|
3034 return it;
|
Chris@16
|
3035 }
|
Chris@16
|
3036 }
|
Chris@16
|
3037 else if(equal_func(key, v)){
|
Chris@16
|
3038 return it;
|
Chris@16
|
3039 }
|
Chris@16
|
3040 if(optimize_multikey){
|
Chris@16
|
3041 previt = bucket_type::s_iterator_to
|
Chris@16
|
3042 (*group_functions_t::get_last_in_group
|
Chris@16
|
3043 (detail::dcast_bucket_ptr<node>(it.pointed_node()), optimize_multikey_t()));
|
Chris@16
|
3044 it = previt;
|
Chris@16
|
3045 }
|
Chris@16
|
3046 else{
|
Chris@16
|
3047 previt = it;
|
Chris@16
|
3048 }
|
Chris@16
|
3049 ++it;
|
Chris@16
|
3050 }
|
Chris@16
|
3051 previt = b.before_begin();
|
Chris@16
|
3052 return this->priv_invalid_local_it();
|
Chris@16
|
3053 }
|
Chris@16
|
3054
|
Chris@16
|
3055 iterator priv_insert_equal_with_hash(reference value, std::size_t hash_value)
|
Chris@16
|
3056 {
|
Chris@16
|
3057 size_type bucket_num;
|
Chris@16
|
3058 siterator prev;
|
Chris@16
|
3059 siterator it = this->priv_find_with_hash
|
Chris@16
|
3060 (value, this->priv_equal(), bucket_num, hash_value, prev);
|
Chris@16
|
3061 return this->priv_insert_equal_find(value, bucket_num, hash_value, it);
|
Chris@16
|
3062 }
|
Chris@16
|
3063
|
Chris@16
|
3064 iterator priv_insert_equal_find(reference value, size_type bucket_num, std::size_t hash_value, siterator it)
|
Chris@16
|
3065 {
|
Chris@16
|
3066 bucket_type &b = this->priv_bucket_pointer()[bucket_num];
|
Chris@16
|
3067 bool found_equal = it != this->priv_invalid_local_it();
|
Chris@16
|
3068 if(!found_equal){
|
Chris@16
|
3069 it = b.before_begin();
|
Chris@16
|
3070 }
|
Chris@16
|
3071 //Now store hash if needed
|
Chris@16
|
3072 node_ptr n = pointer_traits<node_ptr>::pointer_to(this->priv_value_to_node(value));
|
Chris@16
|
3073 node_functions_t::store_hash(n, hash_value, store_hash_t());
|
Chris@16
|
3074 //Checks for some modes
|
Chris@16
|
3075 if(safemode_or_autounlink)
|
Chris@16
|
3076 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n));
|
Chris@16
|
3077 //Shortcut for optimize_multikey cases
|
Chris@16
|
3078 if(optimize_multikey){
|
Chris@16
|
3079 node_ptr first_in_group = found_equal ?
|
Chris@16
|
3080 detail::dcast_bucket_ptr<node>(it.pointed_node()) : node_ptr();
|
Chris@16
|
3081 group_functions_t::insert_in_group(first_in_group, n, optimize_multikey_t());
|
Chris@16
|
3082 }
|
Chris@16
|
3083 //Update cache and increment size if needed
|
Chris@16
|
3084 this->priv_insertion_update_cache(bucket_num);
|
Chris@16
|
3085 this->priv_size_traits().increment();
|
Chris@16
|
3086 //Insert the element in the bucket after it
|
Chris@16
|
3087 return iterator(b.insert_after(it, *n), &this->get_bucket_value_traits());
|
Chris@16
|
3088 }
|
Chris@16
|
3089
|
Chris@16
|
3090 template<class KeyType, class KeyHasher, class KeyValueEqual>
|
Chris@16
|
3091 std::pair<siterator, siterator> priv_equal_range
|
Chris@16
|
3092 ( const KeyType &key
|
Chris@16
|
3093 , KeyHasher hash_func
|
Chris@16
|
3094 , KeyValueEqual equal_func
|
Chris@16
|
3095 , size_type &bucket_number_first
|
Chris@16
|
3096 , size_type &bucket_number_second
|
Chris@16
|
3097 , size_type &cnt) const
|
Chris@16
|
3098 {
|
Chris@16
|
3099 std::size_t h;
|
Chris@16
|
3100 cnt = 0;
|
Chris@16
|
3101 siterator prev;
|
Chris@16
|
3102 //Let's see if the element is present
|
Chris@16
|
3103 std::pair<siterator, siterator> to_return
|
Chris@16
|
3104 ( this->priv_find(key, hash_func, equal_func, bucket_number_first, h, prev)
|
Chris@16
|
3105 , this->priv_invalid_local_it());
|
Chris@16
|
3106 if(to_return.first == to_return.second){
|
Chris@16
|
3107 bucket_number_second = bucket_number_first;
|
Chris@16
|
3108 return to_return;
|
Chris@16
|
3109 }
|
Chris@16
|
3110 {
|
Chris@16
|
3111 //If it's present, find the first that it's not equal in
|
Chris@16
|
3112 //the same bucket
|
Chris@16
|
3113 bucket_type &b = this->priv_bucket_pointer()[bucket_number_first];
|
Chris@16
|
3114 siterator it = to_return.first;
|
Chris@16
|
3115 if(optimize_multikey){
|
Chris@16
|
3116 to_return.second = bucket_type::s_iterator_to
|
Chris@16
|
3117 (*node_traits::get_next(group_functions_t::get_last_in_group
|
Chris@16
|
3118 (detail::dcast_bucket_ptr<node>(it.pointed_node()), optimize_multikey_t())));
|
Chris@101
|
3119
|
Chris@101
|
3120 cnt = 0;
|
Chris@101
|
3121 for(; it != to_return.second; ++it){ ++cnt; }
|
Chris@16
|
3122 if(to_return.second != b.end()){
|
Chris@16
|
3123 bucket_number_second = bucket_number_first;
|
Chris@16
|
3124 return to_return;
|
Chris@16
|
3125 }
|
Chris@16
|
3126 }
|
Chris@16
|
3127 else{
|
Chris@16
|
3128 ++cnt;
|
Chris@16
|
3129 ++it;
|
Chris@16
|
3130 while(it != b.end()){
|
Chris@16
|
3131 const value_type &v = this->priv_value_from_slist_node(it.pointed_node());
|
Chris@16
|
3132 if(compare_hash){
|
Chris@16
|
3133 std::size_t hv = this->priv_stored_or_compute_hash(v, store_hash_t());
|
Chris@16
|
3134 if(hv != h || !equal_func(key, v)){
|
Chris@16
|
3135 to_return.second = it;
|
Chris@16
|
3136 bucket_number_second = bucket_number_first;
|
Chris@16
|
3137 return to_return;
|
Chris@16
|
3138 }
|
Chris@16
|
3139 }
|
Chris@16
|
3140 else if(!equal_func(key, v)){
|
Chris@16
|
3141 to_return.second = it;
|
Chris@16
|
3142 bucket_number_second = bucket_number_first;
|
Chris@16
|
3143 return to_return;
|
Chris@16
|
3144 }
|
Chris@16
|
3145 ++it;
|
Chris@16
|
3146 ++cnt;
|
Chris@16
|
3147 }
|
Chris@16
|
3148 }
|
Chris@16
|
3149 }
|
Chris@16
|
3150
|
Chris@16
|
3151 //If we reached the end, find the first, non-empty bucket
|
Chris@16
|
3152 for(bucket_number_second = bucket_number_first+1
|
Chris@16
|
3153 ; bucket_number_second != this->priv_bucket_count()
|
Chris@16
|
3154 ; ++bucket_number_second){
|
Chris@16
|
3155 bucket_type &b = this->priv_bucket_pointer()[bucket_number_second];
|
Chris@16
|
3156 if(!b.empty()){
|
Chris@16
|
3157 to_return.second = b.begin();
|
Chris@16
|
3158 return to_return;
|
Chris@16
|
3159 }
|
Chris@16
|
3160 }
|
Chris@16
|
3161
|
Chris@16
|
3162 //Otherwise, return the end node
|
Chris@16
|
3163 to_return.second = this->priv_invalid_local_it();
|
Chris@16
|
3164 return to_return;
|
Chris@16
|
3165 }
|
Chris@16
|
3166 /// @endcond
|
Chris@16
|
3167 };
|
Chris@16
|
3168
|
Chris@16
|
3169 /// @cond
|
Chris@16
|
3170 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
3171 template < class T
|
Chris@16
|
3172 , bool UniqueKeys
|
Chris@16
|
3173 , class PackedOptions
|
Chris@16
|
3174 >
|
Chris@16
|
3175 #else
|
Chris@16
|
3176 template <class T, bool UniqueKeys, class ...Options>
|
Chris@16
|
3177 #endif
|
Chris@101
|
3178 struct make_bucket_traits
|
Chris@16
|
3179 {
|
Chris@16
|
3180 //Real value traits must be calculated from options
|
Chris@16
|
3181 typedef typename detail::get_value_traits
|
Chris@16
|
3182 <T, typename PackedOptions::proto_value_traits>::type value_traits;
|
Chris@101
|
3183
|
Chris@16
|
3184 typedef typename PackedOptions::bucket_traits specified_bucket_traits;
|
Chris@16
|
3185
|
Chris@16
|
3186 //Real bucket traits must be calculated from options and calculated value_traits
|
Chris@16
|
3187 typedef typename detail::get_slist_impl
|
Chris@16
|
3188 <typename detail::reduced_slist_node_traits
|
Chris@101
|
3189 <typename value_traits::node_traits>::type
|
Chris@16
|
3190 >::type slist_impl;
|
Chris@16
|
3191
|
Chris@16
|
3192 typedef typename
|
Chris@16
|
3193 detail::if_c< detail::is_same
|
Chris@16
|
3194 < specified_bucket_traits
|
Chris@16
|
3195 , default_bucket_traits
|
Chris@16
|
3196 >::value
|
Chris@16
|
3197 , detail::bucket_traits_impl<slist_impl>
|
Chris@16
|
3198 , specified_bucket_traits
|
Chris@16
|
3199 >::type type;
|
Chris@16
|
3200 };
|
Chris@16
|
3201 /// @endcond
|
Chris@16
|
3202
|
Chris@16
|
3203 //! Helper metafunction to define a \c hashtable that yields to the same type when the
|
Chris@16
|
3204 //! same options (either explicitly or implicitly) are used.
|
Chris@16
|
3205 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
3206 template<class T, class ...Options>
|
Chris@16
|
3207 #else
|
Chris@16
|
3208 template<class T, class O1 = void, class O2 = void
|
Chris@16
|
3209 , class O3 = void, class O4 = void
|
Chris@16
|
3210 , class O5 = void, class O6 = void
|
Chris@16
|
3211 , class O7 = void, class O8 = void
|
Chris@16
|
3212 , class O9 = void, class O10= void
|
Chris@16
|
3213 >
|
Chris@16
|
3214 #endif
|
Chris@16
|
3215 struct make_hashtable
|
Chris@16
|
3216 {
|
Chris@16
|
3217 /// @cond
|
Chris@16
|
3218 typedef typename pack_options
|
Chris@16
|
3219 < hashtable_defaults,
|
Chris@16
|
3220 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
3221 O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
|
Chris@16
|
3222 #else
|
Chris@16
|
3223 Options...
|
Chris@16
|
3224 #endif
|
Chris@16
|
3225 >::type packed_options;
|
Chris@16
|
3226
|
Chris@16
|
3227 typedef typename detail::get_value_traits
|
Chris@16
|
3228 <T, typename packed_options::proto_value_traits>::type value_traits;
|
Chris@16
|
3229
|
Chris@101
|
3230 typedef typename make_bucket_traits
|
Chris@101
|
3231 <T, false, packed_options>::type bucket_traits;
|
Chris@16
|
3232
|
Chris@16
|
3233 typedef hashtable_impl
|
Chris@16
|
3234 < value_traits
|
Chris@16
|
3235 , typename packed_options::hash
|
Chris@16
|
3236 , typename packed_options::equal
|
Chris@16
|
3237 , typename packed_options::size_type
|
Chris@101
|
3238 , bucket_traits
|
Chris@16
|
3239 , (std::size_t(false)*hash_bool_flags::unique_keys_pos)
|
Chris@16
|
3240 | (std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos)
|
Chris@16
|
3241 | (std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos)
|
Chris@16
|
3242 | (std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos)
|
Chris@16
|
3243 | (std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos)
|
Chris@16
|
3244 | (std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos)
|
Chris@16
|
3245 > implementation_defined;
|
Chris@16
|
3246
|
Chris@16
|
3247 /// @endcond
|
Chris@16
|
3248 typedef implementation_defined type;
|
Chris@16
|
3249 };
|
Chris@16
|
3250
|
Chris@16
|
3251 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
|
Chris@16
|
3252
|
Chris@16
|
3253 #if defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
3254 template<class T, class ...Options>
|
Chris@16
|
3255 #else
|
Chris@16
|
3256 template<class T, class O1, class O2, class O3, class O4, class O5, class O6, class O7, class O8, class O9, class O10>
|
Chris@16
|
3257 #endif
|
Chris@16
|
3258 class hashtable
|
Chris@16
|
3259 : public make_hashtable<T,
|
Chris@16
|
3260 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
3261 O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
|
Chris@16
|
3262 #else
|
Chris@16
|
3263 Options...
|
Chris@16
|
3264 #endif
|
Chris@16
|
3265 >::type
|
Chris@16
|
3266 {
|
Chris@16
|
3267 typedef typename make_hashtable<T,
|
Chris@16
|
3268 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
3269 O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
|
Chris@16
|
3270 #else
|
Chris@16
|
3271 Options...
|
Chris@16
|
3272 #endif
|
Chris@16
|
3273 >::type Base;
|
Chris@16
|
3274 BOOST_MOVABLE_BUT_NOT_COPYABLE(hashtable)
|
Chris@16
|
3275
|
Chris@16
|
3276 public:
|
Chris@16
|
3277 typedef typename Base::value_traits value_traits;
|
Chris@16
|
3278 typedef typename Base::iterator iterator;
|
Chris@16
|
3279 typedef typename Base::const_iterator const_iterator;
|
Chris@16
|
3280 typedef typename Base::bucket_ptr bucket_ptr;
|
Chris@16
|
3281 typedef typename Base::size_type size_type;
|
Chris@16
|
3282 typedef typename Base::hasher hasher;
|
Chris@16
|
3283 typedef typename Base::bucket_traits bucket_traits;
|
Chris@16
|
3284 typedef typename Base::key_equal key_equal;
|
Chris@16
|
3285
|
Chris@16
|
3286 //Assert if passed value traits are compatible with the type
|
Chris@101
|
3287 BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
|
Chris@16
|
3288
|
Chris@16
|
3289 explicit hashtable ( const bucket_traits &b_traits
|
Chris@16
|
3290 , const hasher & hash_func = hasher()
|
Chris@16
|
3291 , const key_equal &equal_func = key_equal()
|
Chris@16
|
3292 , const value_traits &v_traits = value_traits())
|
Chris@16
|
3293 : Base(b_traits, hash_func, equal_func, v_traits)
|
Chris@16
|
3294 {}
|
Chris@16
|
3295
|
Chris@16
|
3296 hashtable(BOOST_RV_REF(hashtable) x)
|
Chris@101
|
3297 : Base(BOOST_MOVE_BASE(Base, x))
|
Chris@16
|
3298 {}
|
Chris@16
|
3299
|
Chris@16
|
3300 hashtable& operator=(BOOST_RV_REF(hashtable) x)
|
Chris@101
|
3301 { return static_cast<hashtable&>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
|
Chris@16
|
3302 };
|
Chris@16
|
3303
|
Chris@16
|
3304 #endif
|
Chris@16
|
3305
|
Chris@16
|
3306 } //namespace intrusive
|
Chris@16
|
3307 } //namespace boost
|
Chris@16
|
3308
|
Chris@16
|
3309 #include <boost/intrusive/detail/config_end.hpp>
|
Chris@16
|
3310
|
Chris@16
|
3311 #endif //BOOST_INTRUSIVE_HASHTABLE_HPP
|