P4C
The P4 Compiler
|
The implementation below decouples generic hash interface provider from a particular implementation for a given class T
. One should partially-specialize Util::Hasher<T> to provide a hash value for T
. Util::Hash is intended to be used instead of std::hash<T> in various associative containers. For example std::unordered_set<K, Util::Hash>
would work as soon as there is an implementation of Util::Hasher<K>. The code below provides some default specializations for certain built-in types and theirs combinations (pairs and tuples). Additionally, hashes could be combined either directly (Hash::operator() is variadic) or via dedicated hash_combine
/ hash_combine_generic
functions.