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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

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

KeycardMaster
Item ESP & Unity UI Dev
MEMBER
Rep: 215
Join Date: Oct 2023
Posts: 19
Thanks: 54
1y ago · Nov 4, 2024 9:42 AM
#1
Here is a 5-line FNV-1a constexpr hash function that allows using string literals directly in C++ switch-case statements!
KeycardMaster | Keycard & Objective ESP Specialist
The following users thanked KeycardMaster for this post:
PixelCraft
ImGui UI Hacker
MEMBER
Rep: 344
Join Date: Mar 2022
Posts: 7
Thanks: 92
1y ago · Nov 4, 2024 2:24 PM
#2
Switching on string hashes: switch(HashConst(commandName)) { case HashConst("spawn"): ... } makes text dispatchers O(1) jump tables!
PixelCraft · ImGui UI Hacker
Creating custom Dear ImGui themes, graphs, docking layouts, ...
BlazorKing
Full-Stack C#
MEMBER
Rep: 199
Join Date: Oct 2023
Posts: 6
Thanks: 26
1y ago · Nov 4, 2024 5:24 PM
#3
Using uint32_t or uint64_t FNV-1a hash constants is completely evaluated at compile time with zero runtime cost.
BlazorKing · Full-Stack C#
Building real-time web applications and desktop tools with B...