<xstd/ints/ext/boost/hash2.hpp>¶
xstd::hash_append_int¶
template<class Hash, class Flavor, integer T>
constexpr auto hash_append_int(Hash& h, const Flavor& f, T v) -> void;
Appends an integer's value to a Boost.Hash2 algorithm, so that equal values of every width hash the same.
Template parameters¶
| Parameter | Meaning |
|---|---|
Hash |
the hash algorithm |
Flavor |
the flavor Hash2 appends with |
T |
the integer type |
Constraints: T models integer. char and bool, which Hash2's own hash_append treats as integers, are turned
away.
Parameters¶
| Parameter | Meaning |
|---|---|
h |
the algorithm to append to |
f |
the flavor |
v |
the value to append |
Effects¶
Effects: Let w be numeric_limits<T>::digits + (is_signed_v<T> ? 1 : 0).
- If
w <= 64, callsboost::hash2::hash_append(h, f, static_cast<N>(v)), whereNis the first ofuint8_t,uint16_t,uint32_tanduint64_twith at leastwdigits, made signed whenTis signed. So every name for a standard width hashes as the exact-width type of that width, and a bit-precise type as the narrowest standard type that holds it. - Otherwise, with
uthe value converted tomake_unsigned_t<T>, callsboost::hash2::hash_append(h, f, static_cast<uint64_t>(u >> 64 * k))for eachkbeloww / 64, low word first, and then, ifw % 64is not zero, appends one moreuint64_tholding the remainingw % 64bits, sign-extended whenTis signed and zero-extended otherwise.
Exceptions¶
Throws: Any exception hash_append or h.update throws. It is not noexcept.
Remarks¶
It is a function to call in place of boost::hash2::hash_append, not a customization Hash2 finds.
Notes¶
- Under
little_endian_flavorthe message is the value's two's-complement bytes, least significant first, for every type it takes, at run time and in constant evaluation. - Every 128-bit type,
int128, Boost's, Abseil's and_BitInt(128), gives the same FNV-1a digests, and underbig_endian_flavorthe words stay low first while the bytes within each reverse. - Only the value is hashed: the padding of a
bit_int<24>never reaches the message, under the default flavor too. - The header compiles on its own wherever Boost.Hash2 is found.
See also¶
| Entity | Relation |
|---|---|
integer |
what T models |
int128, uint128, bit_int, bit_uint |
integers it hashes by value |
make_unsigned<boost::int128::int128> |
makes Boost's pair an integer it takes |