Repository navigation
HashHelper
HashHelper provides high-performance FNV-1a hashing utilities with caching support for both 32-bit and 64-bit hash values. It is used extensively throughout the engine for fast string identification, dictionary lookups, and cache keys.
| Feature | Description |
|---|---|
| Algorithm | FNV-1a (Fowler-Noll-Vo) non-cryptographic hash |
| Hash Sizes | 32-bit and 64-bit variants |
| Caching | Thread-safe caching for frequently accessed strings |
| Performance | Stack allocation for small strings, array pooling for large strings |
| Enum Support | Hash enum values directly |
| Thread Safety | Fully thread-safe |
FNV-1a is a non-cryptographic hash algorithm designed for speed. It produces high-quality hash values suitable for hash tables, dictionaries, and other data structures. It is significantly faster than cryptographic hashes like SHA-256 or MD5.
| Use Case | Recommended |
|---|---|
| Dictionary keys | ✅ |
| Cache lookups | ✅ |
| String identification | ✅ |
| Security-sensitive | ❌ (use cryptographic hashes) |
The engine relies on HashHelper as a core performance optimization. Repeated string hashing and comparison add work to hot lookup paths. VOID can cache a numeric identifier once and then use that value for dictionary lookups, cache accesses, and identifier matching.
The 32-bit variant is used for internal system identifiers where speed is critical and collision probability is acceptable. When you load an LDtk map, the engine needs to quickly find levels by name, layers by ID, and tilesets by name. LDtk settings use hashes to look up field values without string comparisons. Spritesheet entries are stored by hash so sprite bounds, patches, and pivots can be retrieved instantly. JsonHelper uses hashes when parsing LDtk field instances to look up settings by identifier. All of these lookups happen frequently during asset loading and runtime access, so the performance gain from hashing is substantial.
The 64-bit variant is used for global identifiers where collision probability must be extremely low. AssetManager uses hashes to look up assets in the cache by path. LDtkMap uses hashes for entity IDs since these identifiers are unique across the entire project. BeaconManager uses hashes for topic names in the pub/sub system so events can be routed quickly. InputAction converts action names and enum values into cached 64-bit IDs for its action registry and action-state snapshots. Game and GameSettings use hashes for version verification during build validation. ContentTypeWriterReader uses hashes for save file version verification to prevent loading saves from incompatible game versions.
See Input for action lookup behavior and Beacon Manager for hashed Beacon topics.
HashHelper keeps the underlying FNV work allocation-conscious. Small strings are encoded into stack storage, while larger strings rent temporary buffers from ArrayPool. Cached calls reuse the previously computed hash value instead of recomputing the FNV hash for the same string.
HashHelper is fully thread-safe. All caching operations use concurrent collections, and the methods themselves are stateless.
Gets a cached 32-bit hash for the specified input. The hash is computed once for a new string key and reused on later lookups.
uint hash = HashHelper.Cache32("Hello World");
uint enumHash = HashHelper.Cache32(MyEnum.Value);Gets a cached 64-bit hash for the specified input. The hash is computed once for a new string key and reused on later lookups.
ulong hash = HashHelper.Cache64("Hello World");
ulong enumHash = HashHelper.Cache64(MyEnum.Value);Computes a 32-bit FNV-1a hash from a string, byte array, or span without caching.
uint hash = HashHelper.Hash32("Hello World");
byte[] data = Encoding.UTF8.GetBytes("Hello World");
uint hash2 = HashHelper.Hash32(data);Computes a 64-bit FNV-1a hash from a string, byte array, or span without caching.
ulong hash = HashHelper.Hash64("Hello World");
byte[] data = Encoding.UTF8.GetBytes("Hello World");
ulong hash2 = HashHelper.Hash64(data);Home · Getting Started · Rendering · Custom Renderers · GitHub · Report an Issue
Built with VOID Engine · MIT License
- Coroutines
- State Machine
- Save System
- Pathfinding
- Logging
- Beacon Manager
- Beacon Event System
- Discoverable System
- Instance Helper
- BeaconManager Extensions
- BeaconHandle Extensions
- Enum Extensions
- String Extensions
- Int Extensions
- Float Extensions
- IEnumerable Extensions
- Random Extensions
- Sound Extensions
- Font Extensions