| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This is a C++20 constexpr implementation of the XXH3 64-bit variant of xxHash
Three functions are implemented: XXH3_64bits_const, XXH3_64bits_withSecret_const, XXH3_64bits_withSeed_const.
Also included is a unit test to ensure they produce exactly the same results as the xxHash library.
Credits to:
Basic interfaces mimic upstream interfaces.
Types T and S can be any of the following:
We are unable to provide a constexpr interface with parameter type const void* because of limitation imposed by the C++ standard, which apparently does not want constexpr evaluation to depend on byte representation. This means that we cannot directly hash, for example, a structure, at compile time, unless we explicitly copy it member-wise to an array of bytes and manually take care of memory layout (including padding) and endianness.
In a constexpr context, it is often more convenient to be able to pass the input bytes and length as one parameter. This is what the convenient interfaces provide:
Bytes can be any of the following types:
Note that null bytes embedded in string literals are considered part of the string, e.g. XXH3_64bits_const("a\0b") is equivalent to XXH3_64bits_const("a\0b", 3) rather than XXH3_64bits_const("a", 1).
Unfortunately, we cannot distinguish a string literal from a “real” const char[]. This means the following code snippet hashes 3 bytes instead of 4.
constexpr char bytes[] = {0xff, 0xfc, 0xfb, 0xfa};
constexpr uint64_t hash = XXH3_64bits_const(bytes);This is unfortunate, but there appears to be no simple way to work it around. For now, we have to use XXH3_64bits_const(bytes, sizeof(bytes)) or XXH3_64bits_const(std::span(bytes)) in this case.
if you want to include this header directly to your project without copy this file, you my add this repository as submodule and include simple static library into your proeject
git submodule add https://github.com/chys87/constexpr-xxh3.gitadd_subdirectory(constexpr-xxh3)
target_link_libraries(${PROJECT_NAME} PUBLIC xxh3)
#include <constexpr-xxh3.h>
constexpr hash = XXH3_64bits_const(constexprdataarray);Implement the 128-bit version
| Back | FazBrowse Home | New Git URL |