/src/spirv-tools/source/util/hash_combine.h
Line | Count | Source |
1 | | // Copyright (c) 2022 The Khronos Group Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef SOURCE_UTIL_HASH_COMBINE_H_ |
16 | | #define SOURCE_UTIL_HASH_COMBINE_H_ |
17 | | |
18 | | #include <cstddef> |
19 | | #include <functional> |
20 | | #include <vector> |
21 | | |
22 | | namespace spvtools { |
23 | | namespace utils { |
24 | | |
25 | | // Helpers for incrementally computing hashes. |
26 | | // For reference, see |
27 | | // http://open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3876.pdf |
28 | | |
29 | | template <typename T> |
30 | 6.60M | inline size_t hash_combine(std::size_t seed, const T& val) { |
31 | 6.60M | return seed ^ (std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); |
32 | 6.60M | } unsigned long spvtools::utils::hash_combine<unsigned int>(unsigned long, unsigned int const&) Line | Count | Source | 30 | 5.47M | inline size_t hash_combine(std::size_t seed, const T& val) { | 31 | 5.47M | return seed ^ (std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); | 32 | 5.47M | } |
unsigned long spvtools::utils::hash_combine<bool>(unsigned long, bool const&) Line | Count | Source | 30 | 519k | inline size_t hash_combine(std::size_t seed, const T& val) { | 31 | 519k | return seed ^ (std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); | 32 | 519k | } |
unsigned long spvtools::utils::hash_combine<spv::FPEncoding>(unsigned long, spv::FPEncoding const&) Line | Count | Source | 30 | 610k | inline size_t hash_combine(std::size_t seed, const T& val) { | 31 | 610k | return seed ^ (std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); | 32 | 610k | } |
unsigned long spvtools::utils::hash_combine<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 30 | 1.38k | inline size_t hash_combine(std::size_t seed, const T& val) { | 31 | 1.38k | return seed ^ (std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); | 32 | 1.38k | } |
|
33 | | |
34 | | template <typename T> |
35 | 555k | inline size_t hash_combine(std::size_t hash, const std::vector<T>& vals) { |
36 | 794k | for (const T& val : vals) { |
37 | 794k | hash = hash_combine(hash, val); |
38 | 794k | } |
39 | 555k | return hash; |
40 | 555k | } unsigned long spvtools::utils::hash_combine<unsigned int>(unsigned long, std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > const&) Line | Count | Source | 35 | 491k | inline size_t hash_combine(std::size_t hash, const std::vector<T>& vals) { | 36 | 726k | for (const T& val : vals) { | 37 | 726k | hash = hash_combine(hash, val); | 38 | 726k | } | 39 | 491k | return hash; | 40 | 491k | } |
unsigned long spvtools::utils::hash_combine<std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > >(unsigned long, std::__1::vector<std::__1::vector<unsigned int, std::__1::allocator<unsigned int> >, std::__1::allocator<std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > > > const&) Line | Count | Source | 35 | 63.7k | inline size_t hash_combine(std::size_t hash, const std::vector<T>& vals) { | 36 | 68.3k | for (const T& val : vals) { | 37 | 68.3k | hash = hash_combine(hash, val); | 38 | 68.3k | } | 39 | 63.7k | return hash; | 40 | 63.7k | } |
|
41 | | |
42 | 0 | inline size_t hash_combine(std::size_t hash) { return hash; } |
43 | | |
44 | | template <typename T, typename... Types> |
45 | | inline size_t hash_combine(std::size_t hash, const T& val, |
46 | 1.30M | const Types&... args) { |
47 | 1.30M | return hash_combine(hash_combine(hash, val), args...); |
48 | 1.30M | } unsigned long spvtools::utils::hash_combine<unsigned int, bool>(unsigned long, unsigned int const&, bool const&) Line | Count | Source | 46 | 462k | const Types&... args) { | 47 | 462k | return hash_combine(hash_combine(hash, val), args...); | 48 | 462k | } |
unsigned long spvtools::utils::hash_combine<unsigned int, spv::FPEncoding>(unsigned long, unsigned int const&, spv::FPEncoding const&) Line | Count | Source | 46 | 610k | const Types&... args) { | 47 | 610k | return hash_combine(hash_combine(hash, val), args...); | 48 | 610k | } |
unsigned long spvtools::utils::hash_combine<unsigned int, unsigned int, bool, bool, unsigned int, unsigned int, unsigned int>(unsigned long, unsigned int const&, unsigned int const&, bool const&, bool const&, unsigned int const&, unsigned int const&, unsigned int const&) Line | Count | Source | 46 | 28.5k | const Types&... args) { | 47 | 28.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 28.5k | } |
unsigned long spvtools::utils::hash_combine<unsigned int, bool, bool, unsigned int, unsigned int, unsigned int>(unsigned long, unsigned int const&, bool const&, bool const&, unsigned int const&, unsigned int const&, unsigned int const&) Line | Count | Source | 46 | 28.5k | const Types&... args) { | 47 | 28.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 28.5k | } |
unsigned long spvtools::utils::hash_combine<bool, bool, unsigned int, unsigned int, unsigned int>(unsigned long, bool const&, bool const&, unsigned int const&, unsigned int const&, unsigned int const&) Line | Count | Source | 46 | 28.5k | const Types&... args) { | 47 | 28.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 28.5k | } |
unsigned long spvtools::utils::hash_combine<bool, unsigned int, unsigned int, unsigned int>(unsigned long, bool const&, unsigned int const&, unsigned int const&, unsigned int const&) Line | Count | Source | 46 | 28.5k | const Types&... args) { | 47 | 28.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 28.5k | } |
unsigned long spvtools::utils::hash_combine<unsigned int, std::__1::vector<std::__1::vector<unsigned int, std::__1::allocator<unsigned int> >, std::__1::allocator<std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > > > >(unsigned long, unsigned int const&, std::__1::vector<std::__1::vector<unsigned int, std::__1::allocator<unsigned int> >, std::__1::allocator<std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > > > const&) Line | Count | Source | 46 | 63.7k | const Types&... args) { | 47 | 63.7k | return hash_combine(hash_combine(hash, val), args...); | 48 | 63.7k | } |
unsigned long spvtools::utils::hash_combine<unsigned int, unsigned int>(unsigned long, unsigned int const&, unsigned int const&) Line | Count | Source | 46 | 28.5k | const Types&... args) { | 47 | 28.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 28.5k | } |
unsigned long spvtools::utils::hash_combine<unsigned int, unsigned int, unsigned int>(unsigned long, unsigned int const&, unsigned int const&, unsigned int const&) Line | Count | Source | 46 | 28.5k | const Types&... args) { | 47 | 28.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 28.5k | } |
Unexecuted instantiation: unsigned long spvtools::utils::hash_combine<unsigned int, unsigned int, unsigned int, unsigned int>(unsigned long, unsigned int const&, unsigned int const&, unsigned int const&, unsigned int const&) Unexecuted instantiation: unsigned long spvtools::utils::hash_combine<unsigned int, unsigned int, std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > >(unsigned long, unsigned int const&, unsigned int const&, std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > const&) Unexecuted instantiation: unsigned long spvtools::utils::hash_combine<unsigned int, std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > >(unsigned long, unsigned int const&, std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > const&) |
49 | | |
50 | | } // namespace utils |
51 | | } // namespace spvtools |
52 | | |
53 | | #endif // SOURCE_UTIL_HASH_COMBINE_H_ |