Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Types::Util Namespace Reference

Functions

uint64_t INFINITY_API_PUBLIC hash64 (const char *s, size_t len)
 Computes a 64-bit hash of a byte sequence using CityHash64.
 

Function Documentation

◆ hash64()

uint64_t INFINITY_API_PUBLIC Infinity::Types::Util::hash64 ( const char *  s,
size_t  len 
)

Computes a 64-bit hash of a byte sequence using CityHash64.

Provides a fast, high-quality hash function based on Google's CityHash64 algorithm. CityHash is designed for speed on modern CPUs and produces well-distributed hash values suitable for hash tables, checksums, and fingerprinting.

This function is used throughout the Infinity Engine for:

  • Computing stable TypeID hashes from type name strings
  • Generating hash keys for data structures
  • Creating fingerprints for assets and procedural content
  • Building hash-based lookups in registries

The hash is deterministic (same input always produces same output) and stable across platforms and runs, making it suitable for serialization and persistent storage where consistent hash values are required.

Example usage:

// Hash a type name for TypeID
const char* typeName = "Infinity::Types::Mesh";
uint64_t typeHash = hash64(typeName, std::strlen(typeName));
// Hash binary data
std::vector<uint8_t> data = {1, 2, 3, 4, 5};
uint64_t dataHash = hash64(
reinterpret_cast<const char*>(data.data()),
data.size()
);
// Hash a string
std::string str = "procedural_mesh_v2";
uint64_t strHash = hash64(str.c_str(), str.length());
uint64_t INFINITY_API_PUBLIC hash64(const char *s, size_t len)
Computes a 64-bit hash of a byte sequence using CityHash64.
Parameters
sPointer to the byte sequence to hash.
lenLength of the byte sequence in bytes.
Returns
64-bit hash value.
Note
The hash algorithm is CityHash64, which is optimized for x86-64 processors but works correctly on all platforms.
Hash values are stable and deterministic - the same input will always produce the same hash value across different runs and platforms.
For empty input (len = 0), the function returns a well-defined hash value.
The pointer s must be valid for len bytes; passing nullptr with len > 0 results in undefined behavior.
See also
TypeID::create_stable_hash