Common/Hash: Add ComputeHash64 std::span interface

This commit is contained in:
Wunkolo 2024-03-02 10:47:33 -08:00
parent 69e758d738
commit 21bfc043f0

View File

@ -6,6 +6,7 @@
#include <cstddef> #include <cstddef>
#include <cstring> #include <cstring>
#include <span>
#include "common/cityhash.h" #include "common/cityhash.h"
#include "common/common_types.h" #include "common/common_types.h"
@ -21,6 +22,15 @@ static inline u64 ComputeHash64(const void* data, std::size_t len) noexcept {
return CityHash64(static_cast<const char*>(data), len); return CityHash64(static_cast<const char*>(data), len);
} }
/**
* Computes a 64-bit hash over the specified block of data
* @param data Block of data to compute hash over
* @returns 64-bit hash value that was computed over the data block
*/
static inline u64 ComputeHash64(std::span<const std::byte> data) noexcept {
return ComputeHash64(data.data(), data.size());
}
/** /**
* Computes a 64-bit hash of a struct. In addition to being trivially copyable, it is also critical * Computes a 64-bit hash of a struct. In addition to being trivially copyable, it is also critical
* that either the struct includes no padding, or that any padding is initialized to a known value * that either the struct includes no padding, or that any padding is initialized to a known value