Skip to content

Commit a6ce083

Browse files
authored
Add preprocessor macro PHMAP_DISABLE_MIX (#259)
* Add preporcessor define to disable mixing (`PHMAP_DISABLE_MIX`). * Update `README.md`.
1 parent debe606 commit a6ce083

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ When an ordering is not needed, a hash container is typically a better choice th
147147

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

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

152152

153153
## Memory usage

parallel_hashmap/phmap.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,11 @@ class raw_hash_set
18921892
{
18931893
template <class K, class... Args>
18941894
size_t operator()(const K& key, Args&&...) const {
1895+
#if PHMAP_DISABLE_MIX
1896+
return h(key);
1897+
#else
18951898
return phmap_mix<sizeof(size_t)>()(h(key));
1899+
#endif
18961900
}
18971901
const hasher& h;
18981902
};
@@ -3749,7 +3753,11 @@ class parallel_hash_set
37493753
{
37503754
template <class K, class... Args>
37513755
size_t operator()(const K& key, Args&&...) const {
3756+
#if PHMAP_DISABLE_MIX
3757+
return h(key);
3758+
#else
37523759
return phmap_mix<sizeof(size_t)>()(h(key));
3760+
#endif
37533761
}
37543762
const hasher& h;
37553763
};

0 commit comments

Comments
 (0)