200
108 /* get pool on which persistent data resides */
109
auto pop = pmem::obj::pool_by_vptr(data);
110
111
/* search for element with specified key - if found
112
* update its value in a transaction */
113
for (const auto &e : buckets[index]) {
114
if (e.first == key) {
115
pmem::obj::transaction::run(pop, [&] {
116
data->values[e.second] = val;
117
});
118
119
return;
120
}
121
}
122
123 /* if there is no element with specified key, insert new value
124
* to the end of values vector and key to keys vector
125
* in a transaction */
126
pmem::obj::transaction::run(pop, [&] {
127
data->values.emplace_back(val);
128
data->keys.emplace_back(key);
129
});
130
131
buckets[index].emplace_back(key, data->values.size() - 1);
132 }
133 };
134
135 /**
136 * Class which is stored on persistent memory.
137 * Value - type of the value stored in hashmap
138 * N - number of buckets in hashmap
139 */
140 template
141 struct simple_kv_persistent {
142 using key_type = pmem::obj::string;
Chapter 11 Designing Data struCtures for persistent MeMory
108 /* get pool on which persistent data resides */
109
auto pop = pmem::obj::pool_by_vptr(data);
110
111
/* search for element with specified key - if found
112
* update its value in a transaction */
113
for (const auto &e : buckets[index]) {
114
if (e.first == key) {
115
pmem::obj::transaction::run(pop, [&] {
116
data->values[e.second] = val;
117
});
118
119
return;
120
}
121
}
122
123 /* if there is no element with specified key, insert new value
124
* to the end of values vector and key to keys vector
125
* in a transaction */
126
pmem::obj::transaction::run(pop, [&] {
127
data->values.emplace_back(val);
128
data->keys.emplace_back(key);
129
});
130
131
buckets[index].emplace_back(key, data->values.size() - 1);
132 }
133 };
134
135 /**
136 * Class which is stored on persistent memory.
137 * Value - type of the value stored in hashmap
138 * N - number of buckets in hashmap
139 */
140 template
141 struct simple_kv_persistent {
142 using key_type = pmem::obj::string;
Chapter 11 Designing Data struCtures for persistent MeMory
