59[[nodiscard]]
inline uint32_t
read32(
const uint8_t* ptr)
61 if constexpr (ALIGNED) {
63 assert((
reinterpret_cast<intptr_t
>(ptr) & 3) == 0);
65 return *
reinterpret_cast<const uint32_t*
>(ptr);
68 memcpy(&result, ptr,
sizeof(result));
74template<
bool ALIGNED, u
int8_t MASK8 = 0xFF, u
int32_t SEED = 0>
77 constexpr uint32_t MASK32 = MASK8 * 0x01010101U;
79 const uint8_t*
const bEnd = p +
size;
82 if (
size >= 16) [[unlikely]] {
83 const uint8_t*
const limit = bEnd - 16;
92 uint32_t r1 = (read32<ALIGNED>(p + 0) & MASK32) *
PRIME32_2;
93 uint32_t r2 = (read32<ALIGNED>(p + 4) & MASK32) *
PRIME32_2;
94 uint32_t r3 = (read32<ALIGNED>(p + 8) & MASK32) *
PRIME32_2;
95 uint32_t r4 = (read32<ALIGNED>(p + 12) & MASK32) *
PRIME32_2;
101 }
while (p <= limit);
103 h32 = std::rotl(v1, 1) + std::rotl(v2, 7) + std::rotl(v3, 12) + std::rotl(
v4, 18);
108 h32 += uint32_t(
size);
110 while ((p + 4) <= bEnd) {
111 uint32_t r = (read32<ALIGNED>(p) & MASK32) *
PRIME32_3;
112 h32 = std::rotl(h32 + r, 17) *
PRIME32_4;
118 h32 = std::rotl(h32 + r, 11) *
PRIME32_1;
124 return h32 ^ (h32 >> 16);
127template<u
int8_t MASK8> [[nodiscard]]
inline uint32_t
xxhash_impl(std::string_view key)
129 const auto* data =
reinterpret_cast<const uint8_t*
>(key.data());
130 auto size = key.size();
131 if (
reinterpret_cast<intptr_t
>(data) & 3) {
132 return xxhash_impl<false, MASK8>(data,
size);
135 return xxhash_impl<true, MASK8>(data,
size);
139[[nodiscard]]
inline uint32_t
xxhash(std::string_view key)
141 return xxhash_impl<0xFF>(key);
145 return xxhash_impl<static_cast<uint8_t>(~(
'a' -
'A'))>(key);
149 [[nodiscard]] uint32_t
operator()(std::string_view key)
const {
155 [[nodiscard]] uint32_t
operator()(std::string_view key)
const {
size_t size(std::string_view utf8)
uint32_t operator()(std::string_view key) const
uint32_t operator()(std::string_view key) const
uint32_t read32(const uint8_t *ptr)
uint32_t xxhash_impl(const uint8_t *p, size_t size)
constexpr uint32_t PRIME32_1
constexpr uint32_t PRIME32_2
uint32_t xxhash(std::string_view key)
constexpr uint32_t PRIME32_3
uint32_t xxhash_case(std::string_view key)
constexpr uint32_t PRIME32_5
constexpr uint32_t PRIME32_4