hash.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <util/generic/hash.h>
  3. #include <util/random/random.h>
  4. namespace NYT {
  5. ////////////////////////////////////////////////////////////////////////////////
  6. //! Updates #h with #k.
  7. //! Cf. |boost::hash_combine|.
  8. void HashCombine(size_t& h, size_t k);
  9. //! Updates #h with the hash of #k.
  10. //! Cf. |boost::hash_combine|.
  11. template <class T>
  12. void HashCombine(size_t& h, const T& k);
  13. //! Computes the hash of #value handling NaN values gracefully
  14. //! (returning the same constant for all NaNs).
  15. //! If |T| is not a floating-point type, #NaNSafeHash is equivalent to #THash.
  16. template <class T>
  17. size_t NaNSafeHash(const T& value);
  18. ////////////////////////////////////////////////////////////////////////////////
  19. //! Provides a hasher that randomizes the results of another one.
  20. template <class TElement, class TUnderlying = ::THash<TElement>>
  21. class TRandomizedHash
  22. {
  23. public:
  24. TRandomizedHash();
  25. size_t operator()(const TElement& element) const;
  26. private:
  27. size_t Seed_;
  28. TUnderlying Underlying_;
  29. };
  30. ////////////////////////////////////////////////////////////////////////////////
  31. } // namespace NYT
  32. #define HASH_INL_H_
  33. #include "hash-inl.h"
  34. #undef HASH_INL_H_