mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-30 03:15:38 -05:00
hash for string_view
This commit is contained in:
parent
f540d5bd63
commit
9db76274b5
1 changed files with 6 additions and 2 deletions
|
@ -55,15 +55,19 @@ namespace geode {
|
||||||
constexpr unsigned int hash(char const* str, int h = 0) {
|
constexpr unsigned int hash(char const* str, int h = 0) {
|
||||||
return !str[h] ? 5381 : (hash(str, h + 1) * 33) ^ str[h];
|
return !str[h] ? 5381 : (hash(str, h + 1) * 33) ^ str[h];
|
||||||
}
|
}
|
||||||
|
constexpr unsigned int hash(std::string_view str, int h = 0) {
|
||||||
|
return h >= str.size() ? 5381 : (hash(str, h + 1) * 33) ^ str[h];
|
||||||
|
}
|
||||||
constexpr unsigned int hash(wchar_t const* str, int h = 0) {
|
constexpr unsigned int hash(wchar_t const* str, int h = 0) {
|
||||||
return !str[h] ? 5381 : (hash(str, h + 1) * 33) ^ str[h];
|
return !str[h] ? 5381 : (hash(str, h + 1) * 33) ^ str[h];
|
||||||
}
|
}
|
||||||
|
constexpr unsigned int hash(std::wstring_view str, int h = 0) {
|
||||||
|
return h >= str.size() ? 5381 : (hash(str, h + 1) * 33) ^ str[h];
|
||||||
|
}
|
||||||
|
|
||||||
constexpr size_t operator"" _h(char const* txt, size_t) {
|
constexpr size_t operator"" _h(char const* txt, size_t) {
|
||||||
return geode::utils::hash(txt);
|
return geode::utils::hash(txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr size_t operator"" _h(wchar_t const* txt, size_t) {
|
constexpr size_t operator"" _h(wchar_t const* txt, size_t) {
|
||||||
return geode::utils::hash(txt);
|
return geode::utils::hash(txt);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue