aboutsummaryrefslogtreecommitdiff
path: root/src/util/hash_impl.hpp
blob: ea9e7d1bd663eb105db36ed406f9b6b63a93f509 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once

#include "hash.hpp"

#include <cstdint>
#include <functional>

/**
 * Combines the hash 'seed' with the hash of 'value'.
 *
 * @param seed A hash that will be mutated
 * @param value A hashable value
 */
template <typename Value>
void hash_combine(std::size_t &seed, const Value &value) noexcept
{
	constexpr std::uint32_t shift_left = 6;
	constexpr std::uint32_t shift_right = 2;

	seed ^= std::hash<Value>()(value) + GOLDEN_RATIO + (seed << shift_left) +
			(seed >> shift_right);
}