2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
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.
35 #define TEST_CASE(TAG, X) void X();
37 class Map_InsDel_string: public cds_test::stress_fixture
40 static size_t s_nMapSize; // map size
41 static size_t s_nInsertThreadCount; // count of insertion thread
42 static size_t s_nDeleteThreadCount; // count of deletion thread
43 static size_t s_nThreadPassCount; // pass count for each thread
44 static size_t s_nBronsonAVLTreeMapPassCount;
45 static size_t s_nEllenBinTreeMapPassCount;
46 static size_t s_nFeldmanPassCount;
47 static size_t s_nMichaelMapPassCount;
48 static size_t s_nSkipListMapPassCount;
49 static size_t s_nSplitListMapPassCount;
51 static size_t s_nMaxLoadFactor; // maximum load factor
53 static size_t s_nCuckooInitialSize; // initial size for CuckooMap
54 static size_t s_nCuckooProbesetSize; // CuckooMap probeset size (only for list-based probeset)
55 static size_t s_nCuckooProbesetThreshold; // CuckooMap probeset threshold (o - use default)
57 static size_t s_nFeldmanMap_HeadBits;
58 static size_t s_nFeldmanMap_ArrayBits;
60 static size_t s_nLoadFactor; // current load factor
62 static void SetUpTestCase();
63 static void TearDownTestCase();
65 static void setup_test_case();
66 static std::vector<size_t> get_load_factors();
68 typedef std::string key_type;
69 typedef size_t value_type;
71 static std::vector<std::string> s_arrKeys;
80 class Inserter: public cds_test::thread
82 typedef cds_test::thread base_class;
86 size_t m_nInsertSuccess = 0;
87 size_t m_nInsertFailed = 0;
90 Inserter( cds_test::thread_pool& pool, Map& map )
91 : base_class( pool, insert_thread )
95 Inserter( Inserter& src )
100 virtual thread * clone()
102 return new Inserter( *this );
109 for (auto it = s_arrKeys.cbegin(), itEnd = s_arrKeys.cend();
111 if (rMap.insert(*it, 0))
120 class Deleter: public cds_test::thread
122 typedef cds_test::thread base_class;
126 size_t m_nDeleteSuccess = 0;
127 size_t m_nDeleteFailed = 0;
130 Deleter( cds_test::thread_pool& pool, Map& map )
131 : base_class( pool, delete_thread )
135 Deleter( Deleter& src )
140 virtual thread * clone()
142 return new Deleter( *this );
149 for (auto it = s_arrKeys.cbegin(), itEnd = s_arrKeys.cend();
160 template <typename Hash>
161 static void fill_string_array();
164 void do_test( Map& testMap )
166 typedef Inserter<Map> inserter;
167 typedef Deleter<Map> deleter;
169 cds_test::thread_pool& pool = get_pool();
170 std::unique_ptr<inserter> inserter_thrd(
171 new inserter(pool, testMap));
172 std::unique_ptr<deleter> deleter_thrd(
173 new deleter(pool, testMap));
174 for (size_t nPass = 0; nPass < s_nThreadPassCount; ++nPass) {
175 inserter_thrd->test();
176 deleter_thrd->test();
180 for ( auto const& str: s_arrKeys )
181 testMap.erase( str );
182 EXPECT_TRUE( testMap.empty());
183 EXPECT_EQ( testMap.size(), 0u );
184 additional_cleanup( testMap );
190 Map testMap( *this );
195 void run_bronson_avl_tree() {
196 Map_InsDel_string::s_nThreadPassCount =
197 Map_InsDel_string::s_nBronsonAVLTreeMapPassCount;
202 void run_ellen_bin_tree() {
203 Map_InsDel_string::s_nThreadPassCount =
204 Map_InsDel_string::s_nEllenBinTreeMapPassCount;
210 Map_InsDel_string::s_nThreadPassCount =
211 Map_InsDel_string::s_nFeldmanPassCount;
217 Map_InsDel_string::s_nThreadPassCount =
218 Map_InsDel_string::s_nMichaelMapPassCount;
223 void run_skip_list() {
224 Map_InsDel_string::s_nThreadPassCount =
225 Map_InsDel_string::s_nSkipListMapPassCount;
230 void run_split_list() {
231 Map_InsDel_string::s_nThreadPassCount =
232 Map_InsDel_string::s_nSplitListMapPassCount;
237 class Map_InsDel_string_stdhash: public Map_InsDel_string
240 static void SetUpTestCase();
245 Map_InsDel_string::run_test<Map>();
249 #if CDS_BUILD_BITS == 64
250 class Map_InsDel_string_city32: public Map_InsDel_string
253 static void SetUpTestCase();
258 Map_InsDel_string::run_test<Map>();
262 class Map_InsDel_string_city64: public Map_InsDel_string
265 static void SetUpTestCase();
270 Map_InsDel_string::run_test<Map>();
274 class Map_InsDel_string_city128: public Map_InsDel_string
277 static void SetUpTestCase();
282 Map_InsDel_string::run_test<Map>();
286 #endif // #if CDS_BUILD_BITS == 64
288 class Map_InsDel_string_LF: public Map_InsDel_string
289 , public ::testing::WithParamInterface<size_t>
295 s_nLoadFactor = GetParam();
296 propout() << std::make_pair( "load_factor", s_nLoadFactor );
297 Map_InsDel_string::run_test<Map>();