Skip to content

Commit

Permalink
Add preprocessor macro PHMAP_DISABLE_MIX (#259)
Browse files Browse the repository at this point in the history
* Add preporcessor define to disable mixing (`PHMAP_DISABLE_MIX`).

* Update `README.md`.
  • Loading branch information
greg7mdp authored Nov 2, 2024
1 parent debe606 commit a6ce083
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ When an ordering is not needed, a hash container is typically a better choice th

- 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).

- 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.
- 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. Disabling this mixing is possible by defining the preprocessor macro `PHMAP_DISABLE_MIX=1` before `phmap.h` is included, but it is not recommended.


## Memory usage
Expand Down
8 changes: 8 additions & 0 deletions parallel_hashmap/phmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,11 @@ class raw_hash_set
{
template <class K, class... Args>
size_t operator()(const K& key, Args&&...) const {
#if PHMAP_DISABLE_MIX
return h(key);
#else
return phmap_mix<sizeof(size_t)>()(h(key));
#endif
}
const hasher& h;
};
Expand Down Expand Up @@ -3749,7 +3753,11 @@ class parallel_hash_set
{
template <class K, class... Args>
size_t operator()(const K& key, Args&&...) const {
#if PHMAP_DISABLE_MIX
return h(key);
#else
return phmap_mix<sizeof(size_t)>()(h(key));
#endif
}
const hasher& h;
};
Expand Down

0 comments on commit a6ce083

Please sign in to comment.