Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/base/functional.cc

Issue 632713002: Don't use identity as hash function for integers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/base/functional.h ('k') | test/unittests/base/functional-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « src/base/functional.h ('k') | test/unittests/base/functional-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698