C++20 compile-time XXH32() calculation #496
Labels
No labels
announcement
bug
build
CI
dependencies
documentation
duplicate
enhancement
experience feedback
feature request
github_actions
help wanted
install
invalid
Long-term
optimization
portability
question
target-specific
test issue
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-Cyan4973/xxHash#496
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is not an issue. Just for sharing my experiment. The following post demonstrates compile-time
XXH32()hash calculation in C++20 and itsconstexpr.But if you want to use compile-time xxHash now, please take a look at @ekpyron's excellent C++11 implementation of compile-time
XXH64(). It's better than my code in many aspects.What's this?
This code demonstrates compile-time XXH32 hash calculation in C++20.
"xxHash - Extremely Fast Hash algorithm".XXH32()when you defineINCLUDE_XXHASH.What's the point of this code?
When hash value becomes compile-time constant:
caselabel,static_assert()expression, etc.if constexpr ()is also useful.Since C++17/20 relaxed many restriction of
constexpr, this code is a naive version ofXXH32().So my point is, it's always nice to have naive/simple version of the code for clarity and testing.
It also will encourage other developers to implmenent the algorithm in different form and language.
See also
The code and result
Code, result and disassembly at Compiler Explorer
gist version of the code for convenience
Prerequisites
g++-10)Code
Build
pls. have tiny typo correction: ↥.