• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
JenkinsHashMix(uint32_t hash,uint32_t data)35  inline uint32_t JenkinsHashMix(uint32_t hash, uint32_t data) {
36      hash += data;
37      hash += (hash << 10);
38      hash ^= (hash >> 6);
39      return hash;
40  }
41  
42  hash_t JenkinsHashWhiten(uint32_t hash);
43  
44  /* Helpful utility functions for hashing data in 32 bit chunks */
45  uint32_t JenkinsHashMixBytes(uint32_t hash, const uint8_t* bytes, size_t size);
46  
47  uint32_t JenkinsHashMixShorts(uint32_t hash, const uint16_t* shorts, size_t size);
48  
49  }
50  
51  #endif // ANDROID_JENKINS_HASH_H
52