2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSUNIT_SET_TYPE_STRIPED_H
32 #define CDSUNIT_SET_TYPE_STRIPED_H
34 #include "set2/set_type.h"
36 #include <cds/container/striped_set/std_list.h>
37 #include <cds/container/striped_set/std_vector.h>
38 #include <cds/container/striped_set/std_set.h>
39 #include <cds/container/striped_set/std_hash_set.h>
40 #include <cds/container/striped_set/boost_unordered_set.h>
42 #include <boost/version.hpp>
43 #if BOOST_VERSION >= 104800
44 # include <cds/container/striped_set/boost_slist.h>
45 # include <cds/container/striped_set/boost_list.h>
46 # include <cds/container/striped_set/boost_vector.h>
47 # include <cds/container/striped_set/boost_stable_vector.h>
48 # include <cds/container/striped_set/boost_set.h>
49 # include <cds/container/striped_set/boost_flat_set.h>
51 #include <cds/container/striped_set.h>
55 struct tag_StripedSet;
57 template <typename Key, typename Val>
58 struct set_type< tag_StripedSet, Key, Val >: public set_type_base< Key, Val >
60 typedef set_type_base< Key, Val > base_class;
61 typedef typename base_class::key_val key_val;
62 typedef typename base_class::compare compare;
63 typedef typename base_class::less less;
64 typedef typename base_class::equal_to equal_to;
65 typedef typename base_class::hash hash;
66 typedef typename base_class::hash2 hash2;
69 // ***************************************************************************
72 // for sequential containers
73 template <class BucketEntry, typename... Options>
74 class StripedHashSet_seq:
75 public cc::StripedSet< BucketEntry,
76 co::mutex_policy< cc::striped_set::striping<> >
77 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
81 typedef cc::StripedSet< BucketEntry,
82 co::mutex_policy< cc::striped_set::striping<> >
83 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
86 typedef typename base_class::resizing_policy resizing_policy_t;
88 resizing_policy_t m_placeHolder;
90 template <class Config>
91 StripedHashSet_seq( Config const& cfg )
92 : base_class( cfg.c_nSetSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nLoadFactor )) )
96 template <typename Q, typename Less>
97 bool erase_with( Q const& v, Less pred )
99 return base_class::erase( v );
104 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
105 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
106 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
109 template <class BucketEntry, typename... Options>
110 class StripedHashSet_seq_rational:
111 public cc::StripedSet< BucketEntry,
112 co::mutex_policy< cc::striped_set::striping<> >
113 ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
117 typedef cc::StripedSet< BucketEntry,
118 co::mutex_policy< cc::striped_set::striping<> >
119 ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
122 typedef typename base_class::resizing_policy resizing_policy_t;
124 resizing_policy_t m_placeHolder;
126 template <class Config>
127 StripedHashSet_seq_rational( Config const& cfg ) // LoadFactor = 1 / nDenominator
128 : base_class( cfg.c_nSetSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( 1, cfg.c_nLoadFactor )) )
132 template <typename Q, typename Less>
133 bool erase_with( Q const& v, Less pred )
135 return base_class::erase( v );
140 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
141 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
142 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
145 // for non-sequential ordered containers
146 template <class BucketEntry, typename... Options>
147 class StripedHashSet_ord:
148 public cc::StripedSet< BucketEntry,
149 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
150 ,co::mutex_policy< cc::striped_set::striping<> >
154 typedef cc::StripedSet< BucketEntry,
155 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
156 ,co::mutex_policy< cc::striped_set::striping<> >
159 typedef typename base_class::resizing_policy resizing_policy_t;
161 resizing_policy_t m_placeHolder;
163 template <class Config>
164 StripedHashSet_ord( Config const& cfg )
165 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nMaxLoadFactor * 1024 )) )
169 template <typename Q, typename Less>
170 bool erase_with( Q const& v, Less pred )
172 return base_class::erase( v );
177 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
178 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
179 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
182 template <class BucketEntry, typename... Options>
183 class StripedHashSet_ord_rational:
184 public cc::StripedSet< BucketEntry,
185 co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
186 ,co::mutex_policy< cc::striped_set::striping<> >
190 typedef cc::StripedSet< BucketEntry,
191 co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
192 ,co::mutex_policy< cc::striped_set::striping<> >
195 typedef typename base_class::resizing_policy resizing_policy_t;
197 resizing_policy_t m_placeHolder;
199 template <class Config>
200 StripedHashSet_ord_rational( Config const& cfg ) // LoadFactor = 1 / nDenominator
201 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( 1024, cfg.c_nLoadFactor )))
205 template <typename Q, typename Less>
206 bool erase_with( Q const& v, Less pred )
208 return base_class::erase( v );
213 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
214 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
215 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
218 typedef StripedHashSet_seq<
224 typedef StripedHashSet_seq_rational<
228 > StripedSet_rational_list;
230 typedef StripedHashSet_seq<
231 std::vector< key_val >
236 typedef StripedHashSet_seq_rational<
237 std::vector< key_val >
240 > StripedSet_rational_vector;
242 #if BOOST_VERSION >= 104800
243 typedef StripedHashSet_seq<
244 boost::container::slist< key_val >
247 > StripedSet_boost_slist;
249 typedef StripedHashSet_seq_rational<
250 boost::container::slist< key_val >
253 > StripedSet_rational_boost_slist;
255 typedef StripedHashSet_seq<
256 boost::container::list< key_val >
259 > StripedSet_boost_list;
261 typedef StripedHashSet_seq_rational<
262 boost::container::list< key_val >
265 > StripedSet_rational_boost_list;
267 typedef StripedHashSet_seq<
268 boost::container::vector< key_val >
271 > StripedSet_boost_vector;
273 typedef StripedHashSet_seq_rational<
274 boost::container::vector< key_val >
277 > StripedSet_rational_boost_vector;
279 typedef StripedHashSet_seq<
280 boost::container::stable_vector< key_val >
283 > StripedSet_boost_stable_vector;
285 typedef StripedHashSet_seq_rational<
286 boost::container::stable_vector< key_val >
289 > StripedSet_rational_boost_stable_vector;
292 typedef StripedHashSet_ord<
293 std::set< key_val, less >
297 typedef StripedHashSet_ord_rational<
298 std::set< key_val, less >
300 > StripedSet_rational_set;
302 typedef StripedHashSet_ord<
303 std::unordered_set< key_val, hash, equal_to >
305 > StripedSet_hashset;
307 typedef StripedHashSet_ord_rational<
308 std::unordered_set< key_val, hash, equal_to >
310 > StripedSet_rational_hashset;
312 #if BOOST_VERSION >= 104800
313 typedef StripedHashSet_ord<
314 boost::container::set< key_val, less >
316 > StripedSet_boost_set;
318 typedef StripedHashSet_ord_rational<
319 boost::container::set< key_val, less >
321 > StripedSet_rational_boost_set;
323 typedef StripedHashSet_ord<
324 boost::container::flat_set< key_val, less >
326 > StripedSet_boost_flat_set;
328 typedef StripedHashSet_ord_rational<
329 boost::container::flat_set< key_val, less >
331 > StripedSet_rational_boost_flat_set;
334 typedef StripedHashSet_ord<
335 boost::unordered_set< key_val, hash, equal_to >
337 > StripedSet_boost_unordered_set;
339 typedef StripedHashSet_ord_rational<
340 boost::unordered_set< key_val, hash, equal_to >
342 > StripedSet_rational_boost_unordered_set;
345 // ***************************************************************************
348 // for sequential containers
349 template <class BucketEntry, typename... Options>
350 class RefinableHashSet_seq:
351 public cc::StripedSet< BucketEntry,
352 co::mutex_policy< cc::striped_set::refinable<> >
353 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
357 typedef cc::StripedSet< BucketEntry,
358 co::mutex_policy< cc::striped_set::refinable<> >
359 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
362 typedef typename base_class::resizing_policy resizing_policy_t;
364 resizing_policy_t m_placeHolder;
366 template <class Config>
367 RefinableHashSet_seq( Config const& cfg )
368 : base_class( cfg.c_nSetSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nLoadFactor )) )
372 template <typename Q, typename Less>
373 bool erase_with( Q const& v, Less pred )
375 return base_class::erase( v );
380 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
381 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
384 template <class BucketEntry, typename... Options>
385 class RefinableHashSet_seq_rational:
386 public cc::StripedSet< BucketEntry,
387 co::mutex_policy< cc::striped_set::refinable<> >
388 ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
392 typedef cc::StripedSet< BucketEntry,
393 co::mutex_policy< cc::striped_set::refinable<> >
394 ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
397 typedef typename base_class::resizing_policy resizing_policy_t;
399 resizing_policy_t m_placeHolder;
401 template <class Config>
402 RefinableHashSet_seq_rational( Config const& cfg ) // LoadFactor = 1 / nDenominator
403 : base_class( cfg.c_nSetSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( 1, cfg.c_nLoadFactor )))
407 template <typename Q, typename Less>
408 bool erase_with( Q const& v, Less pred )
410 return base_class::erase( v );
415 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
416 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
419 // for non-sequential ordered containers
420 template <class BucketEntry, typename... Options>
421 class RefinableHashSet_ord:
422 public cc::StripedSet< BucketEntry,
423 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
424 ,co::mutex_policy< cc::striped_set::refinable<> >
428 typedef cc::StripedSet< BucketEntry,
429 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
430 ,co::mutex_policy< cc::striped_set::refinable<> >
433 typedef typename base_class::resizing_policy resizing_policy_t;
435 resizing_policy_t m_placeHolder;
437 template <class Config>
438 RefinableHashSet_ord( Config const& cfg )
439 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nMaxLoadFactor * 1024 )) )
443 template <typename Q, typename Less>
444 bool erase_with( Q const& v, Less pred )
446 return base_class::erase( v );
451 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
452 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
455 template <class BucketEntry, typename... Options>
456 class RefinableHashSet_ord_rational:
457 public cc::StripedSet< BucketEntry,
458 co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
459 ,co::mutex_policy< cc::striped_set::refinable<> >
463 typedef cc::StripedSet< BucketEntry,
464 co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
465 ,co::mutex_policy< cc::striped_set::refinable<> >
468 typedef typename base_class::resizing_policy resizing_policy_t;
470 resizing_policy_t m_placeHolder;
472 template <class Config>
473 RefinableHashSet_ord_rational( Config const& cfg ) // LoadFactor = 1 / nDenominator
474 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( 1024, cfg.c_nLoadFactor )))
478 template <typename Q, typename Less>
479 bool erase_with( Q const& v, Less pred )
481 return base_class::erase( v );
486 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
487 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
490 typedef RefinableHashSet_seq<
496 typedef RefinableHashSet_seq_rational<
500 > RefinableSet_rational_list;
502 typedef RefinableHashSet_seq<
503 std::vector< key_val >
506 > RefinableSet_vector;
508 typedef RefinableHashSet_seq_rational<
509 std::vector< key_val >
512 > RefinableSet_rational_vector;
514 #if BOOST_VERSION >= 104800
515 typedef RefinableHashSet_seq<
516 boost::container::slist< key_val >
519 > RefinableSet_boost_slist;
521 typedef RefinableHashSet_seq_rational<
522 boost::container::slist< key_val >
525 > RefinableSet_rational_boost_slist;
527 typedef RefinableHashSet_seq<
528 boost::container::list< key_val >
531 > RefinableSet_boost_list;
533 typedef RefinableHashSet_seq_rational<
534 boost::container::list< key_val >
537 > RefinableSet_rational_boost_list;
539 typedef RefinableHashSet_seq<
540 boost::container::vector< key_val >
543 > RefinableSet_boost_vector;
545 typedef RefinableHashSet_seq_rational<
546 boost::container::vector< key_val >
549 > RefinableSet_rational_boost_vector;
551 typedef RefinableHashSet_seq<
552 boost::container::stable_vector< key_val >
555 > RefinableSet_boost_stable_vector;
557 typedef RefinableHashSet_seq_rational<
558 boost::container::stable_vector< key_val >
561 > RefinableSet_rational_boost_stable_vector;
564 typedef RefinableHashSet_ord<
565 std::set< key_val, less >
569 typedef RefinableHashSet_ord_rational<
570 std::set< key_val, less >
572 > RefinableSet_rational_set;
574 typedef RefinableHashSet_ord<
575 std::unordered_set< key_val, hash, equal_to >
577 > RefinableSet_hashset;
579 typedef RefinableHashSet_ord_rational<
580 std::unordered_set< key_val, hash, equal_to >
582 > RefinableSet_rational_hashset;
584 #if BOOST_VERSION >= 104800
585 typedef RefinableHashSet_ord<
586 boost::container::set< key_val, less >
588 > RefinableSet_boost_set;
590 typedef RefinableHashSet_ord_rational<
591 boost::container::set< key_val, less >
593 > RefinableSet_rational_boost_set;
595 typedef RefinableHashSet_ord<
596 boost::container::flat_set< key_val, less >
598 > RefinableSet_boost_flat_set;
600 typedef RefinableHashSet_ord_rational<
601 boost::container::flat_set< key_val, less >
603 > RefinableSet_rational_boost_flat_set;
606 typedef RefinableHashSet_ord<
607 boost::unordered_set< key_val, hash, equal_to >
609 > RefinableSet_boost_unordered_set;
611 typedef RefinableHashSet_ord_rational<
612 boost::unordered_set< key_val, hash, equal_to >
614 > RefinableSet_rational_boost_unordered_set;
619 #endif // #ifndef CDSUNIT_SET_TYPE_STRIPED_H