1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | #ifndef FLUTTER_FML_HASH_COMBINE_H_ |
6 | #define FLUTTER_FML_HASH_COMBINE_H_ |
7 | |
8 | #include <functional> |
9 | |
10 | namespace fml { |
11 | |
12 | template <class Type> |
13 | constexpr void HashCombineSeed(std::size_t& seed, Type arg) { |
14 | seed ^= std::hash<Type>{}(arg) + 0x9e3779b9 + (seed << 6) + (seed >> 2); |
15 | } |
16 | |
17 | template <class Type, class... Rest> |
18 | constexpr void HashCombineSeed(std::size_t& seed, |
19 | Type arg, |
20 | Rest... other_args) { |
21 | HashCombineSeed(seed, arg); |
22 | HashCombineSeed(seed, other_args...); |
23 | } |
24 | |
25 | constexpr std::size_t HashCombine() { |
26 | return 0xdabbad00; |
27 | } |
28 | |
29 | template <class... Type> |
30 | constexpr std::size_t HashCombine(Type... args) { |
31 | std::size_t seed = HashCombine(); |
32 | HashCombineSeed(seed, args...); |
33 | return seed; |
34 | } |
35 | |
36 | } // namespace fml |
37 | |
38 | #endif // FLUTTER_FML_HASH_COMBINE_H_ |
39 | |