hash-inl.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef HASH_INL_H_
  2. #error "Direct inclusion of this file is not allowed, include hash.h"
  3. // For the sake of sane code completion.
  4. #include "hash.h"
  5. #endif
  6. namespace NYT {
  7. ////////////////////////////////////////////////////////////////////////////////
  8. inline void HashCombine(size_t& h, size_t k)
  9. {
  10. static_assert(sizeof(size_t) == 8, "size_t must be 64 bit.");
  11. const size_t m = 0xc6a4a7935bd1e995ULL;
  12. const int r = 47;
  13. k *= m;
  14. k ^= k >> r;
  15. k *= m;
  16. h ^= k;
  17. h *= m;
  18. }
  19. template <class T>
  20. void HashCombine(size_t& h, const T& k)
  21. {
  22. HashCombine(h, THash<T>()(k));
  23. }
  24. ////////////////////////////////////////////////////////////////////////////////
  25. template <class TElement, class TUnderlying>
  26. TRandomizedHash<TElement, TUnderlying>::TRandomizedHash()
  27. : Seed_(RandomNumber<size_t>())
  28. { }
  29. template <class TElement, class TUnderlying>
  30. size_t TRandomizedHash<TElement, TUnderlying>::operator ()(const TElement& element) const
  31. {
  32. return Underlying_(element) + Seed_;
  33. }
  34. ////////////////////////////////////////////////////////////////////////////////
  35. } // namespace NYT