| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // This also contains public domain code from MurmurHash. From the | 5 // This also contains public domain code from MurmurHash. From the |
| 6 // MurmurHash header: | 6 // MurmurHash header: |
| 7 // | 7 // |
| 8 // MurmurHash3 was written by Austin Appleby, and is placed in the public | 8 // MurmurHash3 was written by Austin Appleby, and is placed in the public |
| 9 // domain. The author hereby disclaims copyright to this source code. | 9 // domain. The author hereby disclaims copyright to this source code. |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 value ^= value >> r; | 57 value ^= value >> r; |
| 58 value *= m; | 58 value *= m; |
| 59 | 59 |
| 60 seed ^= value; | 60 seed ^= value; |
| 61 seed *= m; | 61 seed *= m; |
| 62 #endif // V8_HOST_ARCH_32_BIT | 62 #endif // V8_HOST_ARCH_32_BIT |
| 63 return seed; | 63 return seed; |
| 64 } | 64 } |
| 65 | 65 |
| 66 | 66 |
| 67 // Thomas Wang, Integer Hash Functions. |
| 68 // http://www.concentric.net/~Ttwang/tech/inthash.htm |
| 69 size_t hash_value(unsigned int v) { |
| 70 v = ~v + (v << 15); // v = (v << 15) - v - 1; |
| 71 v = v ^ (v >> 12); |
| 72 v = v + (v << 2); |
| 73 v = v ^ (v >> 4); |
| 74 v = v * 2057; // v = (v + (v << 3)) + (v << 11); |
| 75 v = v ^ (v >> 16); |
| 76 return v; |
| 77 } |
| 78 |
| 79 |
| 67 size_t hash_value(unsigned long v) { // NOLINT(runtime/int) | 80 size_t hash_value(unsigned long v) { // NOLINT(runtime/int) |
| 68 return hash_value_unsigned(v); | 81 return hash_value_unsigned(v); |
| 69 } | 82 } |
| 70 | 83 |
| 71 | 84 |
| 72 size_t hash_value(unsigned long long v) { // NOLINT(runtime/int) | 85 size_t hash_value(unsigned long long v) { // NOLINT(runtime/int) |
| 73 return hash_value_unsigned(v); | 86 return hash_value_unsigned(v); |
| 74 } | 87 } |
| 75 | 88 |
| 76 | 89 |
| 77 size_t hash_value(float v) { | 90 size_t hash_value(float v) { |
| 78 // 0 and -0 both hash to zero. | 91 // 0 and -0 both hash to zero. |
| 79 return v != 0.0f ? hash_value(bit_cast<uint32_t>(v)) : 0; | 92 return v != 0.0f ? hash_value_unsigned(bit_cast<uint32_t>(v)) : 0; |
| 80 } | 93 } |
| 81 | 94 |
| 82 | 95 |
| 83 size_t hash_value(double v) { | 96 size_t hash_value(double v) { |
| 84 // 0 and -0 both hash to zero. | 97 // 0 and -0 both hash to zero. |
| 85 return v != 0.0 ? hash_value(bit_cast<uint64_t>(v)) : 0; | 98 return v != 0.0 ? hash_value_unsigned(bit_cast<uint64_t>(v)) : 0; |
| 86 } | 99 } |
| 87 | 100 |
| 88 } // namespace base | 101 } // namespace base |
| 89 } // namespace v8 | 102 } // namespace v8 |
| OLD | NEW |