Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit cf343ab

Browse files
hashmap: minor docs updates
1 parent 55351ae commit cf343ab

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

examples/concurrent_hash_map/concurrent_hash_map.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515

1616
using namespace pmem::obj;
1717

18-
/* In this example we will be using concurrent_hash_map with p<int> type for
19-
* both keys and values */
18+
/* In this example we use concurrent_hash_map with p<int> type as
19+
* both keys and values. */
2020
using hashmap_type = concurrent_hash_map<p<int>, p<int>>;
2121

2222
const int THREADS_NUM = 30;
2323
const bool remove_hashmap = false;
2424

2525
/* This is basic example and we only need to use concurrent_hash_map. Hence we
26-
* will correlate memory pool root object with single instance of persistent
27-
* pointer to hasmap_type */
26+
* correlate memory pool root object with a single instance of persistent
27+
* pointer to hashmap_type. */
2828
struct root {
2929
persistent_ptr<hashmap_type> pptr;
3030
};
@@ -69,7 +69,7 @@ main(int argc, char *argv[])
6969

7070
r->runtime_initialize();
7171

72-
/* defragment the whole pool at the beginning */
72+
/* Defragment the whole pool at the beginning. */
7373
try {
7474
r->defragment();
7575
} catch (const pmem::defrag_error &e) {
@@ -84,8 +84,8 @@ main(int argc, char *argv[])
8484
std::vector<std::thread> threads;
8585
threads.reserve(static_cast<size_t>(THREADS_NUM));
8686

87-
/* Insert THREADS_NUM / 3 key-value pairs to the hashmap. This
88-
* operation is thread-safe. */
87+
/* Start THREADS_NUM/3 threads to insert key-value pairs
88+
* to the hashmap. This operation is thread-safe. */
8989
for (int i = 0; i < THREADS_NUM / 3; ++i) {
9090
threads.emplace_back([&]() {
9191
for (int i = 0; i < 10 * THREADS_NUM; ++i) {
@@ -95,8 +95,8 @@ main(int argc, char *argv[])
9595
});
9696
}
9797

98-
/* Erase THREADS_NUM /3 key-value pairs from the hashmap. This
99-
* operation is thread-safe. */
98+
/* Start THREADS_NUM/3 threads to erase key-value pairs
99+
* from the hashmap. This operation is thread-safe. */
100100
for (int i = 0; i < THREADS_NUM / 3; ++i) {
101101
threads.emplace_back([&]() {
102102
for (int i = 0; i < 10 * THREADS_NUM; ++i) {
@@ -105,8 +105,9 @@ main(int argc, char *argv[])
105105
});
106106
}
107107

108-
/* Check if given key is in the hashmap. For the time of an
109-
* accessor life, the read-write lock is taken on the item. */
108+
/* Start THREADS_NUM/3 threads to check if given key is
109+
* in the hashmap. For the time of an accessor life,
110+
* the read-write lock is taken on the item. */
110111
for (int i = 0; i < THREADS_NUM / 3; ++i) {
111112
threads.emplace_back([&]() {
112113
for (int i = 0; i < 10 * THREADS_NUM; ++i) {
@@ -127,7 +128,7 @@ main(int argc, char *argv[])
127128
t.join();
128129
}
129130
try {
130-
/* defragment the whole pool at the end */
131+
/* Defragment the whole pool at the end. */
131132
map.defragment();
132133
} catch (const pmem::defrag_error &e) {
133134
std::cerr << "Defragmentation exception: " << e.what()
@@ -148,7 +149,7 @@ main(int argc, char *argv[])
148149
}
149150
/* Erase remaining itemes in map. This function is not
150151
* thread-safe, hence the function is being called only after
151-
* thread execution has completed. */
152+
* execution of all threads has completed. */
152153
try {
153154
map.clear();
154155
} catch (const pmem::transaction_out_of_memory &e) {
@@ -162,14 +163,14 @@ main(int argc, char *argv[])
162163
}
163164

164165
/* If hash map is to be removed, free_data() method should be
165-
* called first. Otherwise, if deallocating internal hash map
166-
* metadata in a destructor fail program might terminate. */
166+
* called first. Otherwise, program might terminate, if
167+
* deallocating internal hash map metadata in a destructor
168+
* fails. */
167169
if (remove_hashmap) {
168170
map.free_data();
169171

170172
/* map.clear() // WRONG
171-
* After free_data() concurrent hash map cannot be used
172-
* anymore! */
173+
* After free_data() hash map cannot be used anymore! */
173174

174175
transaction::run(pop, [&] {
175176
delete_persistent<hashmap_type>(r);

include/libpmemobj++/container/concurrent_hash_map.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ struct hash_map_node {
333333

334334
/**
335335
* The class provides the way to access certain properties of segments
336-
* used by hash map
336+
* used by hash map.
337337
*/
338338
template <typename Bucket>
339339
class segment_traits {
@@ -1319,7 +1319,7 @@ class hash_map_base {
13191319

13201320
/**
13211321
* Swap hash_map_base
1322-
* @throws std::transaction_error in case of PMDK transaction failed
1322+
* @throw std::transaction_error in case of PMDK transaction failed
13231323
*/
13241324
void
13251325
internal_swap(hash_map_base<Key, T, mutex_t, scoped_t> &table)
@@ -1575,7 +1575,7 @@ operator!=(const hash_map_iterator<Container, M> &i,
15751575
* Persistent memory aware implementation of Intel TBB concurrent_hash_map.
15761576
* The implementation is based on a concurrent hash table algorithm
15771577
* (https://arxiv.org/ftp/arxiv/papers/1509/1509.02235.pdf) where elements
1578-
* assigned to buckets based on a hash code are calculated from a key.
1578+
* are assigned to buckets based on a hash code calculated from a key.
15791579
* In addition to concurrent find, insert, and erase operations, the algorithm
15801580
* employs resizing and on-demand per-bucket rehashing. The hash table consists
15811581
* of an array of buckets, and each bucket consists of a list of nodes and a
@@ -2273,7 +2273,7 @@ class concurrent_hash_map
22732273
* Clear hash map content
22742274
* Not thread safe.
22752275
*
2276-
* @throws pmem::transaction_error in case of PMDK transaction failure
2276+
* @throw pmem::transaction_error in case of PMDK transaction failure
22772277
*/
22782278
void clear();
22792279

@@ -2795,7 +2795,7 @@ class concurrent_hash_map
27952795
* Remove element with corresponding key
27962796
*
27972797
* @return true if element was deleted by this call
2798-
* @throws pmem::transaction_free_error in case of PMDK unable to free
2798+
* @throw pmem::transaction_free_error in case of PMDK unable to free
27992799
* the memory
28002800
* @throw pmem::transaction_scope_error if called inside transaction
28012801
*/
@@ -2884,7 +2884,7 @@ class concurrent_hash_map
28842884
* this function without constructing an instance of Key
28852885
*
28862886
* @return true if element was deleted by this call
2887-
* @throws pmem::transaction_free_error in case of PMDK unable to free
2887+
* @throw pmem::transaction_free_error in case of PMDK unable to free
28882888
* the memory
28892889
* @throw pmem::transaction_scope_error if called inside transaction
28902890
*/

0 commit comments

Comments
 (0)