OR-Tools  9.6
hash.h
Go to the documentation of this file.
1 // Copyright 2010-2022 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #ifndef OR_TOOLS_BASE_HASH_H_
15 #define OR_TOOLS_BASE_HASH_H_
16 
17 #include <array>
18 #include <string>
19 #include <utility>
20 
22 
23 // In SWIG mode, we don't want anything besides these top-level includes.
24 #if !defined(SWIG)
25 
26 namespace operations_research {
27 uint64_t fasthash64(const void* buf, size_t len, uint64_t seed);
28 
29 // 64 bit version.
30 static inline void mix(uint64_t& a, uint64_t& b, uint64_t& c) { // NOLINT
31  a -= b;
32  a -= c;
33  a ^= (c >> 43);
34  b -= c;
35  b -= a;
36  b ^= (a << 9);
37  c -= a;
38  c -= b;
39  c ^= (b >> 8);
40  a -= b;
41  a -= c;
42  a ^= (c >> 38);
43  b -= c;
44  b -= a;
45  b ^= (a << 23);
46  c -= a;
47  c -= b;
48  c ^= (b >> 5);
49  a -= b;
50  a -= c;
51  a ^= (c >> 35);
52  b -= c;
53  b -= a;
54  b ^= (a << 49);
55  c -= a;
56  c -= b;
57  c ^= (b >> 11);
58  a -= b;
59  a -= c;
60  a ^= (c >> 12);
61  b -= c;
62  b -= a;
63  b ^= (a << 18);
64  c -= a;
65  c -= b;
66  c ^= (b >> 22);
67 }
68 } // namespace operations_research
69 
70 #endif // SWIG
71 
72 namespace util_hash {
73 
74 inline uint64_t Hash(uint64_t num, uint64_t c) {
75  uint64_t b = uint64_t{0xe08c1d668b756f82}; // More of the golden ratio.
76  operations_research::mix(num, b, c);
77  return c;
78 }
79 
80 inline uint64_t Hash(uint64_t a, uint64_t b, uint64_t c) {
82  return c;
83 }
84 
85 } // namespace util_hash
86 
87 #endif // OR_TOOLS_BASE_HASH_H_
int64_t b
int64_t a
Collection of objects used to extend the Constraint Solver library.
static void mix(uint64_t &a, uint64_t &b, uint64_t &c)
Definition: hash.h:30
uint64_t fasthash64(const void *buf, size_t len, uint64_t seed)
Definition: hash.cc:36
Definition: hash.h:72
uint64_t Hash(uint64_t num, uint64_t c)
Definition: hash.h:74