Jlm
Loading...
Searching...
No Matches
Hash.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_UTIL_HASH_HPP
7#define JLM_UTIL_HASH_HPP
8
9#include <functional>
10#include <string_view>
11
12namespace jlm::util
13{
14
18template<typename T>
19struct Hash : std::hash<T>
20{
21};
22
23template<typename First, typename Second>
24struct Hash<std::pair<First, Second>>
25{
26 std::size_t
27 operator()(const std::pair<First, Second> & value) const noexcept
28 {
29 return Hash<First>()(value.first) ^ Hash<Second>()(value.second) << 1;
30 }
31};
32
43template<typename... Args>
44void
45combineHashesWithSeed(std::size_t & seed, std::size_t hash, Args... args)
46{
47 seed ^= hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
48 (combineHashesWithSeed(seed, args), ...);
49}
50
61template<typename... Args>
62std::size_t
63CombineHashes(std::size_t hash, Args... args)
64{
65 std::size_t seed = 0;
66 combineHashesWithSeed(seed, hash, std::forward<Args>(args)...);
67 return seed;
68}
69
70}
71
72#endif
void combineHashesWithSeed(std::size_t &seed, std::size_t hash, Args... args)
Definition Hash.hpp:45
std::size_t CombineHashes(std::size_t hash, Args... args)
Definition Hash.hpp:63
std::size_t operator()(const std::pair< First, Second > &value) const noexcept
Definition Hash.hpp:27