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_set.h>
33 #include <cds/container/striped_set.h>
34 #include <cds/sync/spinlock.h>
39 struct my_copy_policy {
40 typedef std::set<StripedSetHdrTest::item, StripedSetHdrTest::less<StripedSetHdrTest::item> > set_type;
41 typedef set_type::iterator iterator;
43 void operator()( set_type& set, iterator itWhat )
45 set.insert( std::make_pair(itWhat->key(), itWhat->val()) );
49 typedef std::set<StripedSetHdrTest::item, StripedSetHdrTest::less<StripedSetHdrTest::item> > set_t;
52 void StripedSetHdrTest::Refinable_set()
54 CPPUNIT_MESSAGE( "cmp");
55 typedef cc::StripedSet< set_t
56 , co::hash< hash_int >
57 , co::compare< cmp<item> >
58 ,co::mutex_policy< cc::striped_set::refinable<> >
60 test_striped< set_cmp >();
62 CPPUNIT_MESSAGE( "less");
63 typedef cc::StripedSet< set_t
64 ,co::mutex_policy< cc::striped_set::refinable<> >
65 , co::hash< hash_int >
66 , co::less< less<item> >
68 test_striped< set_less >();
70 CPPUNIT_MESSAGE( "cmpmix");
71 typedef cc::StripedSet< set_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_striped< set_cmpmix >();
79 // Spinlock as lock policy
80 CPPUNIT_MESSAGE( "spinlock");
81 typedef cc::StripedSet< set_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_striped< set_spin >();
89 CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
91 typedef cc::StripedSet< set_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>(1024));
101 CPPUNIT_MESSAGE( "load_factor_resizing<256>");
102 typedef cc::StripedSet< set_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<256> >
107 > set_less_resizing_lf16;
108 test_striped< set_less_resizing_lf16 >();
110 CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024)");
112 typedef cc::StripedSet< set_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>(1024) );
119 test_striped_with(s);
122 CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
123 typedef cc::StripedSet< set_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<256> >
128 > set_less_resizing_sbt16;
129 test_striped< set_less_resizing_sbt16 >();
132 CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
133 typedef cc::StripedSet< set_t
134 ,co::mutex_policy< cc::striped_set::refinable<> >
135 , co::hash< hash_int >
136 , co::compare< cmp<item> >
137 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
138 , co::copy_policy< cc::striped_set::copy_item >
140 test_striped< set_copy_item >();
142 CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
143 typedef cc::StripedSet< set_t
144 ,co::mutex_policy< cc::striped_set::refinable<> >
145 , co::hash< hash_int >
146 , co::compare< cmp<item> >
147 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
148 , co::copy_policy< cc::striped_set::swap_item >
150 test_striped< set_swap_item >();
152 CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
153 typedef cc::StripedSet< set_t
154 ,co::mutex_policy< cc::striped_set::refinable<> >
155 , co::hash< hash_int >
156 , co::compare< cmp<item> >
157 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
158 , co::copy_policy< cc::striped_set::move_item >
160 test_striped< set_move_item >();
162 CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
163 typedef cc::StripedSet< set_t
164 ,co::mutex_policy< cc::striped_set::refinable<> >
165 , co::hash< hash_int >
166 , co::compare< cmp<item> >
167 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
168 , co::copy_policy< my_copy_policy >
169 > set_special_copy_item;
170 test_striped< set_special_copy_item >();