1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
// Copyright (c) 2006-2018 Maxim Khizhinsky
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "map_insdel_string.h"
#include <cds_test/hash_func.h>
namespace map {
size_t Map_InsDel_string::s_nMapSize = 1000000; // map size
size_t Map_InsDel_string::s_nInsertThreadCount = 4; // count of insertion thread
size_t Map_InsDel_string::s_nDeleteThreadCount = 4; // count of deletion thread
size_t Map_InsDel_string::s_nThreadPassCount = 4; // pass count for each thread
size_t Map_InsDel_string::s_nMaxLoadFactor = 8; // maximum load factor
size_t Map_InsDel_string::s_nCuckooInitialSize = 1024;// initial size for CuckooSet
size_t Map_InsDel_string::s_nCuckooProbesetSize = 16; // CuckooSet probeset size (only for list-based probeset)
size_t Map_InsDel_string::s_nCuckooProbesetThreshold = 0; // CuckooSet probeset threshold (0 - use default)
size_t Map_InsDel_string::s_nFeldmanMap_HeadBits = 10;
size_t Map_InsDel_string::s_nFeldmanMap_ArrayBits = 4;
size_t Map_InsDel_string::s_nLoadFactor = 1;
std::vector<std::string> Map_InsDel_string::s_arrKeys;
void Map_InsDel_string::setup_test_case()
{
cds_test::config const& cfg = get_config( "map_insdel_string" );
s_nMapSize = cfg.get_size_t( "MapSize", s_nMapSize );
if ( s_nMapSize < 1000 )
s_nMapSize = 1000;
s_nInsertThreadCount = cfg.get_size_t( "InsertThreadCount", s_nInsertThreadCount );
if ( s_nInsertThreadCount == 0 )
s_nInsertThreadCount = 2;
s_nDeleteThreadCount = cfg.get_size_t( "DeleteThreadCount", s_nDeleteThreadCount );
if ( s_nDeleteThreadCount == 0 )
s_nDeleteThreadCount = 2;
s_nThreadPassCount = cfg.get_size_t( "ThreadPassCount", s_nThreadPassCount );
if ( s_nThreadPassCount == 0 )
s_nThreadPassCount = 4;
s_nMaxLoadFactor = cfg.get_size_t( "MaxLoadFactor", s_nMaxLoadFactor );
if ( s_nMaxLoadFactor == 0 )
s_nMaxLoadFactor = 1;
s_nCuckooInitialSize = cfg.get_size_t( "CuckooInitialSize", s_nCuckooInitialSize );
if ( s_nCuckooInitialSize < 256 )
s_nCuckooInitialSize = 256;
s_nCuckooProbesetSize = cfg.get_size_t( "CuckooProbesetSize", s_nCuckooProbesetSize );
if ( s_nCuckooProbesetSize < 8 )
s_nCuckooProbesetSize = 8;
s_nCuckooProbesetThreshold = cfg.get_size_t( "CuckooProbesetThreshold", s_nCuckooProbesetThreshold );
s_nFeldmanMap_HeadBits = cfg.get_size_t( "FeldmanMapHeadBits", s_nFeldmanMap_HeadBits );
if ( s_nFeldmanMap_HeadBits == 0 )
s_nFeldmanMap_HeadBits = 2;
s_nFeldmanMap_ArrayBits = cfg.get_size_t( "FeldmanMapArrayBits", s_nFeldmanMap_ArrayBits );
if ( s_nFeldmanMap_ArrayBits == 0 )
s_nFeldmanMap_ArrayBits = 2;
}
void Map_InsDel_string::SetUpTestCase()
{
setup_test_case();
s_arrKeys.clear();
s_arrKeys.reserve( s_nMapSize );
std::vector<std::string> dict = load_dictionary();
for ( size_t i = 0; i < s_nMapSize; ++i )
s_arrKeys.push_back( std::move( dict.at(i)));
}
void Map_InsDel_string::TearDownTestCase()
{
s_arrKeys.clear();
}
std::vector<size_t> Map_InsDel_string::get_load_factors()
{
cds_test::config const& cfg = get_config( "map_insdel_string" );
s_nMaxLoadFactor = cfg.get_size_t( "MaxLoadFactor", s_nMaxLoadFactor );
if ( s_nMaxLoadFactor == 0 )
s_nMaxLoadFactor = 1;
std::vector<size_t> lf;
for ( size_t n = 1; n <= s_nMaxLoadFactor; n *= 2 )
lf.push_back( n );
return lf;
}
template <typename Hash>
void Map_InsDel_string::fill_string_array()
{
typedef Hash hasher;
typedef decltype( hasher()( std::string())) hash_type;
std::map<hash_type, size_t> mapHash;
s_arrKeys.clear();
std::vector<std::string> dict = load_dictionary();
size_t nSize = dict.size();
if ( nSize > s_nMapSize )
nSize = s_nMapSize;
s_arrKeys.reserve( nSize );
size_t nDiffHash = 0;
hasher h;
for ( size_t i = 0; i < dict.size(); ++i ) {
hash_type hash = h( dict.at( i ));
if ( mapHash.insert( std::make_pair( hash, i )).second ) {
if ( ++nDiffHash >= nSize )
break;
s_arrKeys.push_back( std::move( dict.at( i )));
}
}
s_nMapSize = dict.size();
}
void Map_InsDel_string_stdhash::SetUpTestCase()
{
setup_test_case();
fill_string_array<std::hash<std::string>>();
}
#if CDS_BUILD_BITS == 64
void Map_InsDel_string_city32::SetUpTestCase()
{
setup_test_case();
fill_string_array<cds_test::city32>();
}
void Map_InsDel_string_city64::SetUpTestCase()
{
setup_test_case();
fill_string_array<cds_test::city64>();
}
void Map_InsDel_string_city128::SetUpTestCase()
{
setup_test_case();
fill_string_array<cds_test::city128>();
}
#endif
#ifdef CDSTEST_GTEST_INSTANTIATE_TEST_CASE_P_HAS_4TH_ARG
static std::string get_test_parameter_name( testing::TestParamInfo<size_t> const& p )
{
return std::to_string( p.param );
}
INSTANTIATE_TEST_CASE_P( a, Map_InsDel_string_LF, ::testing::ValuesIn( Map_InsDel_string::get_load_factors()), get_test_parameter_name );
#else
INSTANTIATE_TEST_CASE_P( a, Map_InsDel_string_LF, ::testing::ValuesIn( Map_InsDel_string::get_load_factors()));
#endif
} // namespace map
|