67 constexpr std::uint64_t offset = 14695981039346656037ull;
68 constexpr std::uint64_t prime = 1099511628211ull;
69 std::uint64_t value = offset;
70 for (
const std::byte
byte : bytes) {
71 value ^=
static_cast<std::uint64_t
>(byte);
74 return static_cast<std::size_t
>(value);
84 return seed ^ (next + 0x9e3779b97f4a7c15ull + (seed << 6) + (seed >> 2));
102 requires std::is_integral_v<T> || std::is_enum_v<T>
110 std::uint64_t widened = 0;
111 if constexpr (std::is_same_v<T, bool>)
112 widened = value ? 1ull : 0ull;
113 else if constexpr (std::is_enum_v<T>) {
114 using Underlying = std::underlying_type_t<T>;
115 widened =
static_cast<std::uint64_t
>(
static_cast<std::make_unsigned_t<Underlying>
>(
static_cast<Underlying
>(value)));
117 widened =
static_cast<std::uint64_t
>(
static_cast<std::make_unsigned_t<T>
>(value));
118 return HashBytes(std::as_bytes(std::span<const std::uint64_t>(&widened, 1)));
127 requires std::is_floating_point_v<T>
135 unsigned char bytes[
sizeof(T)] = {};
136 std::size_t used =
sizeof(T);
137 if constexpr (std::is_same_v<T, long double> &&
sizeof(
long double) > 10 && std::numeric_limits<long double>::digits == 64)
139 std::memcpy(bytes, &value, used);
140 return HashBytes(std::span<const std::byte>(
reinterpret_cast<const std::byte*
>(bytes), used));
Owned values that cross a DLL without the caller's CRT.
STORMBYTE_FORCE_INLINE std::size_t HashCombine(std::size_t seed, std::size_t next) noexcept
Mix an existing hash with another.
Definition hash.hxx:83
STORMBYTE_FORCE_INLINE std::size_t HashBytes(std::span< const std::byte > bytes) noexcept
Mix a byte range with FNV-1a.
Definition hash.hxx:66
Root namespace of the StormByte suite.
STORMBYTE_FORCE_INLINE std::size_t operator()(T value) const noexcept
Hash value.
Definition hash.hxx:109
STORMBYTE_FORCE_INLINE std::size_t operator()(T *value) const noexcept
Hash value.
Definition hash.hxx:155
Cross-module hash.
Definition hash.hxx:95
#define STORMBYTE_PUBLIC_TYPE
Definition visibility.h:57