HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hash.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7
8#include "required.hpp"
9#include "assert.hpp"
10#include <utility>
11#include <array>
12#include <type_traits>
13
14namespace tt {
15
16[[nodiscard]] inline size_t hash_mix_two(size_t hash1, size_t hash2) noexcept
17{
18 if constexpr (sizeof(size_t) == 8) {
19 return hash1 + 0x9e3779b97f681800 + (hash2 << 6) + (hash2 >> 2);
20 } else if constexpr (sizeof(size_t) == 4) {
21 return hash1 + 0x9e3779b9 + (hash2 << 6) + (hash2 >> 2);
22 } else {
23 tt_not_implemented();
24 }
25}
26
27template<typename First, typename Second, typename... Args>
28[[nodiscard]] size_t hash_mix(First &&first, Second &&second, Args &&... args) noexcept {
29 if constexpr (sizeof...(args) == 0) {
30 return hash_mix_two(
31 std::hash<std::remove_cvref_t<First>>{}(std::forward<First>(first)),
32 std::hash<std::remove_cvref_t<Second>>{}(std::forward<Second>(second))
33 );
34 } else {
35 return hash_mix_two(
36 std::hash<std::remove_cvref_t<First>>{}(std::forward<First>(first)),
37 hash_mix(std::forward<Second>(second), std::forward<Args>(args)...)
38 );
39 }
40}
41
42
43}