mini-llvm 0.1.0
Loading...
Searching...
No Matches
HashCombine.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <climits>
6#include <cstddef>
7#include <cstdint>
8#include <functional>
9
10namespace mini_llvm {
11
12// https://www.boost.org/doc/libs/1_86_0/libs/container_hash/doc/html/hash.html
13
14// Copyright 2005-2014 Daniel James.
15// Copyright 2021, 2022 Peter Dimov.
16// Distributed under the Boost Software License, Version 1.0.
17// https://www.boost.org/LICENSE_1_0.txt
18// Modified under the MIT License.
19
20namespace detail {
21
22template <size_t>
23struct hash_mix_impl;
24
25template <>
26struct hash_mix_impl<64> {
27 static constexpr uint64_t fn(uint64_t x) noexcept {
28 constexpr uint64_t m = 0xe9846af9b1a615d;
29
30 x ^= x >> 32;
31 x *= m;
32 x ^= x >> 32;
33 x *= m;
34 x ^= x >> 28;
35
36 return x;
37 }
38};
39
40template <>
41struct hash_mix_impl<32> {
42 static constexpr uint32_t fn(uint32_t x) noexcept {
43 constexpr uint32_t m1 = 0x21f0aaad;
44 constexpr uint32_t m2 = 0x735a2d97;
45
46 x ^= x >> 16;
47 x *= m1;
48 x ^= x >> 15;
49 x *= m2;
50 x ^= x >> 15;
51
52 return x;
53 }
54};
55
56inline constexpr size_t hash_mix(size_t v) noexcept {
57 return hash_mix_impl<sizeof(size_t) * CHAR_BIT>::fn(v);
58}
59
60} // namespace detail
61
62template <typename T, typename Hash = std::hash<T>>
63constexpr void hash_combine(size_t &seed, const T &v) noexcept {
64 seed = detail::hash_mix(seed + 0x9e3779b9 + Hash()(v));
65}
66
67} // namespace mini_llvm
Definition GraphColoringAllocator.h:13
constexpr void hash_combine(size_t &seed, const T &v) noexcept
Definition HashCombine.h:63