LLVM: llvm::HashBuilder< HasherT, Endianness > Class Template Reference (original) (raw)

Interface to help hash various types through a hasher type. More...

#include "[llvm/Support/HashBuilder.h](HashBuilder%5F8h%5Fsource.html)"

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
HashBuilder & addRange (ForwardIteratorT First, ForwardIteratorT Last)
template
HashBuilder & addRange (const RangeT &Range)
template
HashBuilder & addRangeElements (ForwardIteratorT First, ForwardIteratorT Last)
template
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.

template<typename HasherT, llvm::endianness Endianness>
class llvm::HashBuilder< HasherT, Endianness >

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

builder.add({1});

builder.add({2, 3});

and

builder.add({1, 2});

builder.add({3});

. 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.

HasAddHashT

Initial value:

decltype(addHash(std::declval<HashBuilder &>(), std::declval<T &>()))

Definition at line 206 of file HashBuilder.h.

HasByteSwapT

Initial value:

value_type byte_swap(value_type value, endianness endian)

Definition at line 348 of file HashBuilder.h.

llvm::HashBuilder< HasherT, Endianness >::HashBuilder ( HasherT & Hasher) inlineexplicit

HashBuilder() [2/2]

template<typename... ArgTypes>

llvm::HashBuilder< HasherT, Endianness >::HashBuilder ( ArgTypes &&... Args) inlineexplicit

add() [1/7]

Support hashing ArrayRef.

Value.size() is taken into account to ensure cases like

builder.add({1});

builder.add({2, 3});

and

builder.add({1, 2});

builder.add({3});

do not collide.

Definition at line 164 of file HashBuilder.h.

add() [2/7]

template<typename T1, typename T2>

add() [3/7]

add() [4/7]

Implement hashing for user-defined structs.

Any user-define struct can participate in hashing via HashBuilder by providing a addHash templated function.

template <typename HasherT, llvm::endianness Endianness>

void addHash(HashBuilder<HasherT, Endianness> &HBuilder,

const UserDefinedStruct &Value);

HashBuilder(HasherT &Hasher)

LLVM Value Representation.

For example:

struct SimpleStruct {

char c;

int i;

};

template <typename HasherT, llvm::endianness Endianness>

const SimpleStruct &Value) {

}

Interface to help hash various types through a hasher type.

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.

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.

struct __attribute__ ((packed)) StructWithFastHash {

int I;

char C;

template <typename HasherT, llvm::endianness Endianness>

friend void addHash(HashBuilder<HasherT, Endianness> &HBuilder,

const StructWithFastHash &Value) {

} else {

}

}

};

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

void update(ArrayRef< uint8_t > Data)

Forward to HasherT::update(ArrayRef<uint8_t>).

@ C

The default llvm calling convention, compatible with C.

To avoid collisions, specialization of addHash for variable-size types must take the size into account.

For example:

struct CustomContainer {

private:

int Elements[100];

public:

for (size_t I = 0; I != Size; ++I)

Elements[I] = I;

}

template <typename HasherT, llvm::endianness Endianness>

const CustomContainer &Value) {

sizeof(Value.Size) + Value.Size * sizeof(Value.Elements[0])));

} else {

HBuilder.addRange(&Value.Elements[0], &Value.Elements[0] +

Value.Size);

}

}

};

HashBuilder & addRange(ForwardIteratorT First, ForwardIteratorT Last)

Definition at line 295 of file HashBuilder.h.

add() [5/7]

A convenenience variadic helper.

It simply iterates over its arguments, in order.

is equivalent to

Definition at line 321 of file HashBuilder.h.

add() [6/7]

Support hashing StringRef.

Value.size() is taken into account to ensure cases like

builder.add("a");

builder.add("bc");

and

builder.add("ab");

builder.add("c");

do not collide.

Definition at line 194 of file HashBuilder.h.

add() [7/7]

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().

addRange() [1/2]

template

addRange() [2/2]

template

addRangeElements() [1/2]

template

addRangeElements() [2/2]

template

adjustForEndiannessAndAdd()


The documentation for this class was generated from the following file: