/src/spirv-tools/source/util/hash_combine.h
Line | Count | Source (jump to first uncovered line) |
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 | 4.72M | inline size_t hash_combine(std::size_t seed, const T& val) { |
31 | 4.72M | return seed ^ (std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); |
32 | 4.72M | } unsigned long spvtools::utils::hash_combine<unsigned int>(unsigned long, unsigned int const&) Line | Count | Source | 30 | 3.90M | inline size_t hash_combine(std::size_t seed, const T& val) { | 31 | 3.90M | return seed ^ (std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); | 32 | 3.90M | } |
unsigned long spvtools::utils::hash_combine<bool>(unsigned long, bool const&) Line | Count | Source | 30 | 383k | inline size_t hash_combine(std::size_t seed, const T& val) { | 31 | 383k | return seed ^ (std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); | 32 | 383k | } |
unsigned long spvtools::utils::hash_combine<spv::FPEncoding>(unsigned long, spv::FPEncoding const&) Line | Count | Source | 30 | 436k | inline size_t hash_combine(std::size_t seed, const T& val) { | 31 | 436k | return seed ^ (std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); | 32 | 436k | } |
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 | 727 | inline size_t hash_combine(std::size_t seed, const T& val) { | 31 | 727 | return seed ^ (std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); | 32 | 727 | } |
|
33 | | |
34 | | template <typename T> |
35 | 374k | inline size_t hash_combine(std::size_t hash, const std::vector<T>& vals) { |
36 | 536k | for (const T& val : vals) { |
37 | 536k | hash = hash_combine(hash, val); |
38 | 536k | } |
39 | 374k | return hash; |
40 | 374k | } 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 | 334k | inline size_t hash_combine(std::size_t hash, const std::vector<T>& vals) { | 36 | 493k | for (const T& val : vals) { | 37 | 493k | hash = hash_combine(hash, val); | 38 | 493k | } | 39 | 334k | return hash; | 40 | 334k | } |
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 | 40.7k | inline size_t hash_combine(std::size_t hash, const std::vector<T>& vals) { | 36 | 43.4k | for (const T& val : vals) { | 37 | 43.4k | hash = hash_combine(hash, val); | 38 | 43.4k | } | 39 | 40.7k | return hash; | 40 | 40.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 | 943k | const Types&... args) { |
47 | 943k | return hash_combine(hash_combine(hash, val), args...); |
48 | 943k | } unsigned long spvtools::utils::hash_combine<unsigned int, bool>(unsigned long, unsigned int const&, bool const&) Line | Count | Source | 46 | 342k | const Types&... args) { | 47 | 342k | return hash_combine(hash_combine(hash, val), args...); | 48 | 342k | } |
unsigned long spvtools::utils::hash_combine<unsigned int, spv::FPEncoding>(unsigned long, unsigned int const&, spv::FPEncoding const&) Line | Count | Source | 46 | 436k | const Types&... args) { | 47 | 436k | return hash_combine(hash_combine(hash, val), args...); | 48 | 436k | } |
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 | 20.5k | const Types&... args) { | 47 | 20.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 20.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 | 20.5k | const Types&... args) { | 47 | 20.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 20.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 | 20.5k | const Types&... args) { | 47 | 20.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 20.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 | 20.5k | const Types&... args) { | 47 | 20.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 20.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 | 40.7k | const Types&... args) { | 47 | 40.7k | return hash_combine(hash_combine(hash, val), args...); | 48 | 40.7k | } |
unsigned long spvtools::utils::hash_combine<unsigned int, unsigned int>(unsigned long, unsigned int const&, unsigned int const&) Line | Count | Source | 46 | 20.5k | const Types&... args) { | 47 | 20.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 20.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 | 20.5k | const Types&... args) { | 47 | 20.5k | return hash_combine(hash_combine(hash, val), args...); | 48 | 20.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_ |