]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/core/src/detail/hash.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / prometheus-cpp / core / src / detail / hash.h
CommitLineData
1e59de90
TL
1#pragma once
2
3#include <cstddef>
4#include <functional>
5
6namespace prometheus {
7
8namespace detail {
9
10/// \brief Combine a hash value with nothing.
11/// It's the boundary condition of this serial functions.
12///
13/// \param seed Not effect.
14inline void hash_combine(std::size_t *) {}
15
16/// \brief Combine the given hash value with another obeject.
17///
18/// \param seed The given hash value. It's a input/output parameter.
19/// \param value The object that will be combined with the given hash value.
20template <typename T>
21inline void hash_combine(std::size_t *seed, const T &value) {
22 *seed ^= std::hash<T>{}(value) + 0x9e3779b9 + (*seed << 6) + (*seed >> 2);
23}
24
25/// \brief Combine the given hash value with another objects. It's a recursion。
26///
27/// \param seed The give hash value. It's a input/output parameter.
28/// \param value The object that will be combined with the given hash value.
29/// \param args The objects that will be combined with the given hash value.
30template <typename T, typename... Types>
31inline void hash_combine(std::size_t *seed, const T &value,
32 const Types &...args) {
33 hash_combine(seed, value);
34 hash_combine(seed, args...);
35}
36
37/// \brief Compute a hash value of the given args.
38///
39/// \param args The arguments that will be computed hash value.
40/// \return The hash value of the given args.
41template <typename... Types>
42inline std::size_t hash_value(const Types &...args) {
43 std::size_t seed = 0;
44 hash_combine(&seed, args...);
45 return seed;
46}
47
48} // namespace detail
49
50} // namespace prometheus