Maipa's Standard Library Extension 1.5.6
mstd
Loading...
Searching...
No Matches
hash.hpp
1/*
2 * mstd - Maipa's Standard Library
3 *
4 * Licensed under the BSD 3-Clause License with Attribution Requirement.
5 * See the LICENSE file for details: https://github.com/MAIPA01/mstd/blob/main/LICENSE
6 *
7 * Copyright (c) 2025, Patryk Antosik (MAIPA01)
8 */
9
10#pragma once
11#ifndef _MSTD_HASH_HPP_
12 #define _MSTD_HASH_HPP_
13
14 #include <mstd/config.hpp>
15
17_MSTD_WARNING("this is only available for c++17 and greater!");
18 #else
19
20 #include <mstd/types.hpp>
21
22namespace mstd {
23 template<class T, class... Ts>
24 inline void hash_append(size_t& hashValue, const T& value, const Ts&... values) {
25 static _MSTD_CONSTEXPR17 const size_t left_shift = 6;
26 static _MSTD_CONSTEXPR17 const size_t right_shift = 2;
27 static _MSTD_CONSTEXPR17 const size_t magic_number = 0x9E37'79B9;
28
30
31 if _MSTD_CONSTEXPR17 (sizeof...(Ts) != 0) { hash_append(hashValue, values...); }
32 }
33
34 template<class T0, class T1, class... Ts>
35 inline size_t hash_combine(const T0& value0, const T1& value1, const Ts&... values) {
36 size_t hashValue = 0;
38 return hashValue;
39 }
40
41 template<class Iter>
42 inline void hash_range(size_t& seed, const Iter& begin, const Iter& end) {
43 for (Iter i = begin; i != end; ++i) { hash_append(seed, *i); }
44 }
45} // namespace mstd
46
47 #endif
48#endif
#define _MSTD_HAS_CXX17
Definition config.hpp:45
#define _MSTD_CONSTEXPR17
Definition config.hpp:76
Definition arithmetic_types.hpp:23
void hash_range(size_t &seed, const Iter &begin, const Iter &end)
Definition hash.hpp:42
size_t hash_combine(const T0 &value0, const T1 &value1, const Ts &... values)
Definition hash.hpp:35
void hash_append(size_t &hashValue, const T &value, const Ts &... values)
Definition hash.hpp:24