A stateful helper class for accumulating and mixing hash values.
HashState encapsulates the bitwise operations required to combine multiple values into a single hash. It uses move semantics to enforce a linear chain of operations, ensuring that intermediate states are not accidentally reused.
Public Member Functions | |
| HashState (size_t seed=17) | |
| HashState (const HashState &)=delete | |
| HashState & | operator= (const HashState &)=delete |
| HashState (HashState &&)=default | |
| HashState & | operator= (HashState &&)=default |
| size_t | finalize () |
| Finalizes the hash calculation and returns the result. | |
Static Public Member Functions | |
| static HashState | mix (HashState &&h, size_t val) |
| template<typename T > | |
| static HashState | combine (HashState &&h, const T &val) |
| template<typename T , typename... Ts> | |
| static HashState | combine (HashState &&h, const T &first, const Ts &... rest) |
| template<typename T > | |
| static HashState | combine_contiguous (HashState &&h, const T *data, size_t size) |
| template<typename InputIt > | |
| static HashState | combine_unordered (HashState &&h, InputIt first, InputIt last) |
|
inlineexplicit |
Initializes the hash state with a seed.
| seed | An initial value to randomize the hash. Defaults to 17. |
|
inlinestatic |
Recursively combines multiple values into the hash state.
This is the primary utility for users implementing PwHashValue. It allows you to hash all members of a struct in a single call.
Example:
|
inlinestatic |
Combines a single value into the hash state.
This function acts as the gateway to the hash_value_dispatcher. It automatically detects if val should be hashed via a custom PwHashValue function, as a pointer, or via std::hash.
|
inlinestatic |
Combines a contiguous range of elements into the hash state.
This is intended for arrays or buffers where the order of elements matters.
uint8_t.| h | The current state (passed by move). |
| data | A pointer to the first element in the range. |
| size | The number of elements to hash. |
|
inlinestatic |
Combines a range of elements where the order does not affect the output.
This is intended for unordered containers like sets or maps. It works by hashing each element independently and combining them using commutative operations (addition), ensuring that {A, B} results in the same hash as {B, A}.
| h | The current state (passed by move). |
| first | The starting iterator of the range. |
| last | The ending iterator of the range. |
Mixes a raw integer value into the current hash state.
This implementation is based on boost::hash_combine.
| h | The current state (passed by move). |
| val | The raw integer value to mix in. |