LLVM 22.0.0git
|
Interface to help hash various types through a hasher type. More...
#include "llvm/Support/HashBuilder.h"
Public Types | |
template<typename T> | |
using | HasAddHashT |
template<typename T> | |
using | HasByteSwapT |
Public Types inherited from llvm::HashBuilderBase< HasherT > | |
template<typename HasherT_ = HasherT> | |
using | HashResultTy = decltype(std::declval<HasherT_ &>().final()) |
Public Member Functions | |
HashBuilder (HasherT &Hasher) | |
template<typename... ArgTypes> | |
HashBuilder (ArgTypes &&...Args) | |
template<typename T> | |
std::enable_if_t< hashbuilder_detail::IsHashableData< T >::value, HashBuilder & > | add (T Value) |
Implement hashing for hashable data types, e.g. integral or enum values. | |
template<typename T> | |
HashBuilder & | add (ArrayRef< T > Value) |
Support hashing ArrayRef. | |
HashBuilder & | add (StringRef Value) |
Support hashing StringRef. | |
template<typename T> | |
std::enable_if_t< is_detected< HasAddHashT, T >::value &&!hashbuilder_detail::IsHashableData< T >::value, HashBuilder & > | add (const T &Value) |
Implement hashing for user-defined structs. | |
template<typename T1, typename T2> | |
HashBuilder & | add (const std::pair< T1, T2 > &Value) |
template<typename... Ts> | |
HashBuilder & | add (const std::tuple< Ts... > &Arg) |
template<typename... Ts> | |
std::enable_if_t<(sizeof...(Ts) > 1), HashBuilder & > | add (const Ts &...Args) |
A convenenience variadic helper. | |
template<typename ForwardIteratorT> | |
HashBuilder & | addRange (ForwardIteratorT First, ForwardIteratorT Last) |
template<typename RangeT> | |
HashBuilder & | addRange (const RangeT &Range) |
template<typename ForwardIteratorT> | |
HashBuilder & | addRangeElements (ForwardIteratorT First, ForwardIteratorT Last) |
template<typename RangeT> | |
HashBuilder & | addRangeElements (const RangeT &Range) |
template<typename T> | |
std::enable_if_t< is_detected< HasByteSwapT, T >::value, HashBuilder & > | adjustForEndiannessAndAdd (const T &Value) |
Adjust Value for the target endianness and add it to the hash. | |
Public Member Functions inherited from llvm::HashBuilderBase< HasherT > | |
HasherT & | getHasher () |
void | update (ArrayRef< uint8_t > Data) |
Forward to HasherT::update(ArrayRef<uint8_t>). | |
void | update (StringRef Data) |
Forward to HasherT::update(ArrayRef<uint8_t>). | |
template<typename HasherT_ = HasherT> | |
HashResultTy< HasherT_ > | final () |
Forward to HasherT::final() if available. | |
template<typename HasherT_ = HasherT> | |
HashResultTy< HasherT_ > | result () |
Forward to HasherT::result() if available. |
Additional Inherited Members | |
Protected Member Functions inherited from llvm::HashBuilderBase< HasherT > | |
HashBuilderBase (HasherT &Hasher) | |
template<typename... ArgTypes> | |
HashBuilderBase (ArgTypes &&...Args) |
Interface to help hash various types through a hasher type.
Via provided specializations of add, addRange, and addRangeElements functions, various types (e.g. ArrayRef, StringRef, etc.) can be hashed without requiring any knowledge of hashed types from the hasher type.
The only method expected from the templated hasher type HasherT is:
Additionally, the following methods will be forwarded to the hasher type:
From a user point of view, the interface provides the following:
User-defined struct types can participate in this interface by providing an addHash templated function. See the associated template specialization for details.
This interface does not impose requirements on the hasher update(ArrayRef<uint8_t> Data) method. We want to avoid collisions for variable-size types; for example for
and
. Thus, specializations of add and addHash for variable-size types must not assume that the hasher type considers the size as part of the hash; they must explicitly add the size to the hash. See for example specializations for ArrayRef and StringRef.
Additionally, since types are eventually forwarded to the hasher's void update(ArrayRef<uint8_t>) method, endianness plays a role in the hash computation (for example when computing add((int)123)). Specifiying a non-native Endianness template parameter allows to compute stable hash across platforms with different endianness.
Definition at line 137 of file HashBuilder.h.
using llvm::HashBuilder< HasherT, Endianness >::HasAddHashT |
Definition at line 206 of file HashBuilder.h.
using llvm::HashBuilder< HasherT, Endianness >::HasByteSwapT |
Definition at line 348 of file HashBuilder.h.
|
inlineexplicit |
Definition at line 139 of file HashBuilder.h.
|
inlineexplicit |
Definition at line 141 of file HashBuilder.h.
|
inline |
Support hashing ArrayRef.
Value.size() is taken into account to ensure cases like
and
do not collide.
Definition at line 164 of file HashBuilder.h.
|
inline |
Definition at line 301 of file HashBuilder.h.
|
inline |
Definition at line 305 of file HashBuilder.h.
|
inline |
Implement hashing for user-defined structs.
Any user-define struct can participate in hashing via HashBuilder by providing a addHash templated function.
For example:
To avoid endianness issues, specializations of addHash should generally rely on exising add, addRange, and addRangeElements functions. If directly using update, an implementation must correctly handle endianness.
To avoid collisions, specialization of addHash for variable-size types must take the size into account.
For example:
Definition at line 295 of file HashBuilder.h.
|
inline |
A convenenience variadic helper.
It simply iterates over its arguments, in order.
is equivalent to
Definition at line 321 of file HashBuilder.h.
|
inline |
Support hashing StringRef.
Value.size() is taken into account to ensure cases like
and
do not collide.
Definition at line 194 of file HashBuilder.h.
|
inline |
Implement hashing for hashable data types, e.g. integral or enum values.
Definition at line 147 of file HashBuilder.h.
Referenced by llvm::HashBuilder< hashbuilder_detail::HashCodeHasher, llvm::endianness::native >::add(), llvm::HashBuilder< hashbuilder_detail::HashCodeHasher, llvm::endianness::native >::add(), llvm::HashBuilder< hashbuilder_detail::HashCodeHasher, llvm::endianness::native >::add(), llvm::HashBuilder< hashbuilder_detail::HashCodeHasher, llvm::endianness::native >::add(), llvm::HashBuilder< hashbuilder_detail::HashCodeHasher, llvm::endianness::native >::add(), llvm::VersionTuple::addHash, llvm::HashBuilder< hashbuilder_detail::HashCodeHasher, llvm::endianness::native >::addRange(), llvm::memprof::computeFullStackId(), computeStackId(), and llvm::hash_value().
|
inline |
Definition at line 331 of file HashBuilder.h.
|
inline |
Definition at line 326 of file HashBuilder.h.
Referenced by llvm::HashBuilder< hashbuilder_detail::HashCodeHasher, llvm::endianness::native >::addRange().
|
inline |
Definition at line 343 of file HashBuilder.h.
|
inline |
|
inline |
Adjust Value for the target endianness and add it to the hash.
Definition at line 353 of file HashBuilder.h.
Referenced by llvm::HashBuilder< hashbuilder_detail::HashCodeHasher, llvm::endianness::native >::add().