View in context in the libbitcoin Slack #general mirror.
// 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;
}