File: hash_maps.hpp

package info (click to toggle)
xenium 0.0.2%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,088 kB
  • sloc: cpp: 12,297; makefile: 20
file content (175 lines) | stat: -rw-r--r-- 5,730 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
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
167
168
169
170
171
172
173
174
175
#include "benchmark.hpp"
#include "descriptor.hpp"
#include "reclaimers.hpp"

template <class T>
struct hash_map_builder {
  static auto create(const tao::config::value&) { return std::make_unique<T>(); }
};

#ifdef WITH_VYUKOV_HASH_MAP
#include <xenium/vyukov_hash_map.hpp>

template <class Key, class Value, class... Policies>
struct descriptor<xenium::vyukov_hash_map<Key, Value, Policies...>> {
  static tao::json::value generate() {
    using hash_map = xenium::vyukov_hash_map<Key, Value, Policies...>;
    return {
      {"type", "vyukov_hash_map"},
      {"initial_capacity", DYNAMIC_PARAM},
      {"reclaimer", descriptor<typename hash_map::reclaimer>::generate()}
    };
  }
};

template <class Key, class Value, class... Policies>
struct hash_map_builder<xenium::vyukov_hash_map<Key, Value, Policies...>> {
  static auto create(const tao::config::value& config) {
    auto initial_capacity = config.optional<size_t>("initial_capacity").value_or(128);
    return std::make_unique<xenium::vyukov_hash_map<Key, Value, Policies...>>(initial_capacity);
  }
};

namespace {
  template <class Key, class Value, class... Policies>
  bool try_emplace(xenium::vyukov_hash_map<Key, Value, Policies...>& hash_map, Key key) {
    return hash_map.emplace(key, key);
  }

  template <class Key, class Value, class... Policies>
  bool try_remove(xenium::vyukov_hash_map<Key, Value, Policies...>& hash_map, Key key) {
    return hash_map.erase(key);
  }

  template <class Key, class Value, class... Policies>
  bool try_get(xenium::vyukov_hash_map<Key, Value, Policies...>& hash_map, Key key) {
    typename xenium::vyukov_hash_map<Key, Value, Policies...>::accessor acc;
    return hash_map.try_get_value(key, acc);
  }
}
#endif

#ifdef WITH_HARRIS_MICHAEL_HASH_MAP
#include <xenium/harris_michael_hash_map.hpp>

template <class Key, class Value, class... Policies>
struct descriptor<xenium::harris_michael_hash_map<Key, Value, Policies...>> {
  static tao::json::value generate() {
    using hash_map = xenium::harris_michael_hash_map<Key, Value, Policies...>;
    return {
      {"type", "harris_michael_hash_map"},
      {"buckets", hash_map::num_buckets},
      {"reclaimer", descriptor<typename hash_map::reclaimer>::generate()}
    };
  }
};

namespace {
  template <class Key, class Value, class... Policies>
  bool try_emplace(xenium::harris_michael_hash_map<Key, Value, Policies...>& hash_map, Key key) {
    return hash_map.emplace(key, key);
  }

  template <class Key, class Value, class... Policies>
  bool try_remove(xenium::harris_michael_hash_map<Key, Value, Policies...>& hash_map, Key key) {
    return hash_map.erase(key);
  }

  template <class Key, class Value, class... Policies>
  bool try_get(xenium::harris_michael_hash_map<Key, Value, Policies...>& hash_map, Key key) {
    auto it = hash_map.find(key);
    return it != hash_map.end();
  }
}
#endif

#ifdef WITH_LIBCDS
#include <cds/gc/hp.h>
#include <cds/gc/dhp.h>
#endif

#ifdef WITH_CDS_MICHAEL_HASHMAP
#include <cds/container/michael_kvlist_hp.h>
#include <cds/container/michael_map.h>

template <class List, class Traits>
struct descriptor<cds::container::MichaelHashMap<cds::gc::HP, List, Traits>> {
  static tao::json::value generate() {
    return {
      {"type", "cds::MichaelHashMap"},
      {"nMaxItemCount", DYNAMIC_PARAM},
      {"nLoadFactor", DYNAMIC_PARAM},
      {"gc", "HP"}
    };
  }
};

template <class GC, class List, class Traits>
struct hash_map_builder<cds::container::MichaelHashMap<GC, List, Traits>> {
  static auto create(const tao::config::value& config) {
    auto nMaxItemCount = config.as<size_t>("nMaxItemCount");
    auto nLoadFactor = config.as<size_t>("nLoadFactor");
    return std::make_unique<cds::container::MichaelHashMap<GC, List, Traits>>(nMaxItemCount, nLoadFactor);
  }
};

template <class GC, class List, class Traits>
struct region_guard<cds::container::MichaelHashMap<GC, List, Traits>> {
  struct type{};
};

namespace {
  template <class GC, class List, class Traits>
  bool try_emplace(cds::container::MichaelHashMap<GC, List, Traits>& hash_map, std::uint64_t key) {
    return hash_map.emplace(key, key);
  }

  template <class GC, class List, class Traits>
  bool try_remove(cds::container::MichaelHashMap<GC, List, Traits>& hash_map, std::uint64_t key) {
    return hash_map.erase(key);
  }

  template <class GC, class List, class Traits>
  bool try_get(cds::container::MichaelHashMap<GC, List, Traits>& hash_map, std::uint64_t key) {
    return hash_map.find(key, [](auto& /*val*/){});
  }
}
#endif

#ifdef WITH_CDS_FELDMAN_HASHMAP
#include <cds/container/feldman_hashmap_hp.h>
#include <cds/container/feldman_hashmap_dhp.h>
#include <cds/container/feldman_hashmap_rcu.h>

template <class Key, class T, class Traits>
struct descriptor<cds::container::FeldmanHashMap<cds::gc::HP, Key, T, Traits>> {
  static tao::json::value generate() {
    return {
      {"type", "cds::FeldmanHashMap"},
      {"gc", "HP"}
    };
  }
};

template <class GC, class Key, class T, class Traits>
struct region_guard<cds::container::FeldmanHashMap<GC, Key, T, Traits>> {
  struct type{};
};

namespace {
  template <class GC, class Key, class T, class Traits>
  bool try_emplace(cds::container::FeldmanHashMap<GC, Key, T, Traits>& hash_map, std::uint64_t key) {
    return hash_map.emplace(key, key);
  }

  template <class GC, class Key, class T, class Traits>
  bool try_remove(cds::container::FeldmanHashMap<GC, Key, T, Traits>& hash_map, std::uint64_t key) {
    return hash_map.erase(key);
  }

  template <class GC, class Key, class T, class Traits>
  bool try_get(cds::container::FeldmanHashMap<GC, Key, T, Traits>& hash_map, std::uint64_t key) {
    return hash_map.find(key, [](auto& /*val*/){});
  }
}
#endif