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 #include "set/hdr_striped_set.h"
32 #include <cds/container/striped_set/std_vector.h>
33 #include <cds/container/striped_set.h>
34 #include <cds/sync/spinlock.h>
39 struct my_copy_policy {
40 typedef std::vector<StripedSetHdrTest::item> vector_type;
41 typedef vector_type::iterator iterator;
43 void operator()( vector_type& vec, iterator itInsert, iterator itWhat )
45 vec.insert( itInsert, std::make_pair(itWhat->key(), itWhat->val()) );
49 typedef std::vector<StripedSetHdrTest::item> sequence_t;
52 void StripedSetHdrTest::Refinable_vector()
54 CPPUNIT_MESSAGE( "cmp");
55 typedef cc::StripedSet< sequence_t
56 ,co::mutex_policy< cc::striped_set::refinable<> >
57 , co::hash< hash_int >
58 , co::compare< cmp<item> >
60 test_striped2< set_cmp >();
62 CPPUNIT_MESSAGE( "less");
63 typedef cc::StripedSet< sequence_t
64 ,co::mutex_policy< cc::striped_set::refinable<> >
65 , co::hash< hash_int >
66 , co::less< less<item> >
68 test_striped2< set_less >();
70 CPPUNIT_MESSAGE( "cmpmix");
71 typedef cc::StripedSet< sequence_t
72 ,co::mutex_policy< cc::striped_set::refinable<> >
73 , co::hash< hash_int >
74 , co::compare< cmp<item> >
75 , co::less< less<item> >
77 test_striped2< set_cmpmix >();
79 // Spinlock as lock policy
80 CPPUNIT_MESSAGE( "spinlock");
81 typedef cc::StripedSet< sequence_t
82 , co::mutex_policy< cc::striped_set::refinable<cds::sync::reentrant_spin> >
83 , co::hash< hash_int >
84 , co::less< less<item> >
86 test_striped2< set_spin >();
89 CPPUNIT_MESSAGE( "load_factor_resizing<0>(8)");
91 typedef cc::StripedSet< sequence_t
92 ,co::mutex_policy< cc::striped_set::refinable<> >
93 , co::hash< hash_int >
94 , co::less< less<item> >
95 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
96 > set_less_resizing_lf;
97 set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>(8));
101 CPPUNIT_MESSAGE( "load_factor_resizing<4>");
102 typedef cc::StripedSet< sequence_t
103 ,co::mutex_policy< cc::striped_set::refinable<> >
104 , co::hash< hash_int >
105 , co::less< less<item> >
106 , co::resizing_policy< cc::striped_set::load_factor_resizing<4> >
107 > set_less_resizing_lf16;
108 test_striped2< set_less_resizing_lf16 >();
110 CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(8)");
112 typedef cc::StripedSet< sequence_t
113 ,co::mutex_policy< cc::striped_set::refinable<> >
114 , co::hash< hash_int >
115 , co::less< less<item> >
116 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
117 > set_less_resizing_sbt;
118 set_less_resizing_sbt s(30, cc::striped_set::single_bucket_size_threshold<0>(8));
119 test_striped_with(s);
122 CPPUNIT_MESSAGE( "single_bucket_size_threshold<6>");
123 typedef cc::StripedSet< sequence_t
124 ,co::mutex_policy< cc::striped_set::refinable<> >
125 , co::hash< hash_int >
126 , co::less< less<item> >
127 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<6> >
128 > set_less_resizing_sbt16;
129 test_striped2< set_less_resizing_sbt16 >();
133 CPPUNIT_MESSAGE( "copy_item");
134 typedef cc::StripedSet< sequence_t
135 ,co::mutex_policy< cc::striped_set::refinable<> >
136 , co::hash< hash_int >
137 , co::compare< cmp<item> >
138 , co::copy_policy< cc::striped_set::copy_item >
140 test_striped2< set_copy_item >();
142 CPPUNIT_MESSAGE( "swap_item");
143 typedef cc::StripedSet< sequence_t
144 ,co::mutex_policy< cc::striped_set::refinable<> >
145 , co::hash< hash_int >
146 , co::compare< cmp<item> >
147 , co::copy_policy< cc::striped_set::swap_item >
149 test_striped2< set_swap_item >();
151 CPPUNIT_MESSAGE( "move_item");
152 typedef cc::StripedSet< sequence_t
153 ,co::mutex_policy< cc::striped_set::refinable<> >
154 , co::hash< hash_int >
155 , co::compare< cmp<item> >
156 , co::copy_policy< cc::striped_set::move_item >
158 test_striped2< set_move_item >();
160 CPPUNIT_MESSAGE( "special copy policy");
161 typedef cc::StripedSet< sequence_t
162 ,co::mutex_policy< cc::striped_set::refinable<> >
163 , co::hash< hash_int >
164 , co::compare< cmp<item> >
165 , co::copy_policy< my_copy_policy >
166 > set_special_copy_item;
167 test_striped2< set_special_copy_item >();