qxLib
hash.h
Go to the documentation of this file.
1 /**
2 
3  @file hash.h
4  @author Khrapov
5  @date 18.08.2025
6  @copyright © Nick Khrapov, 2025. All right reserved.
7 
8 **/
9 #pragma once
10 
11 #include <cstddef>
12 
13 namespace qx
14 {
15 
16 /**
17  @brief Get an object hash
18  @details A simple wrapper over std::hash
19  that removes the need to specify the type and unnecessary parentheses.
20  @tparam T - object type
21  @param value - object value
22  @retval - object hash
23 **/
24 template<typename T>
25 constexpr size_t get_hash(const T& value) noexcept
26 {
27  return std::hash<T>()(value);
28 }
29 
30 /**
31  @brief Combine hashes
32  @tparam T - object type
33  @param seed - input/output hash value
34  @param value - object to hash
35 **/
36 template<typename T>
37 constexpr void hash_combine(size_t& seed, const T& value) noexcept
38 {
39  seed ^= get_hash(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
40 }
41 
42 } // namespace qx
constexpr size_t get_hash(const T &value) noexcept
Get an object hash.
Definition: hash.h:25
constexpr void hash_combine(size_t &seed, const T &value) noexcept
Combine hashes.
Definition: hash.h:37