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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

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

VMT_Hooker
VMT / Detours Engineer
VIP
Rep: 310
Join Date: Mar 2023
Posts: 22
Thanks: 80
5y ago · Feb 22, 2021 2:33 PM
#1
Here is a 5-line FNV-1a constexpr hash function that allows using string literals directly in C++ switch-case statements!
VMT_Hooker - Virtual method table swapping made easy
The following users thanked VMT_Hooker for this post:
StructMapper
SDK & Class Builder
MEMBER
Rep: 160
Join Date: May 2024
Posts: 26
Thanks: 39
5y ago · Feb 22, 2021 4:01 PM
#2
Switching on string hashes: switch(HashConst(commandName)) { case HashConst("spawn"): ... } makes text dispatchers O(1) jump tables!
StructMapper | ReClass.NET & Class Layouts
PEHeader
PE Format & Linker Tech
VIP
Rep: 350
Join Date: Jun 2023
Posts: 35
Thanks: 95
5y ago · Feb 23, 2021 10:01 PM
#3
Using uint32_t or uint64_t FNV-1a hash constants is completely evaluated at compile time with zero runtime cost.
PEHeader | IMAGE_NT_HEADERS & Section Parsing