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.
35 class Map_InsDel_int: public cds_test::stress_fixture
38 static size_t s_nMapSize; // map size
39 static size_t s_nInsertThreadCount; // count of insertion thread
40 static size_t s_nDeleteThreadCount; // count of deletion thread
41 static size_t s_nThreadPassCount; // pass count for each thread
42 static size_t s_nMaxLoadFactor; // maximum load factor
44 static size_t s_nCuckooInitialSize; // initial size for CuckooMap
45 static size_t s_nCuckooProbesetSize; // CuckooMap probeset size (only for list-based probeset)
46 static size_t s_nCuckooProbesetThreshold; // CuckooMap probeset threshold (o - use default)
48 static size_t s_nFeldmanMap_HeadBits;
49 static size_t s_nFeldmanMap_ArrayBits;
51 static size_t s_nLoadFactor; // current load factor
53 static void SetUpTestCase();
54 static void TearDownTestCase();
56 typedef size_t key_type;
57 typedef size_t value_type;
59 typedef std::vector<key_type> key_array;
60 static key_array s_arrKeys;
69 class Inserter: public cds_test::thread
71 typedef cds_test::thread base_class;
75 size_t m_nInsertSuccess = 0;
76 size_t m_nInsertFailed = 0;
79 Inserter( cds_test::thread_pool& pool, Map& map )
80 : base_class( pool, insert_thread )
84 Inserter( Inserter& src )
89 virtual thread * clone()
91 return new Inserter( *this );
99 for ( size_t nPass = 0; nPass < s_nThreadPassCount; ++nPass ) {
100 for ( key_array::const_iterator it = s_arrKeys.cbegin(), itEnd = s_arrKeys.cend(); it != itEnd; ++it ) {
101 if ( rMap.insert( *it, *it * 8 ) )
109 for ( size_t nPass = 0; nPass < s_nThreadPassCount; ++nPass ) {
110 for ( key_array::const_reverse_iterator it = s_arrKeys.crbegin(), itEnd = s_arrKeys.crend(); it != itEnd; ++it ) {
111 if ( rMap.insert( *it, *it * 8 ) )
122 class Deleter: public cds_test::thread
124 typedef cds_test::thread base_class;
127 size_t m_nDeleteSuccess = 0;
128 size_t m_nDeleteFailed = 0;
131 Deleter( cds_test::thread_pool& pool, Map& map )
132 : base_class( pool, delete_thread )
136 Deleter( Deleter& src )
141 virtual thread * clone()
143 return new Deleter( *this );
151 for ( size_t nPass = 0; nPass < s_nThreadPassCount; ++nPass ) {
152 for ( key_array::const_iterator it = s_arrKeys.cbegin(), itEnd = s_arrKeys.cend(); it != itEnd; ++it ) {
153 if ( rMap.erase( *it ) )
161 for ( size_t nPass = 0; nPass < s_nThreadPassCount; ++nPass ) {
162 for ( key_array::const_reverse_iterator it = s_arrKeys.crbegin(), itEnd = s_arrKeys.crend(); it != itEnd; ++it ) {
163 if ( rMap.erase( *it ) )
175 void do_test( Map& testMap )
177 typedef Inserter<Map> inserter;
178 typedef Deleter<Map> deleter;
180 cds_test::thread_pool& pool = get_pool();
181 pool.add( new inserter( pool, testMap ), s_nInsertThreadCount );
182 pool.add( new deleter( pool, testMap ), s_nDeleteThreadCount );
184 propout() << std::make_pair( "insert_thread_count", s_nInsertThreadCount )
185 << std::make_pair( "delete_thread_count", s_nDeleteThreadCount )
186 << std::make_pair( "pass_count", s_nThreadPassCount )
187 << std::make_pair( "map_size", s_nMapSize );
189 std::chrono::milliseconds duration = pool.run();
191 propout() << std::make_pair( "duration", duration );
193 size_t nInsertSuccess = 0;
194 size_t nInsertFailed = 0;
195 size_t nDeleteSuccess = 0;
196 size_t nDeleteFailed = 0;
198 for ( size_t i = 0; i < pool.size(); ++i ) {
199 cds_test::thread& thr = pool.get( i );
200 switch ( thr.type() ) {
203 inserter& t = static_cast<inserter&>( thr );
204 nInsertSuccess += t.m_nInsertSuccess;
205 nInsertFailed += t.m_nInsertFailed;
210 deleter& t = static_cast<deleter&>(thr);
211 nDeleteSuccess += t.m_nDeleteSuccess;
212 nDeleteFailed += t.m_nDeleteFailed;
221 << std::make_pair( "insert_success", nInsertSuccess )
222 << std::make_pair( "insert_failed", nInsertFailed )
223 << std::make_pair( "delete_success", nDeleteSuccess )
224 << std::make_pair( "delete_failed", nDeleteFailed )
225 << std::make_pair( "finish_map_size", testMap.size() );
227 check_before_cleanup( testMap );
231 EXPECT_TRUE( testMap.empty());
233 additional_check( testMap );
234 print_stat( propout(), testMap );
235 additional_cleanup( testMap );
241 Map testMap( *this );
246 class Map_InsDel_int_LF: public Map_InsDel_int
247 , public ::testing::WithParamInterface<size_t>
253 s_nLoadFactor = GetParam();
254 propout() << std::make_pair( "load_factor", s_nLoadFactor );
255 Map_InsDel_int::run_test<Set>();
258 static std::vector<size_t> get_load_factors();