Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
hash.h
Go to the documentation of this file.
1// Copyright 2010-2024 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 <cstdint>
19#include <string>
20#include <utility>
21
22// In SWIG mode, we don't want anything besides these top-level includes.
23#if !defined(SWIG)
24
25namespace operations_research {
26uint64_t fasthash64(const void* buf, size_t len, uint64_t seed);
27
28// 64 bit version.
29static inline void mix(uint64_t& a, uint64_t& b, uint64_t& c) { // NOLINT
30 a -= b;
31 a -= c;
32 a ^= (c >> 43);
33 b -= c;
34 b -= a;
35 b ^= (a << 9);
36 c -= a;
37 c -= b;
38 c ^= (b >> 8);
39 a -= b;
40 a -= c;
41 a ^= (c >> 38);
42 b -= c;
43 b -= a;
44 b ^= (a << 23);
45 c -= a;
46 c -= b;
47 c ^= (b >> 5);
48 a -= b;
49 a -= c;
50 a ^= (c >> 35);
51 b -= c;
52 b -= a;
53 b ^= (a << 49);
54 c -= a;
55 c -= b;
56 c ^= (b >> 11);
57 a -= b;
58 a -= c;
59 a ^= (c >> 12);
60 b -= c;
61 b -= a;
62 b ^= (a << 18);
63 c -= a;
64 c -= b;
65 c ^= (b >> 22);
66}
67} // namespace operations_research
68
69#endif // SWIG
70
71namespace util_hash {
72
73inline uint64_t Hash(uint64_t num, uint64_t c) {
74 uint64_t b = uint64_t{0xe08c1d668b756f82}; // More of the golden ratio.
76 return c;
77}
78
79inline uint64_t Hash(uint64_t a, uint64_t b, uint64_t c) {
81 return c;
82}
83
84} // namespace util_hash
85
86#endif // OR_TOOLS_BASE_HASH_H_
int64_t b
Definition table.cc:45
int64_t a
Definition table.cc:44
In SWIG mode, we don't want anything besides these top-level includes.
uint64_t fasthash64(const void *buf, size_t len, uint64_t seed)
Definition hash.cc:36
static void mix(uint64_t &a, uint64_t &b, uint64_t &c)
64 bit version.
Definition hash.h:29
uint64_t Hash(uint64_t num, uint64_t c)
Definition hash.h:73