48 #include <string_view>
58 [[nodiscard]] constexpr uint32_t
rotl(uint32_t
x)
60 return (
x <<
R) | (
x >> (32 -
R));
63 template<
bool ALIGNED>
64 [[nodiscard]]
inline uint32_t
read32(
const uint8_t* ptr)
68 assert((
reinterpret_cast<intptr_t
>(ptr) & 3) == 0);
70 return *
reinterpret_cast<const uint32_t*
>(ptr);
73 memcpy(&result, ptr,
sizeof(result));
79 template<
bool ALIGNED, u
int8_t MASK8 = 0xFF, u
int32_t SEED = 0>
82 constexpr uint32_t MASK32 = MASK8 * 0x01010101U;
84 const uint8_t*
const bEnd = p +
size;
88 const uint8_t*
const limit = bEnd - 16;
93 uint32_t v3 = SEED + 0;
97 uint32_t r1 = (read32<ALIGNED>(p + 0) & MASK32) *
PRIME32_2;
98 uint32_t r2 = (read32<ALIGNED>(p + 4) & MASK32) *
PRIME32_2;
99 uint32_t r3 = (read32<ALIGNED>(p + 8) & MASK32) *
PRIME32_2;
100 uint32_t r4 = (read32<ALIGNED>(p + 12) & MASK32) *
PRIME32_2;
106 }
while (p <= limit);
108 h32 = rotl<1>(v1) + rotl<7>(v2) + rotl<12>(v3) + rotl<18>(
v4);
113 h32 += uint32_t(
size);
115 while ((p + 4) <= bEnd) {
116 uint32_t r = (read32<ALIGNED>(p) & MASK32) *
PRIME32_3;
129 return h32 ^ (h32 >> 16);
132 template<u
int8_t MASK8> [[nodiscard]]
inline uint32_t
xxhash_impl(std::string_view key)
134 const auto* data =
reinterpret_cast<const uint8_t*
>(key.data());
135 auto size = key.size();
136 if (
reinterpret_cast<intptr_t
>(data) & 3) {
137 return xxhash_impl<false, MASK8>(data,
size);
140 return xxhash_impl<true, MASK8>(data,
size);
144 [[nodiscard]]
inline uint32_t
xxhash(std::string_view key)
146 return xxhash_impl<0xFF>(key);
150 return xxhash_impl<static_cast<uint8_t>(~(
'a' -
'A'))>(key);
154 [[nodiscard]] uint32_t
operator()(std::string_view key)
const {
160 [[nodiscard]] uint32_t
operator()(std::string_view key)
const {
constexpr KeyMatrixPosition x
Keyboard bindings.
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 rotl(uint32_t x)
constexpr uint32_t PRIME32_5
constexpr uint32_t PRIME32_4