cf::hash¶
Functions¶
| Name | |
|---|---|
| constexpruint64_t | fnv1a64(constchar * str, uint64_t seed =fnv1a64_offset_basis) FNV-1a 64-bit hash constexpr implementation. |
| constexpruint64_t | fnv1a64(std::string_view sv, uint64_t seed =fnv1a64_offset_basis) FNV-1a 64-bit hash for std::string_view (runtime/constexpr). |
| constexpruint32_t | fnv1a32(constchar * str, uint32_t seed =fnv1a32_offset_basis) FNV-1a 32-bit hash constexpr implementation. |
| constexpruint32_t | fnv1a32(std::string_view sv, uint32_t seed =fnv1a32_offset_basis) FNV-1a 32-bit hash for std::string_view. |
| constexpruint64_t | operator""_hash(constchar * str, size_t ) User-defined literal for compile-time FNV-1a 64-bit hashing. |
Attributes¶
| Name | |
|---|---|
| constexpruint64_t | fnv1a64_offset_basis FNV-1a 64-bit offset basis. |
| constexpruint64_t | fnv1a64_prime FNV-1a 64-bit prime. |
| constexpruint32_t | fnv1a32_offset_basis FNV-1a 32-bit offset basis. |
| constexpruint32_t | fnv1a32_prime FNV-1a 32-bit prime. |
Functions Documentation¶
function fnv1a64¶
FNV-1a 64-bit hash constexpr implementation.
Parameters:
- str Null-terminated string to hash.
- seed Starting hash value (default: FNV offset basis).
Exceptions:
- None.
Return: 64-bit hash value.
Since: 0.1
Note: The hash is computed at compile time for string literals.
Warning: Different inputs may produce the same hash (collision). Use string comparison as fallback when hashes match.
Computes FNV-1a hash at compile time for string literals. The FNV-1a algorithm provides excellent distribution and minimal collisions for string identifiers.
constexpr uint64_t h1 = fnv1a64("TokenA"); // Compile-time
constexpr uint64_t h2 = fnv1a64("TokenB"); // Different value
static_assert(h1 != h2, "Hash collision!");
function fnv1a64¶
FNV-1a 64-bit hash for std::string_view (runtime/constexpr).
Parameters:
- sv String view to hash.
- seed Starting hash value (default: FNV offset basis).
Exceptions:
- None.
Return: 64-bit hash value.
Since: 0.1
Note: This function can be evaluated at compile time if the input is a constant expression.
Warning: Different inputs may produce the same hash (collision). Use string comparison as fallback when hashes match.
function fnv1a32¶
FNV-1a 32-bit hash constexpr implementation.
Parameters:
- str Null-terminated string to hash.
- seed Starting hash value (default: FNV offset basis).
Exceptions:
- None.
Return: 32-bit hash value.
Since: 0.1
Note: The hash is computed at compile time for string literals.
Warning: Different inputs may produce the same hash (collision). Use string comparison as fallback when hashes match.
function fnv1a32¶
FNV-1a 32-bit hash for std::string_view.
Parameters:
- sv String view to hash.
- seed Starting hash value (default: FNV offset basis).
Exceptions:
- None.
Return: 32-bit hash value.
Since: 0.1
Note: This function can be evaluated at compile time if the input is a constant expression.
Warning: Different inputs may produce the same hash (collision). Use string comparison as fallback when hashes match.
function operator""_hash¶
User-defined literal for compile-time FNV-1a 64-bit hashing.
Parameters:
- str Null-terminated string to hash.
- len Length of the string (unused, required by UDL syntax).
Exceptions:
- None.
Return: 64-bit hash value.
Since: 0.1
Note: This function is constexpr and evaluated at compile time.
Warning: None.
Enables syntax: "TokenName"_hash for compile-time hash computation.
constexpr uint64_t h = "MyToken"_hash; // Compile-time hash
static_assert(h == fnv1a64("MyToken"), "Hash must match");
Attributes Documentation¶
variable fnv1a64_offset_basis¶
FNV-1a 64-bit offset basis.
Since: 0.1
variable fnv1a64_prime¶
FNV-1a 64-bit prime.
Since: 0.1
variable fnv1a32_offset_basis¶
FNV-1a 32-bit offset basis.
Since: 0.1
variable fnv1a32_prime¶
FNV-1a 32-bit prime.
Since: 0.1
Updated on 2026-03-09 at 10:14:00 +0000