OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkChecksum_DEFINED | 8 #ifndef SkChecksum_DEFINED |
9 #define SkChecksum_DEFINED | 9 #define SkChecksum_DEFINED |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 static uint32_t Mix(uint32_t hash) { | 45 static uint32_t Mix(uint32_t hash) { |
46 hash ^= hash >> 16; | 46 hash ^= hash >> 16; |
47 hash *= 0x85ebca6b; | 47 hash *= 0x85ebca6b; |
48 hash ^= hash >> 13; | 48 hash ^= hash >> 13; |
49 hash *= 0xc2b2ae35; | 49 hash *= 0xc2b2ae35; |
50 hash ^= hash >> 16; | 50 hash ^= hash >> 16; |
51 return hash; | 51 return hash; |
52 } | 52 } |
53 | 53 |
54 /** | 54 /** |
| 55 * uint32_t -> uint32_t hash, useful for when you're about to trucate this h
ash but you |
| 56 * suspect its low bits aren't well mixed. |
| 57 * |
| 58 * This version is 2-lines cheaper than Mix, but seems to be sufficient for
the font cache. |
| 59 */ |
| 60 static uint32_t CheapMix(uint32_t hash) { |
| 61 hash ^= hash >> 16; |
| 62 hash *= 0x85ebca6b; |
| 63 hash ^= hash >> 16; |
| 64 return hash; |
| 65 } |
| 66 |
| 67 /** |
55 * Calculate 32-bit Murmur hash (murmur3). | 68 * Calculate 32-bit Murmur hash (murmur3). |
56 * This should take 2-3x longer than SkChecksum::Compute, but is a considera
bly better hash. | 69 * This should take 2-3x longer than SkChecksum::Compute, but is a considera
bly better hash. |
57 * See en.wikipedia.org/wiki/MurmurHash. | 70 * See en.wikipedia.org/wiki/MurmurHash. |
58 * | 71 * |
59 * @param data Memory address of the data block to be processed. Must be 32
-bit aligned. | 72 * @param data Memory address of the data block to be processed. Must be 32
-bit aligned. |
60 * @param size Size of the data block in bytes. Must be a multiple of 4. | 73 * @param size Size of the data block in bytes. Must be a multiple of 4. |
61 * @param seed Initial hash seed. (optional) | 74 * @param seed Initial hash seed. (optional) |
62 * @return hash result | 75 * @return hash result |
63 */ | 76 */ |
64 static uint32_t Murmur3(const uint32_t* data, size_t bytes, uint32_t seed=0)
{ | 77 static uint32_t Murmur3(const uint32_t* data, size_t bytes, uint32_t seed=0)
{ |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 * define. | 159 * define. |
147 */ | 160 */ |
148 if (8 == sizeof(result)) { | 161 if (8 == sizeof(result)) { |
149 result ^= result >> HALFBITS; | 162 result ^= result >> HALFBITS; |
150 } | 163 } |
151 return static_cast<uint32_t>(result); | 164 return static_cast<uint32_t>(result); |
152 } | 165 } |
153 }; | 166 }; |
154 | 167 |
155 #endif | 168 #endif |
OLD | NEW |