Skip to content

Engine → Core

hash.h

FNV-1a hashing. These are the engine's canonical content hashes: string_id, error categories, asset identity and the C# NameHash all use them, so the constants and the exact byte order are part of the ABI and must never change. Test vectors live in tests/core/foundation/test_hash.cpp and are mirrored by Conjure.Managed.

Constants

Name Type Value Description
hash::FNV1A32_OFFSET_BASIS inline constexpr u32 0x811C9DC5u
hash::FNV1A32_PRIME inline constexpr u32 0x01000193u
hash::FNV1A64_OFFSET_BASIS inline constexpr u64 0xCBF29CE484222325ull
hash::FNV1A64_PRIME inline constexpr u64 0x00000100000001B3ull

Functions

Public

hash::combine

[[nodiscard]] constexpr u64 combine(u64 seed, u64 value) noexcept;

Combines two 64-bit hashes order-dependently (boost::hash_combine style with a 64-bit mix).

hash::fnv1a32

[[nodiscard]] constexpr u32 fnv1a32(std::string_view text, u32 seed = FNV1A32_OFFSET_BASIS) noexcept;

32-bit FNV-1a of the UTF-8 bytes of a string. Usable in constant expressions.

[[nodiscard]] constexpr u32 fnv1a32(std::span<const std::byte> bytes, u32 seed = FNV1A32_OFFSET_BASIS) noexcept;

32-bit FNV-1a of a byte range.

hash::fnv1a32_step

[[nodiscard]] constexpr u32 fnv1a32_step(u32 hash, u8 byteValue) noexcept;

Continues a 32-bit FNV-1a hash with one more byte.

hash::fnv1a64

[[nodiscard]] constexpr u64 fnv1a64(std::string_view text, u64 seed = FNV1A64_OFFSET_BASIS) noexcept;

64-bit FNV-1a of the UTF-8 bytes of a string. Usable in constant expressions.

[[nodiscard]] constexpr u64 fnv1a64(std::span<const std::byte> bytes, u64 seed = FNV1A64_OFFSET_BASIS) noexcept;

64-bit FNV-1a of a byte range.

hash::fnv1a64_step

[[nodiscard]] constexpr u64 fnv1a64_step(u64 hash, u8 byteValue) noexcept;

Continues a 64-bit FNV-1a hash with one more byte.