blob: e964e6f926cc6311a1c6d386324a58c0f91ea0f3 [file] [log] [blame]
Raph Levienb6ea1752012-10-25 23:11:13 -07001/*
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#include <utils/TypeHelpers.h>
23
24namespace android {
25
26/* The Jenkins hash of a sequence of 32 bit words A, B, C is:
27 * Whiten(Mix(Mix(Mix(0, A), B), C)) */
28
29inline uint32_t JenkinsHashMix(uint32_t hash, uint32_t data) {
30 hash += data;
31 hash += (hash << 10);
32 hash ^= (hash >> 6);
33 return hash;
34}
35
36hash_t JenkinsHashWhiten(uint32_t hash);
37
38/* Helpful utility functions for hashing data in 32 bit chunks */
39uint32_t JenkinsHashMixBytes(uint32_t hash, const uint8_t* bytes, size_t size);
40
41uint32_t JenkinsHashMixShorts(uint32_t hash, const uint16_t* shorts, size_t size);
42
43}
44