hash state¶
- group turbo_hash_state
-
class HashState : public hash_internal::HashStateBase<HashState>¶
- #include <hash.h>
HashState is a type erased version of the hash state concept, for use in user-defined
hash_valueimplementations 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) run_combine_unordered(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
hash_valuefunction, but can useturbo::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 callHashState::combine()andHashState::combine_contiguous()on it. Example:class Interface { public: template <typename H> friend H hash_value(H state, const Interface& value) { state = H::combine(std::move(state), std::type_index(typeid(*this))); value.HashValue(turbo::HashState::Create(&state)); return state; } private: virtual void HashValue(turbo::HashState state) const = 0; }; class Impl : Interface { private: void HashValue(turbo::HashState state) const override { turbo::HashState::combine(std::move(state), v1_, v2_); } int v1_; std::string v2_; };
-
class HashState : public hash_internal::HashStateBase<HashState>¶