3 #ifndef CDSUNIT_SET_TYPE_STRIPED_H
4 #define CDSUNIT_SET_TYPE_STRIPED_H
6 #include "set2/set_type.h"
8 #include <cds/container/striped_set/std_list.h>
9 #include <cds/container/striped_set/std_vector.h>
10 #include <cds/container/striped_set/std_set.h>
11 #include <cds/container/striped_set/std_hash_set.h>
12 #include <cds/container/striped_set/boost_unordered_set.h>
14 #include <boost/version.hpp>
15 #if BOOST_VERSION >= 104800
16 # include <cds/container/striped_set/boost_slist.h>
17 # include <cds/container/striped_set/boost_list.h>
18 # include <cds/container/striped_set/boost_vector.h>
19 # include <cds/container/striped_set/boost_stable_vector.h>
20 # include <cds/container/striped_set/boost_set.h>
21 # include <cds/container/striped_set/boost_flat_set.h>
23 #include <cds/container/striped_set.h>
27 struct tag_StripedSet;
29 template <typename Key, typename Val>
30 struct set_type< tag_StripedSet, Key, Val >: public set_type_base< Key, Val >
32 typedef set_type_base< Key, Val > base_class;
33 typedef typename base_class::key_val key_val;
34 typedef typename base_class::compare compare;
35 typedef typename base_class::less less;
36 typedef typename base_class::equal_to equal_to;
37 typedef typename base_class::hash hash;
38 typedef typename base_class::hash2 hash2;
41 // ***************************************************************************
44 // for sequential containers
45 template <class BucketEntry, typename... Options>
46 class StripedHashSet_seq:
47 public cc::StripedSet< BucketEntry,
48 co::mutex_policy< cc::striped_set::striping<> >
49 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
53 typedef cc::StripedSet< BucketEntry,
54 co::mutex_policy< cc::striped_set::striping<> >
55 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
58 typedef typename base_class::resizing_policy resizing_policy_t;
60 resizing_policy_t m_placeHolder;
62 template <class Config>
63 StripedHashSet_seq( Config const& cfg )
64 : base_class( cfg.c_nSetSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nLoadFactor )) )
68 template <typename Q, typename Less>
69 bool erase_with( Q const& v, Less pred )
71 return base_class::erase( v );
76 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
77 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
78 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
81 template <class BucketEntry, typename... Options>
82 class StripedHashSet_seq_rational:
83 public cc::StripedSet< BucketEntry,
84 co::mutex_policy< cc::striped_set::striping<> >
85 ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
89 typedef cc::StripedSet< BucketEntry,
90 co::mutex_policy< cc::striped_set::striping<> >
91 ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
94 typedef typename base_class::resizing_policy resizing_policy_t;
96 resizing_policy_t m_placeHolder;
98 template <class Config>
99 StripedHashSet_seq_rational( Config const& cfg ) // LoadFactor = 1 / nDenominator
100 : base_class( cfg.c_nSetSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( 1, cfg.c_nLoadFactor )) )
104 template <typename Q, typename Less>
105 bool erase_with( Q const& v, Less pred )
107 return base_class::erase( v );
112 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
113 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
114 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
117 // for non-sequential ordered containers
118 template <class BucketEntry, typename... Options>
119 class StripedHashSet_ord:
120 public cc::StripedSet< BucketEntry,
121 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
122 ,co::mutex_policy< cc::striped_set::striping<> >
126 typedef cc::StripedSet< BucketEntry,
127 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
128 ,co::mutex_policy< cc::striped_set::striping<> >
131 typedef typename base_class::resizing_policy resizing_policy_t;
133 resizing_policy_t m_placeHolder;
135 template <class Config>
136 StripedHashSet_ord( Config const& cfg )
137 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nMaxLoadFactor * 1024 )) )
141 template <typename Q, typename Less>
142 bool erase_with( Q const& v, Less pred )
144 return base_class::erase( v );
149 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
150 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
151 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
154 template <class BucketEntry, typename... Options>
155 class StripedHashSet_ord_rational:
156 public cc::StripedSet< BucketEntry,
157 co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
158 ,co::mutex_policy< cc::striped_set::striping<> >
162 typedef cc::StripedSet< BucketEntry,
163 co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
164 ,co::mutex_policy< cc::striped_set::striping<> >
167 typedef typename base_class::resizing_policy resizing_policy_t;
169 resizing_policy_t m_placeHolder;
171 template <class Config>
172 StripedHashSet_ord_rational( Config const& cfg ) // LoadFactor = 1 / nDenominator
173 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( 1024, cfg.c_nLoadFactor )))
177 template <typename Q, typename Less>
178 bool erase_with( Q const& v, Less pred )
180 return base_class::erase( v );
185 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
186 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
187 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
190 typedef StripedHashSet_seq<
196 typedef StripedHashSet_seq_rational<
200 > StripedSet_rational_list;
202 typedef StripedHashSet_seq<
203 std::vector< key_val >
208 typedef StripedHashSet_seq_rational<
209 std::vector< key_val >
212 > StripedSet_rational_vector;
214 #if BOOST_VERSION >= 104800
215 typedef StripedHashSet_seq<
216 boost::container::slist< key_val >
219 > StripedSet_boost_slist;
221 typedef StripedHashSet_seq_rational<
222 boost::container::slist< key_val >
225 > StripedSet_rational_boost_slist;
227 typedef StripedHashSet_seq<
228 boost::container::list< key_val >
231 > StripedSet_boost_list;
233 typedef StripedHashSet_seq_rational<
234 boost::container::list< key_val >
237 > StripedSet_rational_boost_list;
239 typedef StripedHashSet_seq<
240 boost::container::vector< key_val >
243 > StripedSet_boost_vector;
245 typedef StripedHashSet_seq_rational<
246 boost::container::vector< key_val >
249 > StripedSet_rational_boost_vector;
251 typedef StripedHashSet_seq<
252 boost::container::stable_vector< key_val >
255 > StripedSet_boost_stable_vector;
257 typedef StripedHashSet_seq_rational<
258 boost::container::stable_vector< key_val >
261 > StripedSet_rational_boost_stable_vector;
264 typedef StripedHashSet_ord<
265 std::set< key_val, less >
269 typedef StripedHashSet_ord_rational<
270 std::set< key_val, less >
272 > StripedSet_rational_set;
274 typedef StripedHashSet_ord<
275 std::unordered_set< key_val, hash, equal_to >
277 > StripedSet_hashset;
279 typedef StripedHashSet_ord_rational<
280 std::unordered_set< key_val, hash, equal_to >
282 > StripedSet_rational_hashset;
284 #if BOOST_VERSION >= 104800
285 typedef StripedHashSet_ord<
286 boost::container::set< key_val, less >
288 > StripedSet_boost_set;
290 typedef StripedHashSet_ord_rational<
291 boost::container::set< key_val, less >
293 > StripedSet_rational_boost_set;
295 typedef StripedHashSet_ord<
296 boost::container::flat_set< key_val, less >
298 > StripedSet_boost_flat_set;
300 typedef StripedHashSet_ord_rational<
301 boost::container::flat_set< key_val, less >
303 > StripedSet_rational_boost_flat_set;
306 typedef StripedHashSet_ord<
307 boost::unordered_set< key_val, hash, equal_to >
309 > StripedSet_boost_unordered_set;
311 typedef StripedHashSet_ord_rational<
312 boost::unordered_set< key_val, hash, equal_to >
314 > StripedSet_rational_boost_unordered_set;
317 // ***************************************************************************
320 // for sequential containers
321 template <class BucketEntry, typename... Options>
322 class RefinableHashSet_seq:
323 public cc::StripedSet< BucketEntry,
324 co::mutex_policy< cc::striped_set::refinable<> >
325 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
329 typedef cc::StripedSet< BucketEntry,
330 co::mutex_policy< cc::striped_set::refinable<> >
331 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
334 typedef typename base_class::resizing_policy resizing_policy_t;
336 resizing_policy_t m_placeHolder;
338 template <class Config>
339 RefinableHashSet_seq( Config const& cfg )
340 : base_class( cfg.c_nSetSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nLoadFactor )) )
344 template <typename Q, typename Less>
345 bool erase_with( Q const& v, Less pred )
347 return base_class::erase( v );
352 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
353 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
356 template <class BucketEntry, typename... Options>
357 class RefinableHashSet_seq_rational:
358 public cc::StripedSet< BucketEntry,
359 co::mutex_policy< cc::striped_set::refinable<> >
360 ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
364 typedef cc::StripedSet< BucketEntry,
365 co::mutex_policy< cc::striped_set::refinable<> >
366 ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
369 typedef typename base_class::resizing_policy resizing_policy_t;
371 resizing_policy_t m_placeHolder;
373 template <class Config>
374 RefinableHashSet_seq_rational( Config const& cfg ) // LoadFactor = 1 / nDenominator
375 : base_class( cfg.c_nSetSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( 1, cfg.c_nLoadFactor )))
379 template <typename Q, typename Less>
380 bool erase_with( Q const& v, Less pred )
382 return base_class::erase( v );
387 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
388 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
391 // for non-sequential ordered containers
392 template <class BucketEntry, typename... Options>
393 class RefinableHashSet_ord:
394 public cc::StripedSet< BucketEntry,
395 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
396 ,co::mutex_policy< cc::striped_set::refinable<> >
400 typedef cc::StripedSet< BucketEntry,
401 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
402 ,co::mutex_policy< cc::striped_set::refinable<> >
405 typedef typename base_class::resizing_policy resizing_policy_t;
407 resizing_policy_t m_placeHolder;
409 template <class Config>
410 RefinableHashSet_ord( Config const& cfg )
411 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nMaxLoadFactor * 1024 )) )
415 template <typename Q, typename Less>
416 bool erase_with( Q const& v, Less pred )
418 return base_class::erase( v );
423 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
424 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
427 template <class BucketEntry, typename... Options>
428 class RefinableHashSet_ord_rational:
429 public cc::StripedSet< BucketEntry,
430 co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
431 ,co::mutex_policy< cc::striped_set::refinable<> >
435 typedef cc::StripedSet< BucketEntry,
436 co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
437 ,co::mutex_policy< cc::striped_set::refinable<> >
440 typedef typename base_class::resizing_policy resizing_policy_t;
442 resizing_policy_t m_placeHolder;
444 template <class Config>
445 RefinableHashSet_ord_rational( Config const& cfg ) // LoadFactor = 1 / nDenominator
446 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( 1024, cfg.c_nLoadFactor )))
450 template <typename Q, typename Less>
451 bool erase_with( Q const& v, Less pred )
453 return base_class::erase( v );
458 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
459 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
462 typedef RefinableHashSet_seq<
468 typedef RefinableHashSet_seq_rational<
472 > RefinableSet_rational_list;
474 typedef RefinableHashSet_seq<
475 std::vector< key_val >
478 > RefinableSet_vector;
480 typedef RefinableHashSet_seq_rational<
481 std::vector< key_val >
484 > RefinableSet_rational_vector;
486 #if BOOST_VERSION >= 104800
487 typedef RefinableHashSet_seq<
488 boost::container::slist< key_val >
491 > RefinableSet_boost_slist;
493 typedef RefinableHashSet_seq_rational<
494 boost::container::slist< key_val >
497 > RefinableSet_rational_boost_slist;
499 typedef RefinableHashSet_seq<
500 boost::container::list< key_val >
503 > RefinableSet_boost_list;
505 typedef RefinableHashSet_seq_rational<
506 boost::container::list< key_val >
509 > RefinableSet_rational_boost_list;
511 typedef RefinableHashSet_seq<
512 boost::container::vector< key_val >
515 > RefinableSet_boost_vector;
517 typedef RefinableHashSet_seq_rational<
518 boost::container::vector< key_val >
521 > RefinableSet_rational_boost_vector;
523 typedef RefinableHashSet_seq<
524 boost::container::stable_vector< key_val >
527 > RefinableSet_boost_stable_vector;
529 typedef RefinableHashSet_seq_rational<
530 boost::container::stable_vector< key_val >
533 > RefinableSet_rational_boost_stable_vector;
536 typedef RefinableHashSet_ord<
537 std::set< key_val, less >
541 typedef RefinableHashSet_ord_rational<
542 std::set< key_val, less >
544 > RefinableSet_rational_set;
546 typedef RefinableHashSet_ord<
547 std::unordered_set< key_val, hash, equal_to >
549 > RefinableSet_hashset;
551 typedef RefinableHashSet_ord_rational<
552 std::unordered_set< key_val, hash, equal_to >
554 > RefinableSet_rational_hashset;
556 #if BOOST_VERSION >= 104800
557 typedef RefinableHashSet_ord<
558 boost::container::set< key_val, less >
560 > RefinableSet_boost_set;
562 typedef RefinableHashSet_ord_rational<
563 boost::container::set< key_val, less >
565 > RefinableSet_rational_boost_set;
567 typedef RefinableHashSet_ord<
568 boost::container::flat_set< key_val, less >
570 > RefinableSet_boost_flat_set;
572 typedef RefinableHashSet_ord_rational<
573 boost::container::flat_set< key_val, less >
575 > RefinableSet_rational_boost_flat_set;
578 typedef RefinableHashSet_ord<
579 boost::unordered_set< key_val, hash, equal_to >
581 > RefinableSet_boost_unordered_set;
583 typedef RefinableHashSet_ord_rational<
584 boost::unordered_set< key_val, hash, equal_to >
586 > RefinableSet_rational_boost_unordered_set;
591 #endif // #ifndef CDSUNIT_SET_TYPE_STRIPED_H