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 class Set_InsDelFind: public cds_test::stress_fixture
38 static size_t s_nSetSize; // initial set size
39 static size_t s_nPassCount; // initial set size
40 static size_t s_nBronsonAVLTreeMapPassCount;
41 static size_t s_nEllenBinTreeMapPassCount;
42 static size_t s_nFeldmanPassCount;
43 static size_t s_nMichaelMapPassCount;
44 static size_t s_nSkipListMapPassCount;
45 static size_t s_nSplitListMapPassCount;
47 static size_t s_nThreadCount; // thread count
48 static size_t s_nMaxLoadFactor; // maximum load factor
49 static unsigned int s_nInsertPercentage;
50 static unsigned int s_nDeletePercentage;
51 static unsigned int s_nDuration; // test duration, seconds
53 static size_t s_nCuckooInitialSize; // initial size for CuckooSet
54 static size_t s_nCuckooProbesetSize; // CuckooSet probeset size (only for list-based probeset)
55 static size_t s_nCuckooProbesetThreshold; // CUckooSet probeset threshold (0 - use default)
57 static size_t s_nFeldmanSet_HeadBits;
58 static size_t s_nFeldmanSet_ArrayBits;
60 static size_t s_nLoadFactor;
62 static void SetUpTestCase();
63 //static void TearDownTestCase();
72 static const unsigned int c_nShuffleSize = 100;
73 static actions s_arrShuffle[c_nShuffleSize];
76 typedef size_t key_type;
77 typedef size_t value_type;
80 class Worker: public cds_test::thread
82 typedef cds_test::thread base_class;
86 size_t m_nInsertSuccess = 0;
87 size_t m_nInsertFailed = 0;
88 size_t m_nDeleteSuccess = 0;
89 size_t m_nDeleteFailed = 0;
90 size_t m_nFindSuccess = 0;
91 size_t m_nFindFailed = 0;
94 Worker( cds_test::thread_pool& pool, Set& set )
104 virtual thread * clone()
106 return new Worker( *this );
112 Set_InsDelFind& fixture = pool().template fixture<Set_InsDelFind>();
115 size_t const nNormalize = size_t(-1) / ( fixture.s_nSetSize * 2);
116 size_t pass_count = fixture.s_nPassCount;
119 while ( pass_count-- ) {
120 nRand = cds::bitop::RandXorShift(nRand);
121 size_t n = nRand / nNormalize;
122 switch ( s_arrShuffle[i] ) {
124 if ( rSet.contains( n ))
130 if ( rSet.insert( n ))
136 if ( rSet.erase( n ))
143 if ( ++i >= c_nShuffleSize )
151 void do_test( Set& testSet )
153 typedef Worker<Set> work_thread;
155 // fill map - only odd number
157 size_t * pInitArr = new size_t[ s_nSetSize ];
158 size_t * pEnd = pInitArr + s_nSetSize;
159 for ( size_t i = 0; i < s_nSetSize; ++i )
160 pInitArr[i] = i * 2 + 1;
161 shuffle( pInitArr, pEnd );
162 for ( size_t * p = pInitArr; p < pEnd; ++p )
163 testSet.insert( typename Set::value_type( *p, *p ));
168 cds_test::thread_pool& pool = get_pool();
169 std::unique_ptr<work_thread> worker(new work_thread(pool, testSet));
172 propout() << std::make_pair( "thread_count", s_nThreadCount )
173 << std::make_pair( "set_size", s_nSetSize )
174 << std::make_pair( "insert_percentage", s_nInsertPercentage )
175 << std::make_pair( "delete_percentage", s_nDeletePercentage )
176 << std::make_pair( "total_duration", s_nDuration );
178 size_t nInsertSuccess = 0;
179 size_t nInsertFailed = 0;
180 size_t nDeleteSuccess = 0;
181 size_t nDeleteFailed = 0;
182 size_t nFindSuccess = 0;
183 size_t nFindFailed = 0;
184 work_thread &thr = *worker;
185 nInsertSuccess += thr.m_nInsertSuccess;
186 nInsertFailed += thr.m_nInsertFailed;
187 nDeleteSuccess += thr.m_nDeleteSuccess;
188 nDeleteFailed += thr.m_nDeleteFailed;
189 nFindSuccess += thr.m_nFindSuccess;
190 nFindFailed += thr.m_nFindFailed;
193 << std::make_pair( "insert_success", nInsertSuccess )
194 << std::make_pair( "insert_failed", nInsertFailed )
195 << std::make_pair( "delete_success", nDeleteSuccess )
196 << std::make_pair( "delete_failed", nDeleteFailed )
197 << std::make_pair( "find_success", nFindSuccess )
198 << std::make_pair( "find_failed", nFindFailed );
201 EXPECT_TRUE( testSet.empty()) << "set size=" << testSet.size();
203 additional_check( testSet );
204 print_stat( propout(), testSet );
205 additional_cleanup( testSet );
216 void run_bronson_avl_tree() {
217 Set_InsDelFind::s_nPassCount =
218 Set_InsDelFind::s_nBronsonAVLTreeMapPassCount;
223 void run_ellen_bin_tree() {
224 Set_InsDelFind::s_nPassCount =
225 Set_InsDelFind::s_nEllenBinTreeMapPassCount;
231 Set_InsDelFind::s_nPassCount =
232 Set_InsDelFind::s_nFeldmanPassCount;
237 void run_skip_list() {
238 Set_InsDelFind::s_nPassCount =
239 Set_InsDelFind::s_nSkipListMapPassCount;
244 class Set_InsDelFind_LF: public Set_InsDelFind
245 , public ::testing::WithParamInterface<size_t>
251 s_nLoadFactor = GetParam();
252 propout() << std::make_pair( "load_factor", s_nLoadFactor );
253 Set_InsDelFind::run_test<Set>();
258 Set_InsDelFind::s_nPassCount =
259 Set_InsDelFind::s_nMichaelMapPassCount;
260 Set_InsDelFind_LF::run_test<Set>();
264 void run_split_list() {
265 Set_InsDelFind::s_nPassCount =
266 Set_InsDelFind::s_nSplitListMapPassCount;
267 Set_InsDelFind_LF::run_test<Set>();
270 static std::vector<size_t> get_load_factors();