195
52
/**
53
* Value - type of the value stored in hashmap
54
* N - number of buckets in hashmap
55
*/
56
template
57
class simple_kv {
58
private:
59
using key_type = pmem::obj::string;
60
using bucket_type = pmem::obj::vector<
61
std::pair>;
62
using bucket_array_type = pmem::obj::array;
63
using value_vector = pmem::obj::vector;
64
65
bucket_array_type buckets;
66
value_vector values;
67
68
public:
69
simple_kv() = default;
70
71
const Value &
72
get(const std::string &key) const
73
{
74
auto index = std::hash{}(key) % N;
75
76
for (const auto &e : buckets[index]) {
77
if (e.first == key)
78
return values[e.second];
79
}
80
81
throw std::out_of_range("no entry in simplekv");
82
}
83
Chapter 11 Designing Data struCtures for persistent MeMory
52
/**
53
* Value - type of the value stored in hashmap
54
* N - number of buckets in hashmap
55
*/
56
template
57
class simple_kv {
58
private:
59
using key_type = pmem::obj::string;
60
using bucket_type = pmem::obj::vector<
61
std::pair
62
using bucket_array_type = pmem::obj::array
63
using value_vector = pmem::obj::vector
64
65
bucket_array_type buckets;
66
value_vector values;
67
68
public:
69
simple_kv() = default;
70
71
const Value &
72
get(const std::string &key) const
73
{
74
auto index = std::hash
75
76
for (const auto &e : buckets[index]) {
77
if (e.first == key)
78
return values[e.second];
79
}
80
81
throw std::out_of_range("no entry in simplekv");
82
}
83
Chapter 11 Designing Data struCtures for persistent MeMory
