Skip to main content

algorithms Namespace

Definition

namespace helios::core::algorithms { ... }

Functions Index

constexpr uint32_tfnv1a_hash (const std::string_view str) noexcept

Computes a 32-bit FNV-1a hash from a string. More...

Functions

fnv1a_hash()

uint32_t helios::core::algorithms::fnv1a_hash (const std::string_view str)
nodiscard constexpr noexcept

Computes a 32-bit FNV-1a hash from a string.

Implements the Fowler–Noll–Vo hash function (FNV-1a variant), a fast, non-cryptographic hash suitable for hash tables and identifier generation. The function is `constexpr`, enabling compile-time hashing of string literals.

## Algorithm

1. Initialize hash with FNV offset basis (2166136261) 2. For each byte: XOR with hash, then multiply by FNV prime (16777619)

## Usage

```cpp // Compile-time hash for type-safe IDs constexpr uint32_t id = fnv1a_hash("enemy_spawn");

// Used internally by strongly-typed ID constructors constexpr GameObjectPoolId POOL{"bullets"}; // calls fnv1a_hash ```

Parameters
str

The string view to hash.

Returns

32-bit hash value.

info

This is not a cryptographic hash. Do not use for security purposes.

See Also

https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function

See Also

GameObjectPoolId

See Also

SpawnProfileId

See Also

SpawnRuleId

Definition at line 50 of file algorithms.ixx.

50 [[nodiscard]] constexpr uint32_t fnv1a_hash(const std::string_view str) noexcept {
51 uint32_t hash = 2166136261U;
52 for (char c: str) {
53 hash ^= static_cast<uint8_t>(c);
54 hash *= 16777619U;
55 }
56 return hash;
57 }

Referenced by helios::core::data::StrongId< PrefabIdTag, uint32_t >::StrongId.


The documentation for this namespace was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.