feat: added context and utility headers
This commit is contained in:
29
include/fxn/utility.hpp
Normal file
29
include/fxn/utility.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <string_view>
|
||||
#include <cstdint>
|
||||
|
||||
namespace fxn
|
||||
{
|
||||
inline constexpr char ToLower(const char c) noexcept
|
||||
{
|
||||
return (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
|
||||
}
|
||||
|
||||
inline constexpr unsigned int HashString(std::string_view str) noexcept
|
||||
{
|
||||
std::uint32_t hash = 0;
|
||||
|
||||
for (char ch : str)
|
||||
{
|
||||
hash += ToLower(ch);
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash >> 11);
|
||||
hash += (hash << 15);
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user