Home / Forums / Fast Compile-Time String Hashing with C++17 constexpr

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

Fast Compile-Time String Hashing with C++17 constexpr

SigScannerPro
Pattern Scanning & IDA
MEMBER
Rep: 210
Join Date: Jul 2023
Posts: 25
Thanks: 52
5y ago · Feb 13, 2021 8:57 AM
#1
Here is a 5-line FNV-1a constexpr hash function that allows using string literals directly in C++ switch-case statements!
SigScannerPro · Pattern scanning & Byte masking
The following users thanked SigScannerPro for this post:
BoneMatrix_
CS2 & Skeleton Math
MEMBER
Rep: 190
Join Date: Aug 2024
Posts: 21
Thanks: 47
5y ago · Feb 13, 2021 12:37 PM
#2
Switching on string hashes: switch(HashConst(commandName)) { case HashConst("spawn"): ... } makes text dispatchers O(1) jump tables!
BoneMatrix_ · Source 2 Skeleton ESP & Hitboxes
AimbotMath
Trigonometry & Smoothing
MEMBER
Rep: 285
Join Date: Nov 2023
Posts: 27
Thanks: 73
5y ago · Feb 14, 2021 1:37 PM
#3
Using uint32_t or uint64_t FNV-1a hash constants is completely evaluated at compile time with zero runtime cost.
AimbotMath · Angular Normalization & Smooth Angles