File: map_insdelfind.cpp

package info (click to toggle)
libcds 2.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 15,564 kB
  • sloc: cpp: 135,002; ansic: 7,218; perl: 243; sh: 237; makefile: 6
file content (118 lines) | stat: -rw-r--r-- 4,709 bytes parent folder | download | duplicates (3)
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
// 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_insdelfind.h"

namespace map {

    size_t Map_InsDelFind::s_nMapSize = 500000;
    size_t Map_InsDelFind::s_nThreadCount = 8;
    size_t Map_InsDelFind::s_nMaxLoadFactor = 8;
    unsigned int Map_InsDelFind::s_nInsertPercentage = 5;
    unsigned int Map_InsDelFind::s_nDeletePercentage = 5;
    unsigned int Map_InsDelFind::s_nDuration = 30;


    size_t Map_InsDelFind::s_nCuckooInitialSize = 1024;// initial size for CuckooSet
    size_t Map_InsDelFind::s_nCuckooProbesetSize = 16; // CuckooSet probeset size (only for list-based probeset)
    size_t Map_InsDelFind::s_nCuckooProbesetThreshold = 0; // CUckooSet probeset threshold (0 - use default)

    size_t Map_InsDelFind::s_nFeldmanMap_HeadBits = 10;
    size_t Map_InsDelFind::s_nFeldmanMap_ArrayBits = 4;

    size_t Map_InsDelFind::s_nLoadFactor = 1;
    Map_InsDelFind::actions Map_InsDelFind::s_arrShuffle[Map_InsDelFind::c_nShuffleSize];

    void Map_InsDelFind::SetUpTestCase()
    {
        cds_test::config const& cfg = get_config( "map_insdelfind" );

        s_nMapSize = cfg.get_size_t( "InitialMapSize", s_nMapSize );
        if ( s_nMapSize < 1000 )
            s_nMapSize = 1000;

        s_nThreadCount = cfg.get_size_t( "ThreadCount", s_nThreadCount );
        if ( s_nThreadCount == 0 )
            s_nThreadCount = std::min( 16u, std::thread::hardware_concurrency() * 2 );

        s_nMaxLoadFactor = cfg.get_size_t( "MaxLoadFactor", s_nMaxLoadFactor );
        if ( s_nMaxLoadFactor == 0 )
            s_nMaxLoadFactor = 1;

        s_nInsertPercentage = cfg.get_uint( "InsertPercentage", s_nInsertPercentage );
        if ( s_nInsertPercentage >= 100 )
            s_nInsertPercentage = 99;

        s_nDeletePercentage = cfg.get_uint( "DeletePercentage", s_nDeletePercentage );
        if ( s_nDeletePercentage >= 100 )
            s_nDeletePercentage = 99;

        if ( s_nInsertPercentage + s_nDeletePercentage > 100 ) {
            unsigned int total = s_nInsertPercentage + s_nDeletePercentage;
            s_nInsertPercentage = s_nInsertPercentage * 100 / total;
            s_nDeletePercentage = s_nDeletePercentage * 100 / total;
        }

        s_nDuration = cfg.get_uint( "Duration", s_nDuration );
        if ( s_nDuration < 5 )
            s_nDuration = 5;

        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;

        actions * pFirst = s_arrShuffle;
        actions * pLast = s_arrShuffle + s_nInsertPercentage;
        std::fill( pFirst, pLast, do_insert );
        pFirst = pLast;
        pLast += s_nDeletePercentage;
        std::fill( pFirst, pLast, do_delete );
        pFirst = pLast;
        pLast = s_arrShuffle + sizeof( s_arrShuffle ) / sizeof( s_arrShuffle[0] );
        if ( pFirst < pLast )
            std::fill( pFirst, pLast, do_find );
        shuffle( s_arrShuffle, pLast );
    }

    std::vector<size_t> Map_InsDelFind_LF::get_load_factors()
    {
        cds_test::config const& cfg = get_config( "map_insdelfind" );

        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;
    }

#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_InsDelFind_LF, ::testing::ValuesIn( Map_InsDelFind_LF::get_load_factors()), get_test_parameter_name );
#else
    INSTANTIATE_TEST_CASE_P( a, Map_InsDelFind_LF, ::testing::ValuesIn( Map_InsDelFind_LF::get_load_factors()));
#endif

} // namespace map