hash_mix.hpp 992 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef BOOST_UUID_DETAIL_HASH_MIX_INCLUDED
  2. #define BOOST_UUID_DETAIL_HASH_MIX_INCLUDED
  3. // Copyright 2024 Peter Dimov
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #include <cstdint>
  7. namespace boost {
  8. namespace uuids {
  9. namespace detail {
  10. // The multipliers are 32 bit, which makes the product
  11. // easier to compute on 32 bit platforms.
  12. //
  13. // The mixing functions have been created with
  14. // https://github.com/skeeto/hash-prospector
  15. // prospector -p mul,xorr -t 1000
  16. // score = 592.20293470138972
  17. inline std::uint64_t hash_mix_mx( std::uint64_t x ) noexcept
  18. {
  19. x *= 0xD96AAA55;
  20. x ^= x >> 16;
  21. return x;
  22. }
  23. // prospector -p mul:0xD96AAA55,xorr:16,mul,xorr -t 1000
  24. // score = 79.5223047689704
  25. // (with mx prepended)
  26. inline std::uint64_t hash_mix_fmx( std::uint64_t x ) noexcept
  27. {
  28. x *= 0x7DF954AB;
  29. x ^= x >> 16;
  30. return x;
  31. }
  32. } // detail
  33. } // uuids
  34. } // boost
  35. #endif // #ifndef BOOST_UUID_DETAIL_HASH_MIX_INCLUDED