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_hash_set.h>
33 #include <cds/container/striped_set.h>
34 #include <cds/sync/spinlock.h>
42 bool operator ()( T const& i1, T const& i2) const
44 return i1.key() == i2.key();
48 typedef std::unordered_set< StripedSetHdrTest::item, StripedSetHdrTest::hash_int, equal_item > set_t;
50 struct my_copy_policy {
51 typedef set_t::iterator iterator;
53 void operator()( set_t& set, iterator itWhat )
55 set.insert( std::make_pair(itWhat->key(), itWhat->val()) );
60 void StripedSetHdrTest::Refinable_hashset()
62 CPPUNIT_MESSAGE( "cmp");
63 typedef cc::StripedSet< set_t
64 , co::hash< hash_int >
65 , co::compare< cmp<item> >
66 ,co::mutex_policy< cc::striped_set::refinable<> >
68 test_striped< set_cmp >();
70 CPPUNIT_MESSAGE( "less");
71 typedef cc::StripedSet< set_t
72 ,co::mutex_policy< cc::striped_set::refinable<> >
73 , co::hash< hash_int >
74 , co::less< less<item> >
76 test_striped< set_less >();
78 CPPUNIT_MESSAGE( "cmpmix");
79 typedef cc::StripedSet< set_t
80 ,co::mutex_policy< cc::striped_set::refinable<> >
81 , co::hash< hash_int >
82 , co::compare< cmp<item> >
83 , co::less< less<item> >
85 test_striped< set_cmpmix >();
87 // Spinlock as lock policy
88 CPPUNIT_MESSAGE( "spinlock");
89 typedef cc::StripedSet< set_t
90 , co::mutex_policy< cc::striped_set::refinable<cds::sync::reentrant_spin> >
91 , co::hash< hash_int >
92 , co::less< less<item> >
94 test_striped< set_spin >();
97 CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
99 typedef cc::StripedSet< set_t
100 ,co::mutex_policy< cc::striped_set::refinable<> >
101 , co::hash< hash_int >
102 , co::less< less<item> >
103 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
104 > set_less_resizing_lf;
105 set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>(1024));
106 test_striped_with(s);
109 CPPUNIT_MESSAGE( "load_factor_resizing<256>");
110 typedef cc::StripedSet< set_t
111 ,co::mutex_policy< cc::striped_set::refinable<> >
112 , co::hash< hash_int >
113 , co::less< less<item> >
114 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
115 > set_less_resizing_lf16;
116 test_striped< set_less_resizing_lf16 >();
118 CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024)");
120 typedef cc::StripedSet< set_t
121 ,co::mutex_policy< cc::striped_set::refinable<> >
122 , co::hash< hash_int >
123 , co::less< less<item> >
124 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
125 > set_less_resizing_sbt;
126 set_less_resizing_sbt s(30, cc::striped_set::single_bucket_size_threshold<0>(1024) );
127 test_striped_with(s);
130 CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
131 typedef cc::StripedSet< set_t
132 ,co::mutex_policy< cc::striped_set::refinable<> >
133 , co::hash< hash_int >
134 , co::less< less<item> >
135 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
136 > set_less_resizing_sbt16;
137 test_striped< set_less_resizing_sbt16 >();
140 CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
141 typedef cc::StripedSet< set_t
142 ,co::mutex_policy< cc::striped_set::refinable<> >
143 , co::hash< hash_int >
144 , co::compare< cmp<item> >
145 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
146 , co::copy_policy< cc::striped_set::copy_item >
148 test_striped< set_copy_item >();
150 CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
151 typedef cc::StripedSet< set_t
152 ,co::mutex_policy< cc::striped_set::refinable<> >
153 , co::hash< hash_int >
154 , co::compare< cmp<item> >
155 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
156 , co::copy_policy< cc::striped_set::swap_item >
158 test_striped< set_swap_item >();
160 CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
161 typedef cc::StripedSet< set_t
162 ,co::mutex_policy< cc::striped_set::refinable<> >
163 , co::hash< hash_int >
164 , co::compare< cmp<item> >
165 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
166 , co::copy_policy< cc::striped_set::move_item >
168 test_striped< set_move_item >();
170 CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
171 typedef cc::StripedSet< set_t
172 ,co::mutex_policy< cc::striped_set::refinable<> >
173 , co::hash< hash_int >
174 , co::compare< cmp<item> >
175 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
176 , co::copy_policy< my_copy_policy >
177 > set_special_copy_item;
178 test_striped< set_special_copy_item >();