include/brotensor/detail/string_hash.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | // Transparent hash for std::unordered_map<std::string, ...> keys, so lookups | ||
| 4 | // by std::string_view / const char* don't have to materialize a std::string | ||
| 5 | // just to satisfy the map's key type. Pair with std::equal_to<> (already | ||
| 6 | // transparent) as the KeyEqual template argument. | ||
| 7 | |||
| 8 | #include <cstddef> | ||
| 9 | #include <string> | ||
| 10 | #include <string_view> | ||
| 11 | |||
| 12 | namespace brotensor::detail { | ||
| 13 | |||
| 14 | struct StringHash { | ||
| 15 | using is_transparent = void; | ||
| 16 | 103 | std::size_t operator()(std::string_view sv) const noexcept { | |
| 17 | 103 | return std::hash<std::string_view>{}(sv); | |
| 18 | } | ||
| 19 | 160 | std::size_t operator()(const std::string& s) const noexcept { | |
| 20 | 160 | return std::hash<std::string_view>{}(s); | |
| 21 | } | ||
| 22 | std::size_t operator()(const char* s) const noexcept { | ||
| 23 | return std::hash<std::string_view>{}(s); | ||
| 24 | } | ||
| 25 | }; | ||
| 26 | |||
| 27 | } // namespace brotensor::detail | ||
| 28 |