Flutter Engine
JenkinsHash.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 /* Implementation of Jenkins one-at-a-time hash function. These choices are
18  * optimized for code size and portability, rather than raw speed. But speed
19  * should still be quite good.
20  **/
21 
22 #ifndef ANDROID_JENKINS_HASH_H
23 #define ANDROID_JENKINS_HASH_H
24 
25 #include <utils/TypeHelpers.h>
26 
27 namespace android {
28 
29 /* The Jenkins hash of a sequence of 32 bit words A, B, C is:
30  * Whiten(Mix(Mix(Mix(0, A), B), C)) */
31 
32 #ifdef __clang__
33 __attribute__((no_sanitize("integer")))
34 #endif
35 inline uint32_t
36 JenkinsHashMix(uint32_t hash, uint32_t data) {
37  hash += data;
38  hash += (hash << 10);
39  hash ^= (hash >> 6);
40  return hash;
41 }
42 
43 hash_t JenkinsHashWhiten(uint32_t hash);
44 
45 /* Helpful utility functions for hashing data in 32 bit chunks */
46 uint32_t JenkinsHashMixBytes(uint32_t hash, const uint8_t* bytes, size_t size);
47 
48 uint32_t JenkinsHashMixShorts(uint32_t hash,
49  const uint16_t* shorts,
50  size_t size);
51 
52 } // namespace android
53 
54 #endif // ANDROID_JENKINS_HASH_H
uint32_t JenkinsHashMixShorts(uint32_t hash, const uint16_t *shorts, size_t size)
uint32_t hash_t
Definition: TypeHelpers.h:325
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
hash_t JenkinsHashWhiten(uint32_t hash)
enum flutter::DartErrorCode __attribute__
uint32_t JenkinsHashMix(uint32_t hash, uint32_t data)
Definition: JenkinsHash.h:36
uint32_t JenkinsHashMixBytes(uint32_t hash, const uint8_t *bytes, size_t size)