class HashState

Defined at line 315 of file ../../third_party/abseil-cpp/absl/hash/hash.h

HashState

A type erased version of the hash state concept, for use in user-defined

`AbslHashValue` implementations that can't use templates (such as PImpl

classes, virtual functions, etc.). The type erasure adds overhead so it

should be avoided unless necessary.

Note: This wrapper will only erase calls to

combine_contiguous(H, const unsigned char*, size_t)

RunCombineUnordered(H, CombinerF)

All other calls will be handled internally and will not invoke overloads

provided by the wrapped class.

Users of this class should still define a template `AbslHashValue` function,

but can use `absl::HashState::Create(

&state

)` to erase the type of the hash

state and dispatch to their private hashing logic.

This state can be used like any other hash state. In particular, you can call

`HashState::combine()` and `HashState::combine_contiguous()` on it.

Example:

class Interface {

public:

template

<typename

H>

friend H AbslHashValue(H state, const Interface

&

value) {

state = H::combine(std::move(state), std::type_index(typeid(*this)));

value.HashValue(absl::HashState::Create(

&state

));

return state;

}

private:

virtual void HashValue(absl::HashState state) const = 0;

};

class Impl : Interface {

private:

void HashValue(absl::HashState state) const override {

absl::HashState::combine(std::move(state), v1_, v2_);

}

int v1_;

std::string v2_;

};

Public Methods

template <typename T>
HashState Create (T * state)

HashState::Create()

Create a new `HashState` instance that wraps `state`. All calls to

`combine()` and `combine_contiguous()` on the new instance will be

redirected to the original `state` object. The `state` object must outlive

the `HashState` instance.

Defined at line 324 of file ../../third_party/abseil-cpp/absl/hash/hash.h

void HashState (const HashState & )

Defined at line 330 of file ../../third_party/abseil-cpp/absl/hash/hash.h

HashState & operator= (const HashState & )

Defined at line 331 of file ../../third_party/abseil-cpp/absl/hash/hash.h

void HashState (HashState && )

Defined at line 332 of file ../../third_party/abseil-cpp/absl/hash/hash.h

HashState & operator= (HashState && )

Defined at line 333 of file ../../third_party/abseil-cpp/absl/hash/hash.h

HashState combine_contiguous (HashState hash_state, const unsigned char * first, size_t size)

HashState::combine_contiguous()

Combines a contiguous array of `size` elements into a hash state, returning

the updated state.

Defined at line 345 of file ../../third_party/abseil-cpp/absl/hash/hash.h

Records

Friends

class HashStateBase