Enrollment 28.2.0
Loading...
Searching...
No Matches
HashUtils.h
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <cstddef>
10#include <cstdint>
11#include <vector>
12
13namespace inno::detail
14{
15 inline std::size_t HashCombine(std::size_t seed, std::size_t value) noexcept
16 {
17 constexpr std::size_t MixConstant = 0x9e3779b9U; // fractional part of 2^32 / phi (golden ratio)
18 constexpr std::size_t ShiftLeft = 6U;
19 constexpr std::size_t ShiftRight = 2U;
20 return seed ^ (value + MixConstant + (seed << ShiftLeft) + (seed >> ShiftRight));
21 }
22
23 inline std::size_t HashBytes(const std::vector<uint8_t>& data) noexcept
24 {
25 std::size_t seed = data.size();
26 for (const uint8_t byte : data)
27 {
28 seed = HashCombine(seed, static_cast<std::size_t>(byte));
29 }
30 return seed;
31 }
32} // namespace inno::detail