HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hash.hpp
1// Copyright Take Vos 2020-2021.
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#include "../macros.hpp"
8#include "assert.hpp"
9#include "terminate.hpp"
10#include <utility>
11#include <array>
12#include <type_traits>
13#include <exception>
14
15hi_export_module(hikogui.utility.hash);
16
17hi_export namespace hi::inline v1 {
18
19[[nodiscard]] constexpr std::size_t hash_mix_two(std::size_t hash1, std::size_t hash2) noexcept
20{
21 if constexpr (sizeof(std::size_t) == 8) {
22 return hash1 + 0x9e3779b97f681800 + (hash2 << 6) + (hash2 >> 2);
23 } else if constexpr (sizeof(std::size_t) == 4) {
24 return hash1 + 0x9e3779b9 + (hash2 << 6) + (hash2 >> 2);
25 } else {
26 hi_not_implemented();
27 }
28}
29
30template<typename First, typename Second, typename... Args>
31[[nodiscard]] constexpr std::size_t hash_mix(First &&first, Second &&second, Args &&...args) noexcept
32{
33 if constexpr (sizeof...(args) == 0) {
34 return hash_mix_two(
35 std::hash<std::remove_cvref_t<First>>{}(std::forward<First>(first)),
36 std::hash<std::remove_cvref_t<Second>>{}(std::forward<Second>(second)));
37 } else {
38 return hash_mix_two(
39 std::hash<std::remove_cvref_t<First>>{}(std::forward<First>(first)),
40 hash_mix(std::forward<Second>(second), std::forward<Args>(args)...));
41 }
42}
43
44} // namespace hi::inline v1
Utilities to assert and bound check.
Utilities for throwing exceptions and terminating the application.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20