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 <utility>
10#include <array>
11#include <type_traits>
12
13hi_export_module(hikogui.utility.hash);
14
15hi_export namespace hi::inline v1 {
16
17[[nodiscard]] constexpr std::size_t hash_mix_two(std::size_t hash1, std::size_t hash2) noexcept
18{
19 if constexpr (sizeof(std::size_t) == 8) {
20 return hash1 + 0x9e3779b97f681800 + (hash2 << 6) + (hash2 >> 2);
21 } else if constexpr (sizeof(std::size_t) == 4) {
22 return hash1 + 0x9e3779b9 + (hash2 << 6) + (hash2 >> 2);
23 } else {
24 hi_not_implemented();
25 }
26}
27
28template<typename First, typename Second, typename... Args>
29[[nodiscard]] constexpr std::size_t hash_mix(First &&first, Second &&second, Args &&...args) noexcept
30{
31 if constexpr (sizeof...(args) == 0) {
32 return hash_mix_two(
33 std::hash<std::remove_cvref_t<First>>{}(std::forward<First>(first)),
34 std::hash<std::remove_cvref_t<Second>>{}(std::forward<Second>(second)));
35 } else {
36 return hash_mix_two(
37 std::hash<std::remove_cvref_t<First>>{}(std::forward<First>(first)),
38 hash_mix(std::forward<Second>(second), std::forward<Args>(args)...));
39 }
40}
41
42} // namespace hi::inline v1
Utilities to assert and bound check.
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377