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_nMaxLoadFactor; // maximum load factor
46 static size_t s_nCuckooInitialSize; // initial size for CuckooMap
47 static size_t s_nCuckooProbesetSize; // CuckooMap probeset size (only for list-based probeset)
48 static size_t s_nCuckooProbesetThreshold; // CuckooMap probeset threshold (o - use default)
50 static size_t s_nFeldmanMap_HeadBits;
51 static size_t s_nFeldmanMap_ArrayBits;
53 static size_t s_nLoadFactor; // current load factor
55 static void SetUpTestCase();
56 static void TearDownTestCase();
58 static void setup_test_case();
59 static std::vector<size_t> get_load_factors();
61 typedef std::string key_type;
62 typedef size_t value_type;
64 static std::vector<std::string> s_arrKeys;
73 class Inserter: public cds_test::thread
75 typedef cds_test::thread base_class;
79 size_t m_nInsertSuccess = 0;
80 size_t m_nInsertFailed = 0;
83 Inserter( cds_test::thread_pool& pool, Map& map )
84 : base_class( pool, insert_thread )
88 Inserter( Inserter& src )
93 virtual thread * clone()
95 return new Inserter( *this );
103 for ( size_t nPass = 0; nPass < s_nThreadPassCount; ++nPass ) {
104 for ( auto it = s_arrKeys.cbegin(), itEnd = s_arrKeys.cend(); it != itEnd; ++it ) {
105 if ( rMap.insert( *it, 0 ))
113 for ( size_t nPass = 0; nPass < s_nThreadPassCount; ++nPass ) {
114 for ( auto it = s_arrKeys.crbegin(), itEnd = s_arrKeys.crend(); it != itEnd; ++it ) {
115 if ( rMap.insert( *it, 1 ))
126 class Deleter: public cds_test::thread
128 typedef cds_test::thread base_class;
132 size_t m_nDeleteSuccess = 0;
133 size_t m_nDeleteFailed = 0;
136 Deleter( cds_test::thread_pool& pool, Map& map )
137 : base_class( pool, delete_thread )
141 Deleter( Deleter& src )
146 virtual thread * clone()
148 return new Deleter( *this );
156 for ( size_t nPass = 0; nPass < s_nThreadPassCount; ++nPass ) {
157 for ( auto it = s_arrKeys.cbegin(), itEnd = s_arrKeys.cend(); it != itEnd; ++it ) {
158 if ( rMap.erase( *it ))
166 for ( size_t nPass = 0; nPass < s_nThreadPassCount; ++nPass ) {
167 for ( auto it = s_arrKeys.crbegin(), itEnd = s_arrKeys.crend(); it != itEnd; ++it ) {
168 if ( rMap.erase( *it ))
179 template <typename Hash>
180 static void fill_string_array();
183 void do_test( Map& testMap )
185 typedef Inserter<Map> inserter;
186 typedef Deleter<Map> deleter;
188 cds_test::thread_pool& pool = get_pool();
189 pool.add( new inserter( pool, testMap ), s_nInsertThreadCount );
190 pool.add( new deleter( pool, testMap ), s_nDeleteThreadCount );
192 propout() << std::make_pair( "insert_thread_count", s_nInsertThreadCount )
193 << std::make_pair( "delete_thread_count", s_nDeleteThreadCount )
194 << std::make_pair( "pass_count", s_nThreadPassCount )
195 << std::make_pair( "map_size", s_nMapSize );
197 std::chrono::milliseconds duration = pool.run();
199 propout() << std::make_pair( "duration", duration );
201 size_t nInsertSuccess = 0;
202 size_t nInsertFailed = 0;
203 size_t nDeleteSuccess = 0;
204 size_t nDeleteFailed = 0;
206 for ( size_t i = 0; i < pool.size(); ++i ) {
207 cds_test::thread& thr = pool.get( i );
208 switch ( thr.type()) {
211 inserter& t = static_cast<inserter&>(thr);
212 nInsertSuccess += t.m_nInsertSuccess;
213 nInsertFailed += t.m_nInsertFailed;
218 deleter& t = static_cast<deleter&>(thr);
219 nDeleteSuccess += t.m_nDeleteSuccess;
220 nDeleteFailed += t.m_nDeleteFailed;
229 << std::make_pair( "insert_success", nInsertSuccess )
230 << std::make_pair( "insert_failed", nInsertFailed )
231 << std::make_pair( "delete_success", nDeleteSuccess )
232 << std::make_pair( "delete_failed", nDeleteFailed )
233 << std::make_pair( "finish_map_size", testMap.size());
235 check_before_cleanup( testMap );
238 for ( auto const& str: s_arrKeys )
239 testMap.erase( str );
240 EXPECT_TRUE( testMap.empty());
241 EXPECT_EQ( testMap.size(), 0u );
243 additional_check( testMap );
244 print_stat( propout(), testMap );
245 additional_cleanup( testMap );
251 Map testMap( *this );
256 class Map_InsDel_string_stdhash: public Map_InsDel_string
259 static void SetUpTestCase();
264 Map_InsDel_string::run_test<Map>();
268 #if CDS_BUILD_BITS == 64
269 class Map_InsDel_string_city32: public Map_InsDel_string
272 static void SetUpTestCase();
277 Map_InsDel_string::run_test<Map>();
281 class Map_InsDel_string_city64: public Map_InsDel_string
284 static void SetUpTestCase();
289 Map_InsDel_string::run_test<Map>();
293 class Map_InsDel_string_city128: public Map_InsDel_string
296 static void SetUpTestCase();
301 Map_InsDel_string::run_test<Map>();
305 #endif // #if CDS_BUILD_BITS == 64
307 class Map_InsDel_string_LF: public Map_InsDel_string
308 , public ::testing::WithParamInterface<size_t>
314 s_nLoadFactor = GetParam();
315 propout() << std::make_pair( "load_factor", s_nLoadFactor );
316 Map_InsDel_string::run_test<Map>();