<xstd/bits/bit_functional/bit_hash.hpp>¶
bit_hash_append¶
- Constraints:
Hashmodelshash_algorithm, and:- for the first form,
Tis an owner of ours, of either reading, or a set view. A sequence view,bit_spanor a window, is turned away, asspanhas no hash, thoughbit_equalcompares it with its owner; - for the second,
const Rmodelsranges::contiguous_rangeandranges::sized_range, and its value type is a type the first form takes whose width the type fixes, or a built-in array or anarrayof such, nested to any depth: the planes of a board game's position, asbit_fixed_set<64>[2][6]or aspan<const bit_fixed_set<64>>.
- for the first form,
- The bit string of
xis ⌈N/8⌉ bytes for its widthN, bytejholding the positions[8j, 8j + 8)least significant bit first and the bits pastNzero. For a set of run-time width it stops after the byte that holds the last key, so it is empty for an empty set: equal sets need not share a width. -
Effects: For the first form:
- where the type of
xfixes a width of zero,boost::hash2::hash_append(h, f, '\x00'), the one byte Hash2 writes for an emptyarray; - otherwise, updates
hwith the bit string ofx; then, where the width is a run-time value, an inplace capacity included, callsboost::hash2::hash_append_size(h, f, n), wherenis a sequence's size in bits and a set's bit string's length in bytes.
For the second form: - where the type of
rfixes a count of zero,boost::hash2::hash_append(h, f, '\x00'); - otherwise appends each element in order, by the first form or, for a nested array, by this one; then, where the type ofrfixes no count, callsboost::hash2::hash_append_size(h, f, ranges::size(r)). A built-in array, anarrayand aspanof static extent fix one. - The block type is no part of the message, andforders the bytes of the appended size alone. Underlittle_endian_flavor:xmessage basic_bit_fixed_set<size_t, uint64_t, 10>{1, 3, 5, 9}bytes 2A 02bit_fixed_set<0>(),bit_array<0>()byte 00basic_bit_vector<vector<uint64_t>>(10), its even positionstruebytes 55 01, then the size 10basic_bit_set<size_t, vector<uint64_t>>{1, 3, 5}byte 2A, then the size 1basic_bit_set<size_t, vector<uint64_t>>{1, 3, 64}bytes 0A 00 00 00 00 00 00 00 01, then the size 9an empty basic_bit_vector<vector<uint64_t>>orbasic_bit_set<size_t, vector<uint64_t>>the size 0 array<bit_fixed_set<64>, 0>()byte 00 - where the type of
-
Remarks: Wherever the storage holds the bit string, a little-endian target and a block of a built-in type whose value bits fill its object, the string goes in as one
updateover the storage. Elsewhere, a class-type block and a constant evaluation included, the same bytes are assembled, up to 256 anupdate. A Hash2 digest does not depend on how its message is split into updates, so the digest is the same either way. - Remarks: Where each element of
ris an owner whose object is its bit string, asbit_fixed_set<64>inuint64_tblocks is, and each nestedarraymeasures as wide as its elements, the whole range goes in as oneupdate. Abit_fixed_set<50>, eight bytes for a seven-byte string, goes in an element at a time, to the same digest. - Remarks: It is usable in a constant expression.
- Where
xstd::ranges::bit_equal(x, y)istrue,xandyappend the same message: an owner and its view, two owners over different blocks, and a run-time set at any two widths. So what compares equal hashes equal.
bit_hash¶
template<class T, hash_algorithm H, class Flavor>
requires see below
class bit_hash {
public:
using is_avalanching = bool_constant<hash_algorithm_is_avalanching_v<H>>;
using is_transparent = void;
bit_hash() = default;
constexpr explicit bit_hash(uint64_t seed);
constexpr bit_hash(const unsigned char* p, size_t n);
template<class U>
requires see below
constexpr auto operator()(const U& v) const -> size_t;
};
As xstd-misc's hash, with:
- Constraints:
Tis a typebit_hash_appendtakes, by either form. - One algorithm,
H, defaulted toboost::hash2::xxhash_64on every target, wheresize_ttakes Hash2's fold of its result. There is noH32and nohash_type;is_avalanchingis read fromH, so it istrueunder xxHash and SipHash andfalseunder FNV-1a. is_transparentis declared: equal bits hash equal whatever blocks or storage hold them, so a lookup may cross containers of one reading.- There is no specialization for a string key.
operator():- Constraints:
UisT, orxstd::ranges::bit_equal(x, y)is valid for aconst T& xand aconst U& y; andUis a typebit_hash_appendtakes. Sobit_hash<bit_array<64>>does not take abit_span. - Effects: Copies the prototype to
hand callsbit_hash_append(h, Flavor(), v). The prototype is unchanged. - Returns:
boost::hash2::get_integral_result<size_t>(h). vis appended as theUit is, not converted toT.
- Constraints:
- It hashes the bits, not the value as its standard model has it: no key and no count, so
bit_hash<T, H>()(x)and xstd-misc'shash<T, H>()(x)differ. - Equal bits hash equal: a
bit_fixed_set<100>and itsbit_set_view, the same set overuint8_tblocks, and abit_vector, abasic_bit_small_vector<uint8_t, 9>and abasic_bit_inplace_vector<uint64_t, 256>of one value. - Where
hash<T>is enabled for an owner or a set viewT, it is this hash at its defaults:bit_hash<T>()(x)ishash<T>()(x).