diff --git a/README.md b/README.md index fecbe1f..f7f0654 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,11 @@ This repository aims to provide an set of excellent hash map implementations, wi - Not yet **Tested** ~~on Windows (vs2010-2015, g++), linux (g++, clang++) and MacOS (clang++)~~. +## Installation + +Copy the parallel_hashmap directory to your project. That's all. + +> The CMakeLists.txt are provided for building the tests and examples. ## Example diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index 13c5c06..1fe4a4f 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -2151,6 +2151,30 @@ private: } }; +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +constexpr size_t Group::kWidth; + +// Returns "random" seed. +inline size_t RandomSeed() +{ +#if PHMAP_HAVE_THREAD_LOCAL + static thread_local size_t counter = 0; + size_t value = ++counter; +#else // PHMAP_HAVE_THREAD_LOCAL + static std::atomic counter(0); + size_t value = counter.fetch_add(1, std::memory_order_relaxed); +#endif // PHMAP_HAVE_THREAD_LOCAL + return value ^ static_cast(reinterpret_cast(&counter)); +} + +bool ShouldInsertBackwards(size_t hash, ctrl_t* ctrl) +{ + // To avoid problems with weak hashes and single bit tests, we use % 13. + // TODO(kfm,sbenza): revisit after we do unconditional mixing + return (H1(hash, ctrl) ^ RandomSeed()) % 13 > 6; +} + // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- template