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_InsFind_int: public cds_test::stress_fixture
38 static size_t s_nMapSize; // initial map size
39 static size_t s_nThreadCount; // thread count
40 static size_t s_nMaxLoadFactor; // maximum load factor
42 static size_t s_nCuckooInitialSize; // initial size for CuckooMap
43 static size_t s_nCuckooProbesetSize; // CuckooMap probeset size (only for list-based probeset)
44 static size_t s_nCuckooProbesetThreshold; // CuckooMap probeset threshold (o - use default)
46 static size_t s_nFeldmanMap_HeadBits;
47 static size_t s_nFeldmanMap_ArrayBits;
49 static size_t s_nLoadFactor; // current load factor
51 static void SetUpTestCase();
52 //static void TearDownTestCase();
55 typedef size_t key_type;
56 typedef size_t value_type;
58 template <typename Iterator, typename Map>
59 static bool check_result( Iterator const& it, Map const& map )
61 return it != map.end();
63 template <typename Map>
64 static bool check_result( bool b, Map const& )
70 class Inserter: public cds_test::thread
72 typedef cds_test::thread base_class;
75 std::vector<size_t> m_arrVal;
79 size_t const nThreadCount = s_nThreadCount;
80 size_t const nSize = s_nMapSize / nThreadCount + 1;
81 m_arrVal.resize( nSize );
83 for ( size_t i = 0; i < nSize; nItem += nThreadCount, ++i )
85 shuffle( m_arrVal.begin(), m_arrVal.end());
88 size_t m_nInsertSuccess = 0;
89 size_t m_nInsertFailed = 0;
90 size_t m_nFindSuccess = 0;
91 size_t m_nFindFail = 0;
94 Inserter( cds_test::thread_pool& pool, Map& map )
101 Inserter( Inserter& src )
108 virtual thread * clone()
110 return new Inserter( *this );
117 size_t const nArrSize = m_arrVal.size();
118 for ( size_t i = 0; i < nArrSize; ++i ) {
119 size_t const nItem = m_arrVal[i];
120 if ( check_result( rMap.insert( nItem, nItem * 8 ), rMap ))
125 for ( size_t k = 0; k <= i; ++k ) {
126 if ( check_result( rMap.contains( m_arrVal[k] ), rMap ))
138 void do_test( Map& testMap )
140 typedef Inserter<Map> inserter;
142 cds_test::thread_pool& pool = get_pool();
143 pool.add( new inserter( pool, testMap ), s_nThreadCount );
146 << std::make_pair( "thread_count", s_nThreadCount )
147 << std::make_pair( "insert_per_thread", s_nMapSize );
149 std::chrono::milliseconds duration = pool.run();
151 propout() << std::make_pair( "duration", duration );
153 size_t nInsertSuccess = 0;
154 size_t nInsertFailed = 0;
155 size_t nFindSuccess = 0;
156 size_t nFindFailed = 0;
157 for ( size_t i = 0; i < pool.size(); ++i ) {
158 inserter& thr = static_cast<inserter&>(pool.get( i ));
160 EXPECT_EQ( thr.m_nInsertFailed, 0u ) << "thread " << thr.id();
161 EXPECT_EQ( thr.m_nFindFail, 0u ) << "thread " << thr.id();
163 nInsertSuccess += thr.m_nInsertSuccess;
164 nInsertFailed += thr.m_nInsertFailed;
165 nFindSuccess += thr.m_nFindSuccess;
166 nFindFailed += thr.m_nFindFail;
170 << std::make_pair( "insert_success", nInsertSuccess )
171 << std::make_pair( "insert_failed", nInsertFailed )
172 << std::make_pair( "find_success", nFindSuccess )
173 << std::make_pair( "find_failed", nFindFailed )
174 << std::make_pair( "finish_map_size", testMap.size());
176 EXPECT_EQ( nInsertFailed, 0u );
177 EXPECT_EQ( nFindFailed, 0u );
179 check_before_cleanup( testMap );
182 additional_check( testMap );
183 print_stat( propout(), testMap );
184 additional_cleanup( testMap );
190 Map testMap( *this );
195 class Map_InsFind_int_LF: public Map_InsFind_int
196 , public ::testing::WithParamInterface<size_t>
202 s_nLoadFactor = GetParam();
203 propout() << std::make_pair( "load_factor", s_nLoadFactor );
204 Map_InsFind_int::run_test<Map>();
207 static std::vector<size_t> get_load_factors();