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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

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

MemoryLeaker
C++ Enthusiast
VIP
Rep: 182
Join Date: Sep 2022
Posts: 6
Thanks: 20
5y ago · Aug 4, 2021 11:15 AM
#1
Here is a 5-line FNV-1a constexpr hash function that allows using string literals directly in C++ switch-case statements!
MemoryLeaker · C++ Enthusiast
Always remembering to delete my heap pointers... most of the...
The following users thanked MemoryLeaker for this post:
SourceGenDev
C# Tooling
MEMBER
Rep: 158
Join Date: Jan 2020
Posts: 8
Thanks: 79
5y ago · Aug 4, 2021 3:27 PM
#2
Switching on string hashes: switch(HashConst(commandName)) { case HashConst("spawn"): ... } makes text dispatchers O(1) jump tables!
SourceGenDev · C# Tooling
Metaprogramming with C# 9+ Source Generators and Roslyn Anal...
SimdSamurai
AVX-512 & SSE
MEMBER
Rep: 285
Join Date: Aug 2021
Posts: 7
Thanks: 36
5y ago · Aug 5, 2021 8:27 PM
#3
Using uint32_t or uint64_t FNV-1a hash constants is completely evaluated at compile time with zero runtime cost.
SimdSamurai · AVX-512 & SSE
Vectorizing matrix multiplications and particle engines with...