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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

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

DirectX_Pro
DirectX 11/12 Engineer
MEMBER
Rep: 69
Join Date: Aug 2021
Posts: 6
Thanks: 93
5y ago · Aug 13, 2021 5:51 PM
#1
Here is a 5-line FNV-1a constexpr hash function that allows using string literals directly in C++ switch-case statements!
DirectX_Pro · DirectX 11/12 Engineer
Direct3D pipelines, compute shaders, and swap chain presenta...
The following users thanked DirectX_Pro for this post:
ImGuiArtist
Modern UI Designer
MEMBER
Rep: 227
Join Date: Dec 2025
Posts: 6
Thanks: 63
5y ago · Aug 13, 2021 9:27 PM
#2
Switching on string hashes: switch(HashConst(commandName)) { case HashConst("spawn"): ... } makes text dispatchers O(1) jump tables!
ImGuiArtist · Modern UI Designer
Dark glassmorphism, animated sliders, and custom font render...
GameDevSam
Indie Game Developer
VIP
Rep: 90
Join Date: Jul 2020
Posts: 8
Thanks: 22
5y ago · Aug 15, 2021 1:27 AM
#3
Using uint32_t or uint64_t FNV-1a hash constants is completely evaluated at compile time with zero runtime cost.
GameDevSam · Indie Game Developer
Solo indie dev building games with Unity, Monogame, and cust...