File indexing completed on 2025-01-18 09:11:11
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <csignal>
0012 #include <cstddef>
0013 #include <cstdint>
0014 #include <string_view>
0015 #include <type_traits>
0016 #include <utility>
0017
0018 namespace Acts {
0019 using HashedString = std::uint32_t;
0020
0021
0022 namespace detail {
0023
0024 constexpr HashedString fnv1a_32(char const* s, std::size_t count) {
0025 return count != 0u ? (fnv1a_32(s, count - 1) ^ s[count - 1]) * 16777619u
0026 : 2166136261u;
0027 }
0028
0029 constexpr HashedString fnv1a_32(std::string_view s) {
0030 return !s.empty() ? (fnv1a_32(s.substr(0, s.size() - 1)) ^ s[s.size() - 1]) *
0031 16777619u
0032 : 2166136261u;
0033 }
0034
0035 constexpr int length(const char* str) {
0036 return *str != 0 ? 1 + length(str + 1) : 0;
0037 }
0038 }
0039
0040 consteval HashedString hashString(std::string_view s) {
0041 return detail::fnv1a_32(s);
0042 }
0043
0044 constexpr HashedString hashStringDynamic(std::string_view s) {
0045 return detail::fnv1a_32(s);
0046 }
0047
0048 namespace HashedStringLiteral {
0049 constexpr HashedString operator""_hash(char const* s, std::size_t count) {
0050 return detail::fnv1a_32(s, count);
0051 }
0052
0053 }
0054 }