| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/utils.h" | 5 #include "platform/utils.h" |
| 6 | 6 |
| 7 namespace dart { | 7 namespace dart { |
| 8 | 8 |
| 9 // Implementation is from "Hacker's Delight" by Henry S. Warren, Jr., | 9 // Implementation is from "Hacker's Delight" by Henry S. Warren, Jr., |
| 10 // figure 3-3, page 48, where the function is called clp2. | 10 // figure 3-3, page 48, where the function is called clp2. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 // Do a few final mixes of the hash to ensure the last few bytes are | 69 // Do a few final mixes of the hash to ensure the last few bytes are |
| 70 // well-incorporated. | 70 // well-incorporated. |
| 71 hash ^= hash >> 13; | 71 hash ^= hash >> 13; |
| 72 hash *= M; | 72 hash *= M; |
| 73 hash ^= hash >> 15; | 73 hash ^= hash >> 15; |
| 74 return hash; | 74 return hash; |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 uint32_t WordHash(word key) { | 78 uint32_t Utils::WordHash(word key) { |
| 79 // TODO(iposva): Need to check hash spreading. | 79 // TODO(iposva): Need to check hash spreading. |
| 80 // This example is from http://www.concentric.net/~Ttwang/tech/inthash.htm | 80 // This example is from http://www.concentric.net/~Ttwang/tech/inthash.htm |
| 81 uword a = static_cast<uword>(key); | 81 uword a = static_cast<uword>(key); |
| 82 a = (a + 0x7ed55d16) + (a << 12); | 82 a = (a + 0x7ed55d16) + (a << 12); |
| 83 a = (a ^ 0xc761c23c) ^ (a >> 19); | 83 a = (a ^ 0xc761c23c) ^ (a >> 19); |
| 84 a = (a + 0x165667b1) + (a << 5); | 84 a = (a + 0x165667b1) + (a << 5); |
| 85 a = (a + 0xd3a2646c) ^ (a << 9); | 85 a = (a + 0xd3a2646c) ^ (a << 9); |
| 86 a = (a + 0xfd7046c5) + (a << 3); | 86 a = (a + 0xfd7046c5) + (a << 3); |
| 87 a = (a ^ 0xb55a4f09) ^ (a >> 16); | 87 a = (a ^ 0xb55a4f09) ^ (a >> 16); |
| 88 return static_cast<uint32_t>(a); | 88 return static_cast<uint32_t>(a); |
| 89 } | 89 } |
| 90 | 90 |
| 91 } // namespace dart | 91 } // namespace dart |
| OLD | NEW |