|
| HashType | operator() (std::string_view key) const noexcept |
| | Hashes a std::string_view using CRC32-C algorithm.
|
| HashType | operator() (const std::string &key) const noexcept |
| | Hashes a std::string using CRC32-C algorithm.
|
| HashType | operator() (const char *key) const noexcept |
| | Hashes a C-style string using CRC32-C algorithm.
|
| template<typename TKey> |
| std::enable_if_t< std::is_integral_v< TKey >, HashType > | operator() (const TKey &key) const noexcept |
| | Hashes an integral type using multiplicative hashing.
|
| template<typename T> |
| std::enable_if_t< std::is_floating_point_v< T >, HashType > | operator() (T value) const noexcept |
| | Hashes a floating-point value with normalization.
|
| template<typename T> |
| std::enable_if_t< std::is_pointer_v< T > &&!std::is_same_v< T, const char * > &&!std::is_same_v< T, char * >, HashType > | operator() (T ptr) const noexcept |
| | Hashes a pointer by its address.
|
| template<typename TKey> |
| std::enable_if_t< std::is_enum_v< TKey >, HashType > | operator() (const TKey &key) const noexcept |
| | Hashes an enum by its underlying integral value.
|
| template<typename T, size_t N> |
| HashType | operator() (const std::array< T, N > &arr) const noexcept |
| | Hashes a std::array by combining hashes of all elements.
|
| template<typename T> |
| HashType | operator() (const std::optional< T > &opt) const noexcept |
| | Hashes a std::optional - nullopt has distinct hash from any value.
|
| template<typename T1, typename T2> |
| HashType | operator() (const std::pair< T1, T2 > &p) const noexcept |
| | Hashes a std::pair by combining hashes of both elements.
|
| template<typename T, std::size_t Extent = std::dynamic_extent> |
| HashType | operator() (std::span< T, Extent > sp) const noexcept |
| | Hashes a std::span by combining hashes of all elements in the view.
|
| template<typename... Ts> |
| HashType | operator() (const std::tuple< Ts... > &t) const noexcept |
| | Hashes a std::tuple by combining hashes of all elements.
|
| template<typename... Ts> |
| HashType | operator() (const std::variant< Ts... > &var) const noexcept |
| | Hashes a std::variant by combining index and active alternative's hash.
|
| template<typename T> |
| HashType | operator() (const std::vector< T > &vec) const noexcept |
| | Hashes a std::vector by combining size and hashes of all elements.
|
| template<typename TKey> |
| std::enable_if_t<!std::is_same_v< std::decay_t< TKey >, std::string_view > &&!std::is_same_v< std::decay_t< TKey >, std::string > &&!std::is_same_v< std::decay_t< TKey >, const char * > &&!std::is_integral_v< TKey > &&!std::is_floating_point_v< TKey > &&!std::is_pointer_v< TKey > &&!std::is_enum_v< TKey > &&!is_std_array< TKey >::value &&!is_std_optional< TKey >::value &&!is_std_pair< TKey >::value &&!is_std_span< TKey >::value &&!is_std_tuple< TKey >::value &&!is_std_variant< TKey >::value &&!is_std_vector< TKey >::value, HashType > | operator() (const TKey &key) const noexcept |
| | Hashes custom types using std::hash fallback.
|
template<Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? constants::FNV_OFFSET_BASIS_32 : constants::FNV_OFFSET_BASIS_64 )>
struct nfx::hashing::Hasher< HashType, Seed >
General-purpose STL-compatible hash functor supporting multiple types.
- Template Parameters
-
| HashType | Hash value type - must be uint32_t or uint64_t (default: uint32_t) |
| Seed | Initial seed value for hash calculation (default: FNV_OFFSET_BASIS_32 for 32-bit, FNV_OFFSET_BASIS_64 for 64-bit) |
This functor provides a unified hashing interface compatible with STL containers like std::unordered_map and std::unordered_set. It supports transparent lookup via the is_transparent type alias, allowing heterogeneous key comparisons.
Supported Types:
- Strings: std::string, std::string_view, const char* → CRC32-C with SSE4.2 hardware acceleration (requires -march=native/-msse4.2 or /arch:AVX)
- Integers: All integral types → uses multiplicative hashing (Knuth/Wang)
- Pointers: Generic pointers → hashes the address as uintptr_t
- Floating-point: float, double → normalizes special values (+0/-0, NaN) and hashes bit representation
- Enums: Converts to underlying integral type and hashes
- Pairs: std::pair<T1, T2> → hashes both elements and combines them
- Tuples: std::tuple<Ts...> → hashes all elements and combines them
- Arrays: std::array<T, N> → hashes all elements and combines them
- Vectors: std::vector<T> → hashes size and all elements
- Spans: std::span<T> → hashes all elements in the contiguous view
- Optionals: std::optional<T> → hashes nullopt state or contained value
- Variants: std::variant<Ts...> → hashes index and active alternative
- Custom types: Falls back to std::hash<T> for unknown types
Usage Example:
std::unordered_map<std::string, int, nfx::hashing::Hasher<>> map32;
std::unordered_map<std::string, int, nfx::hashing::Hasher<uint64_t>> map64;
std::unordered_map<std::string, int, nfx::hashing::Hasher<>, std::equal_to<>> transparentMap;
std::string_view key = "lookup";
auto it = transparentMap.find(key);
Definition at line 168 of file Hasher.h.