You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repository aims to provide a set of excellent **hash map** implementations, as well as a **btree** alternative to std::map and std::set, with the following characteristics:
10
+
This repository aims to provide a set of excellent **hash map** implementations, as well as a **btree** alternative to std::map and std::set, with the following characteristics:
11
11
12
12
-**Header only**: nothing to build, just copy the `parallel_hashmap` directory to your project and you are good to go.
13
13
@@ -48,7 +48,15 @@ Copy the parallel_hashmap directory to your project. Update your include path. T
48
48
49
49
If you are using Visual Studio, you probably want to add `phmap.natvis` to your projects. This will allow for a clear display of the hash table contents in the debugger.
50
50
51
-
> A cmake configuration files (CMakeLists.txt) is provided for building the tests and examples. Command for building and running the tests is: `mkdir build && cd build && cmake -DPHMAP_BUILD_TESTS=ON -DPHMAP_BUILD_EXAMPLES=ON .. && cmake --build . && make test`
51
+
> A cmake configuration files (CMakeLists.txt) is provided for building the tests and examples. Command for building and running the tests is:
std::cout << "bill's email is: " << email["bill"] << "\n";
81
-
89
+
82
90
return 0;
83
91
}
84
92
```
@@ -115,8 +123,8 @@ The full types with template parameters can be found in the [parallel_hashmap/ph
115
123
116
124
- The `parallel` hash maps are preferred when you have a few hash maps that will store a very large number of values. The `non-parallel` hash maps are preferred if you have a large number of hash maps, each storing a relatively small number of values.
117
125
118
-
- The benefits of the `parallel` hash maps are:
119
-
a. reduced peak memory usage (when resizing), and
126
+
- The benefits of the `parallel` hash maps are:
127
+
a. reduced peak memory usage (when resizing), and
120
128
b. multithreading support (and inherent internal parallelism)
121
129
122
130
**Key decision points for btree containers:**
@@ -139,7 +147,7 @@ When an ordering is not needed, a hash container is typically a better choice th
139
147
140
148
- The Abseil hash tables internally randomize a hash seed, so that the table iteration order is non-deterministic. This can be useful to prevent *Denial Of Service* attacks when a hash table is used for a customer facing web service, but it can make debugging more difficult. The *phmap* hashmaps by default do **not** implement this randomization, but it can be enabled by adding `#define PHMAP_NON_DETERMINISTIC 1` before including the header `phmap.h` (as is done in raw_hash_set_test.cc).
141
149
142
-
- Unlike the Abseil hash maps, we do an internal mixing of the hash value provided. This prevents serious degradation of the hash table performance when the hash function provided by the user has poor entropy distribution. The cost in performance is very minimal, and this helps provide reliable performance even with *imperfect* hash functions.
150
+
- Unlike the Abseil hash maps, we do an internal mixing of the hash value provided. This prevents serious degradation of the hash table performance when the hash function provided by the user has poor entropy distribution. The cost in performance is very minimal, and this helps provide reliable performance even with *imperfect* hash functions.
143
151
144
152
145
153
## Memory usage
@@ -189,10 +197,10 @@ In order to use a flat_hash_set or flat_hash_map, a hash function should be prov
189
197
190
198
- Provide a hash functor via the HashFcn template parameter
191
199
192
-
- As with boost, you may add a `hash_value()` friend function in your class.
200
+
- As with boost, you may add a `hash_value()` friend function in your class.
The `std::hash` specialization for `Person` combines the hash values for both first and last name and age, using the convenient phmap::HashState() function, and returns the combined hash value.
264
+
The `std::hash` specialization for `Person` combines the hash values for both first and last name and age, using the convenient phmap::HashState() function, and returns the combined hash value.
257
265
258
266
### file "main.cpp"
259
267
@@ -268,7 +276,7 @@ int main()
268
276
// As we have defined a specialization of std::hash() for Person,
269
277
// we can now create sparse_hash_set or sparse_hash_map of Persons
@@ -287,7 +295,7 @@ Parallel Hashmap containers follow the thread safety rules of the Standard C++ l
287
295
288
296
- A single phmap hash table is thread safe for reading from multiple threads. For example, given a hash table A, it is safe to read A from thread 1 and from thread 2 simultaneously.
289
297
290
-
- If a single hash table is being written to by one thread, then all reads and writes to that hash table on the same or other threads must be protected. For example, given a hash table A, if thread 1 is writing to A, then thread 2 must be prevented from reading from or writing to A.
298
+
- If a single hash table is being written to by one thread, then all reads and writes to that hash table on the same or other threads must be protected. For example, given a hash table A, if thread 1 is writing to A, then thread 2 must be prevented from reading from or writing to A.
291
299
292
300
- It is safe to read and write to one instance of a type even if another thread is reading or writing to a different instance of the same type. For example, given hash tables A and B of the same type, it is safe if A is being written in thread 1 and B is being read in thread 2.
293
301
@@ -304,4 +312,4 @@ While C++ is the native language of the Parallel Hashmap, we welcome bindings ma
304
312
305
313
## Acknowledgements
306
314
307
-
Many thanks to the Abseil developers for implementing the swiss table and btree data structures (see [abseil-cpp](https://github.com/abseil/abseil-cpp)) upon which this work is based, and to Google for releasing it as open-source.
315
+
Many thanks to the Abseil developers for implementing the swiss table and btree data structures (see [abseil-cpp](https://github.com/abseil/abseil-cpp)) upon which this work is based, and to Google for releasing it as open-source.
0 commit comments