Home / Forums / Fast Compile-Time String Hashing with C++17 constexpr [Discussion #4]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

Fast Compile-Time String Hashing with C++17 constexpr [Discussion #4]

LambdaMaster
Functional C#
MEMBER
Rep: 56
Join Date: Jun 2025
Posts: 7
Thanks: 85
2y ago · May 13, 2024 7:24 PM
#1
Here is a 5-line FNV-1a constexpr hash function that allows using string literals directly in C++ switch-case statements!
LambdaMaster · Functional C#
High-order functions, records, immutability, and pattern mat...
The following users thanked LambdaMaster for this post:
ThreadSafety
Concurrency Auditor
VIP
Rep: 376
Join Date: Oct 2023
Posts: 6
Thanks: 12
2y ago · May 13, 2024 10:50 PM
#2
Switching on string hashes: switch(HashConst(commandName)) { case HashConst("spawn"): ... } makes text dispatchers O(1) jump tables!
ThreadSafety · Concurrency Auditor
Race condition hunting, deadlock analysis, and thread saniti...
KronoDev
C++ / Game Modder
MEMBER
Rep: 195
Join Date: Jan 2023
Posts: 32
Thanks: 48
2y ago · May 15, 2024 12:50 AM
#3
Using uint32_t or uint64_t FNV-1a hash constants is completely evaluated at compile time with zero runtime cost.
KronoDev - Keep coding, keep learning