File: allmaps.cc

package info (click to toggle)
parallel-hashmap 1.4.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,872 kB
  • sloc: cpp: 20,492; ansic: 1,114; python: 492; makefile: 85; haskell: 56; perl: 43; sh: 23
file content (75 lines) | stat: -rw-r--r-- 2,856 bytes parent folder | download
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
// Silly program just to test the natvis file for Visual Studio
// ------------------------------------------------------------
#include <string>
#include "parallel_hashmap/phmap.h"

template<class Set, class F>
void test_set(const F &f)
{
    Set s;
    typename Set::iterator it;
    for (int i=0; i<100; ++i)
        s.insert(f(i));

    it = s.begin();
    ++it;

	it = s.end();
    it = s.begin();
    while(it != s.end())
        ++it;
    it = s.begin();
}

int main(int, char **)
{
    using namespace std;

    auto make_int    = [](int i) { return i; };
    auto make_string = [](int i) { return std::to_string(i); };

    auto make_2int    = [](int i) { return std::make_pair(i, i); };
    auto make_2string = [](int i) { return std::make_pair(std::to_string(i), std::to_string(i)); };
    

    test_set<phmap::flat_hash_set<int>>(make_int);
    test_set<phmap::flat_hash_set<string>>(make_string);

    test_set<phmap::node_hash_set<int>>(make_int);
    test_set<phmap::node_hash_set<string>>(make_string);

    test_set<phmap::flat_hash_map<int, int>>(make_2int);
    test_set<phmap::flat_hash_map<string, string>>(make_2string);

    test_set<phmap::node_hash_map<int, int>>(make_2int);
    test_set<phmap::node_hash_map<string, string>>(make_2string);

    test_set<phmap::parallel_flat_hash_set<int>>(make_int);
    test_set<phmap::parallel_flat_hash_set<string>>(make_string);

    test_set<phmap::parallel_node_hash_set<int>>(make_int);
    test_set<phmap::parallel_node_hash_set<string>>(make_string);

    test_set<phmap::parallel_flat_hash_map<int, int>>(make_2int);
    test_set<phmap::parallel_flat_hash_map<string, string>>(make_2string);

    test_set<phmap::parallel_node_hash_map<int, int>>(make_2int);
    test_set<phmap::parallel_node_hash_map<string, string>>(make_2string);

    // example of using default parameters in order to specify the mutex type.
    // 
    // Please be aware that the iterators returned (by find for example) cannot 
    // be safely read in a multithreaded environment. Instead use if_contains(), 
    // which passes a reference value to the callback while holding the submap lock. 
    // Similarly, write access can be done safely using modify_if, try_emplace_l 
    // or lazy_emplace_l.
    // ----------------------------------------------------------------------------
    using Map = phmap::parallel_flat_hash_map<std::size_t, std::size_t,
                                              std::hash<size_t>,
                                              std::equal_to<size_t>, 
                                              std::allocator<std::pair<const size_t, size_t>>, 
                                              4, 
                                              std::mutex>;
    auto make_2size_t    = [](size_t i) { return std::make_pair(i, i); };
    test_set<Map>(make_2size_t);
}