From 5e8b6a9e5590fa8a0795c36ee5cd0a90dd7df5cb Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 29 Nov 2021 06:14:20 +0200 Subject: [PATCH] Add comment describing the origin of mix64_policy::apply_hash --- include/boost/unordered/detail/implementation.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/boost/unordered/detail/implementation.hpp b/include/boost/unordered/detail/implementation.hpp index b084bbc0..daf9b8f6 100644 --- a/include/boost/unordered/detail/implementation.hpp +++ b/include/boost/unordered/detail/implementation.hpp @@ -2632,6 +2632,11 @@ namespace boost { static inline SizeT apply_hash(Hash const& hf, T const& x) { SizeT key = hf(x); + + // "Integer Hash Function", Thomas Wang, 1997 + // https://gist.github.com/badboy/6267743 + // http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm + key = (~key) + (key << 21); // key = (key << 21) - key - 1; key = key ^ (key >> 24); key = (key + (key << 3)) + (key << 8); // key * 265