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;
50 static size_t s_nMaxLoadFactor; // maximum load factor
52 static size_t s_nCuckooInitialSize; // initial size for CuckooMap
53 static size_t s_nCuckooProbesetSize; // CuckooMap probeset size (only for list-based probeset)
54 static size_t s_nCuckooProbesetThreshold; // CuckooMap probeset threshold (o - use default)
56 static size_t s_nFeldmanMap_HeadBits;
57 static size_t s_nFeldmanMap_ArrayBits;
59 static size_t s_nLoadFactor; // current load factor
61 static void SetUpTestCase();
62 static void TearDownTestCase();
64 static void setup_test_case();
65 static std::vector<size_t> get_load_factors();
67 typedef std::string key_type;
68 typedef size_t value_type;
70 static std::vector<std::string> s_arrKeys;
79 class Inserter: public cds_test::thread
81 typedef cds_test::thread base_class;
85 size_t m_nInsertSuccess = 0;
86 size_t m_nInsertFailed = 0;
89 Inserter( cds_test::thread_pool& pool, Map& map )
90 : base_class( pool, insert_thread )
94 Inserter( Inserter& src )
99 virtual thread * clone()
101 return new Inserter( *this );
108 for (auto it = s_arrKeys.cbegin(), itEnd = s_arrKeys.cend();
110 if (rMap.insert(*it, 0))
119 class Deleter: public cds_test::thread
121 typedef cds_test::thread base_class;
125 size_t m_nDeleteSuccess = 0;
126 size_t m_nDeleteFailed = 0;
129 Deleter( cds_test::thread_pool& pool, Map& map )
130 : base_class( pool, delete_thread )
134 Deleter( Deleter& src )
139 virtual thread * clone()
141 return new Deleter( *this );
148 for (auto it = s_arrKeys.cbegin(), itEnd = s_arrKeys.cend();
159 template <typename Hash>
160 static void fill_string_array();
163 void do_test( Map& testMap )
165 typedef Inserter<Map> inserter;
166 typedef Deleter<Map> deleter;
168 cds_test::thread_pool& pool = get_pool();
169 std::unique_ptr<inserter> inserter_thrd(
170 new inserter(pool, testMap));
171 std::unique_ptr<deleter> deleter_thrd(
172 new deleter(pool, testMap));
173 for (size_t nPass = 0; nPass < s_nThreadPassCount; ++nPass) {
174 inserter_thrd->test();
175 deleter_thrd->test();
179 for ( auto const& str: s_arrKeys )
180 testMap.erase( str );
181 EXPECT_TRUE( testMap.empty());
182 EXPECT_EQ( testMap.size(), 0u );
183 additional_cleanup( testMap );
189 Map testMap( *this );
194 void run_bronson_avl_tree() {
195 Map_InsDel_string::s_nThreadPassCount =
196 Map_InsDel_string::s_nBronsonAVLTreeMapPassCount;
201 void run_ellen_bin_tree() {
202 Map_InsDel_string::s_nThreadPassCount =
203 Map_InsDel_string::s_nEllenBinTreeMapPassCount;
209 Map_InsDel_string::s_nThreadPassCount =
210 Map_InsDel_string::s_nFeldmanPassCount;
216 Map_InsDel_string::s_nThreadPassCount =
217 Map_InsDel_string::s_nMichaelMapPassCount;
222 void run_skip_list() {
223 Map_InsDel_string::s_nThreadPassCount =
224 Map_InsDel_string::s_nSkipListMapPassCount;
229 class Map_InsDel_string_stdhash: public Map_InsDel_string
232 static void SetUpTestCase();
237 Map_InsDel_string::run_test<Map>();
241 #if CDS_BUILD_BITS == 64
242 class Map_InsDel_string_city32: public Map_InsDel_string
245 static void SetUpTestCase();
250 Map_InsDel_string::run_test<Map>();
254 class Map_InsDel_string_city64: public Map_InsDel_string
257 static void SetUpTestCase();
262 Map_InsDel_string::run_test<Map>();
266 class Map_InsDel_string_city128: public Map_InsDel_string
269 static void SetUpTestCase();
274 Map_InsDel_string::run_test<Map>();
278 #endif // #if CDS_BUILD_BITS == 64
280 class Map_InsDel_string_LF: public Map_InsDel_string
281 , public ::testing::WithParamInterface<size_t>
287 s_nLoadFactor = GetParam();
288 propout() << std::make_pair( "load_factor", s_nLoadFactor );
289 Map_InsDel_string::run_test<Map>();