1 /*
2 * Copyright 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #pragma once
18
19 #include <functional>
20
21 namespace android {
hashCombineSingleHashed(size_t & combinedHash,size_t hash)22 static inline void hashCombineSingleHashed(size_t& combinedHash, size_t hash) {
23 combinedHash = 31 * combinedHash + hash;
24 }
25
26 template<typename T>
hashCombineSingle(size_t & combinedHash,const T & val)27 static inline void hashCombineSingle(size_t& combinedHash, const T& val) {
28 hashCombineSingleHashed(combinedHash, std::hash<T>{}(val));
29 }
30
31 template<typename... Types>
hashCombine(const Types &...args)32 static inline size_t hashCombine(const Types& ... args) {
33 size_t hash = 0;
34 ( hashCombineSingle(hash, args), ... );
35 return hash;
36 }
37
38 } // namespace android