hash functions¶
- group turbo_hash_function
Functions
-
template<int&... ExplicitArgumentBarrier, typename ...Types>
size_t hash_of(const Types&... values)¶ hash_of() is a helper that generates a hash from the values of its arguments.
It dispatches to turbo::Hash directly, as follows:
hash_of(t) == turbo::Hash<T>{}(t)
hash_of(a, b, c) == hash_of(std::make_tuple(a, b, c)) hash_of(a1, a2, …) == hash_of(b1, b2, …) is guaranteed when
The argument lists have pairwise identical C++ types
a1 == b1 && a2 == b2 && …
The requirement that the arguments match in both type and value is critical. It means that
a == bdoes not necessarily implyhash_of(a) == hash_of(b)ifaandbhave different types. For example,hash_of(2) != hash_of(2.0). Example:Output: 10074652746429307112#include <turbo/hash/hash.h> int main() { std::string s = "hello"; std::string_view sv = s; std::cout << turbo::hash_of(s) << std::endl; std::cout << turbo::hash_of(sv) << std::endl; }
- Template Parameters:
ExplicitArgumentBarrier – ExplicitArgumentBarrier
Types – Types
- Parameters:
values – values
- Returns:
size_t
-
template<int&... ExplicitArgumentBarrier, typename ...Types>