准备新增字符串的增强结构,包括编译期字符串

This commit is contained in:
2025-08-28 16:49:48 +08:00
parent 651c890442
commit 6e1eaef2e6
5 changed files with 197 additions and 0 deletions

View File

@@ -46,6 +46,20 @@ inline uint32_t Hash(const int64_t A)
return (uint32_t)A + ((uint32_t)(A >> 32) * 23);
}
uint32_t Hash(const char* str, uint32_t hash = 5381)
{
return *str == '\0' ? hash : Hash(str + 1, ((hash << 5) + hash) + *str);
}
uint32_t Hash(std::string_view str, uint32_t hash = 5381)
{
for (size_t i = 0; i < str.length(); ++i)
{
hash = ((hash << 5) + hash) + str[i];
}
return hash;
}
constexpr uint32_t CHash(const uint8_t A)
{
return A;