View in context in the libbitcoin Slack #general mirror.
aabbccdd.......:0, in the point table the hashmap key is aabbccdd?aabbccdd and the 0 . This requires a mathematical operation called hash combination.namespace std
{
template<>
struct hash<bc::system::chain::point>
{
size_t operator()(const bc::system::chain::point& value) const NOEXCEPT
{
return bc::system::hash_combine(value.index(),
bc::system::unique_hash(value.hash()));
}
};
template<>
struct hash<bc::system::chain::point_cref>
{
std::size_t operator()(
const bc::system::chain::point_cref& value) const NOEXCEPT
{
return std::hash<bc::system::chain::point>{}(value.get());
}
};// Combine hash values, such as a pair of djb2_hash outputs.
INLINE constexpr size_t hash_combine(size_t left, size_t right) NOEXCEPT
{
return left ^ shift_left(right, one);
}template <size_t Size>
INLINE constexpr size_t unique_hash(const data_array<Size>& key) NOEXCEPT
{
constexpr auto size = std::min(Size, sizeof(size_t));
// This optimization breaks data portability (by endianness).
// Could be modified to use an endian conversion vs. simple copy.
size_t value{};
std::copy_n(key.begin(), size, system::byte_cast(value).begin());
return value;
}// Objectives: deterministic, uniform distribution, efficient computation.
INLINE constexpr size_t djb2_hash(const data_slice& data) NOEXCEPT
{
// Nothing special here except that it tested well against collisions.
auto hash = 5381_size;
// Efficient sum of ((hash * 33) + byte) for all bytes.
for (const auto byte: data)
hash = (shift_left(hash, 5_size) + hash) + byte;
return hash;
}