GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
hash_utils.h
Go to the documentation of this file.
1// Copyright 2016 The Draco Authors.
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 DRACO_CORE_HASH_UTILS_H_
16#define DRACO_CORE_HASH_UTILS_H_
17
18#include <stdint.h>
19
20#include <cstddef>
21#include <functional>
22
23namespace draco {
24
25template <typename T1, typename T2>
26size_t HashCombine(T1 a, T2 b) {
27 const size_t hash1 = std::hash<T1>()(a);
28 const size_t hash2 = std::hash<T2>()(b);
29 return (hash1 << 2) ^ (hash2 << 1);
30}
31
32template <typename T>
33size_t HashCombine(T a, size_t hash) {
34 const size_t hasha = std::hash<T>()(a);
35 return (hash) ^ (hasha + 239);
36}
37
38inline uint64_t HashCombine(uint64_t a, uint64_t b) {
39 return (a + 1013) ^ (b + 107) << 1;
40}
41
42// Will never return 1 or 0.
43uint64_t FingerprintString(const char *s, size_t len);
44
45// Hash for std::array.
46template <typename T>
47struct HashArray {
48 size_t operator()(const T &a) const {
49 size_t hash = 79; // Magic number.
50 for (unsigned int i = 0; i < std::tuple_size<T>::value; ++i) {
51 hash = HashCombine(hash, ValueHash(a[i]));
52 }
53 return hash;
54 }
55
56 template <typename V>
57 size_t ValueHash(const V &val) const {
58 return std::hash<V>()(val);
59 }
60};
61
62} // namespace draco
63
64#endif // DRACO_CORE_HASH_UTILS_H_
Definition attribute_octahedron_transform.cc:21
uint64_t FingerprintString(const char *s, size_t len)
Definition hash_utils.cc:24
size_t HashCombine(T1 a, T2 b)
Definition hash_utils.h:26
Definition GameApi.h:42
Definition GameApi.h:17
Definition hash_utils.h:47
size_t ValueHash(const V &val) const
Definition hash_utils.h:57
size_t operator()(const T &a) const
Definition hash_utils.h:48