LLVM 20.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 = decltype(addHash(std::declval< HashBuilder & >(), std::declval< T & >())) |
template<typename T > | |
using | HasByteSwapT = decltype(support::endian::byte_swap(std::declval< T & >(), llvm::endianness::little)) |
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 struct s. | |
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:
template<typename T> add(const T &Value)
The add
function implements hashing of various types.template <typename ItT> void addRange(ItT First, ItT Last)
The addRange
function is designed to aid hashing a range of values. It explicitly adds the size of the range in the hash.template <typename ItT> void addRangeElements(ItT First, ItT Last)
The addRangeElements
function is also designed to aid hashing a range of values. In contrast to addRange
, it ignores the size of the range, behaving as if elements were added one at a time with add
.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 139 of file HashBuilder.h.
using llvm::HashBuilder< HasherT, Endianness >::HasAddHashT = decltype(addHash(std::declval<HashBuilder &>(), std::declval<T &>())) |
Definition at line 208 of file HashBuilder.h.
using llvm::HashBuilder< HasherT, Endianness >::HasByteSwapT = decltype(support::endian::byte_swap( std::declval<T &>(), llvm::endianness::little)) |
Definition at line 350 of file HashBuilder.h.
|
inlineexplicit |
Definition at line 141 of file HashBuilder.h.
|
inlineexplicit |
Definition at line 143 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 166 of file HashBuilder.h.
References llvm::HashBuilder< HasherT, Endianness >::add(), llvm::native, and llvm::HashBuilderBase< HasherT >::update().
|
inline |
Definition at line 303 of file HashBuilder.h.
References llvm::HashBuilder< HasherT, Endianness >::add().
|
inline |
Definition at line 307 of file HashBuilder.h.
References llvm::HashBuilder< HasherT, Endianness >::add().
|
inline |
Implement hashing for user-defined struct
s.
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 297 of file HashBuilder.h.
|
inline |
A convenenience variadic helper.
It simply iterates over its arguments, in order.
is equivalent to
Definition at line 323 of file HashBuilder.h.
References llvm::HashBuilder< HasherT, Endianness >::add().
|
inline |
Support hashing StringRef
.
Value.size()
is taken into account to ensure cases like
and
do not collide.
Definition at line 196 of file HashBuilder.h.
References llvm::HashBuilder< HasherT, Endianness >::add(), and llvm::HashBuilderBase< HasherT >::update().
|
inline |
Implement hashing for hashable data types, e.g. integral or enum values.
Definition at line 149 of file HashBuilder.h.
References llvm::HashBuilder< HasherT, Endianness >::adjustForEndiannessAndAdd().
Referenced by llvm::HashBuilder< HasherT, Endianness >::add(), llvm::HashBuilder< HasherT, Endianness >::addRange(), computeFullStackId(), computeStackId(), and llvm::hash_value().
|
inline |
Definition at line 333 of file HashBuilder.h.
References llvm::HashBuilder< HasherT, Endianness >::addRange(), llvm::adl_begin(), llvm::adl_end(), and Range.
|
inline |
Definition at line 328 of file HashBuilder.h.
References llvm::HashBuilder< HasherT, Endianness >::add(), llvm::HashBuilder< HasherT, Endianness >::addRangeElements(), llvm::First, and llvm::Last.
Referenced by llvm::HashBuilder< HasherT, Endianness >::addRange().
|
inline |
Definition at line 345 of file HashBuilder.h.
References llvm::HashBuilder< HasherT, Endianness >::addRangeElements(), llvm::adl_begin(), llvm::adl_end(), and Range.
|
inline |
Definition at line 338 of file HashBuilder.h.
References llvm::First, and llvm::Last.
Referenced by llvm::HashBuilder< HasherT, Endianness >::addRange(), and llvm::HashBuilder< HasherT, Endianness >::addRangeElements().
|
inline |
Adjust Value
for the target endianness and add it to the hash.
Definition at line 355 of file HashBuilder.h.
References llvm::support::endian::byte_swap(), and llvm::HashBuilderBase< HasherT >::update().
Referenced by llvm::HashBuilder< HasherT, Endianness >::add().