Hash.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Util/StdTypes.h>
  7. namespace anki {
  8. /// @addtogroup util_other
  9. /// @{
  10. /// Computes a hash of a buffer. This function implements the MurmurHash2 algorithm by Austin Appleby.
  11. /// @param[in] buffer The buffer to hash.
  12. /// @param bufferSize The size of the buffer.
  13. /// @param seed A unique seed.
  14. /// @return The hash.
  15. [[nodiscard]] ANKI_PURE U64 computeHash(const void* buffer, PtrSize bufferSize, U64 seed = 123);
  16. /// Computes a hash of a buffer. This function implements the MurmurHash2 algorithm by Austin Appleby.
  17. /// @param[in] buffer The buffer to hash.
  18. /// @param bufferSize The size of the buffer.
  19. /// @param prevHash The hash to append to.
  20. /// @return The new hash.
  21. [[nodiscard]] ANKI_PURE U64 appendHash(const void* buffer, PtrSize bufferSize, U64 prevHash);
  22. /// See computeHash.
  23. template<typename T>
  24. [[nodiscard]] ANKI_PURE U64 computeObjectHash(const T& obj, U64 seed = 123)
  25. {
  26. return computeHash(&obj, sizeof(obj), seed);
  27. }
  28. /// See appendHash.
  29. template<typename T>
  30. [[nodiscard]] ANKI_PURE U64 appendObjectHash(const T& obj, U64 prevHash)
  31. {
  32. return appendHash(&obj, sizeof(obj), prevHash);
  33. }
  34. /// @}
  35. } // end namespace anki