Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:11

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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 // Adapted from https://gist.github.com/Lee-R/3839813
0022 namespace detail {
0023 // FNV-1a 32bit hashing algorithm.
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 }  // namespace detail
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 }  // namespace HashedStringLiteral
0054 }  // namespace Acts