Skip to main content
Version: Latest 🚧

Hash Utilities

The Hash and StaticHash utilities provide mechanisms for generating hash values from strings. They are useful for applications requiring unique identifiers or efficient lookups.

Note: They are global functions in the global namespace. You can just call Hash or StaticHash directly.

The source file for this utility is located in os/framework/Hash.h


Functions​

Hash​

inline uint32_t Hash(string str);

Generates a hash value for a given string using the FNV-1a hash algorithm.

Parameters:

  • str (string): The input string to hash.

Returns:

  • uint32_t: The hash value of the input string.

Example Usage:

string myString = "example";
uint32_t hashValue = Hash(myString);

StaticHash​

template <uint32_t N>
constexpr static uint32_t StaticHash(const char (&str)[N]);

Generates a compile-time hash value for a given string literal. Uses the HashHelper mechanism to compute the hash.

Parameters:

  • str (const char (&)[N]): The input string literal to hash.

Returns:

  • uint32_t: The compile-time hash value of the input string.

Example Usage:

constexpr uint32_t hashValue = StaticHash("example");

Comments