xref: /aosp_15_r20/external/abseil-cpp/absl/hash/internal/low_level_hash.h (revision 9356374a3709195abf420251b3e825997ff56c0f)
1 // Copyright 2020 The Abseil 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 //     https://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 // This file provides the Google-internal implementation of LowLevelHash.
16 //
17 // LowLevelHash is a fast hash function for hash tables, the fastest we've
18 // currently (late 2020) found that passes the SMHasher tests. The algorithm
19 // relies on intrinsic 128-bit multiplication for speed. This is not meant to be
20 // secure - just fast.
21 //
22 // It is closely based on a version of wyhash, but does not maintain or
23 // guarantee future compatibility with it.
24 
25 #ifndef ABSL_HASH_INTERNAL_LOW_LEVEL_HASH_H_
26 #define ABSL_HASH_INTERNAL_LOW_LEVEL_HASH_H_
27 
28 #include <stdint.h>
29 #include <stdlib.h>
30 
31 #include "absl/base/config.h"
32 
33 namespace absl {
34 ABSL_NAMESPACE_BEGIN
35 namespace hash_internal {
36 
37 // Hash function for a byte array. A 64-bit seed and a set of five 64-bit
38 // integers are hashed into the result.
39 //
40 // To allow all hashable types (including string_view and Span) to depend on
41 // this algorithm, we keep the API low-level, with as few dependencies as
42 // possible.
43 uint64_t LowLevelHash(const void* data, size_t len, uint64_t seed,
44                       const uint64_t salt[5]);
45 
46 // Same as above except the length must be greater than 16.
47 uint64_t LowLevelHashLenGt16(const void* data, size_t len, uint64_t seed,
48                              const uint64_t salt[5]);
49 
50 }  // namespace hash_internal
51 ABSL_NAMESPACE_END
52 }  // namespace absl
53 
54 #endif  // ABSL_HASH_INTERNAL_LOW_LEVEL_HASH_H_
55