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

Side by Side Diff: test/unittests/base/functional-unittest.cc

Issue 635733002: Further improve hashing of pointers and integers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Also fix HashIsOkish test. 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.cc ('k') | no next file » | 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 #include "src/base/functional.h" 5 #include "src/base/functional.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <set> 8 #include <set>
9 9
10 #include "test/unittests/test-utils.h" 10 #include "test/unittests/test-utils.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 hash<TypeParam> h1, h2; 75 hash<TypeParam> h1, h2;
76 for (int i = 0; i < 128; ++i) { 76 for (int i = 0; i < 128; ++i) {
77 TypeParam v; 77 TypeParam v;
78 this->rng()->NextBytes(&v, sizeof(v)); 78 this->rng()->NextBytes(&v, sizeof(v));
79 EXPECT_EQ(h1(v), h2(v)); 79 EXPECT_EQ(h1(v), h2(v));
80 } 80 }
81 } 81 }
82 82
83 83
84 TYPED_TEST(FunctionalTest, HashIsOkish) { 84 TYPED_TEST(FunctionalTest, HashIsOkish) {
85 const size_t kValues = 128;
86 const size_t kMinHashes = kValues / 4;
87 std::set<TypeParam> vs; 85 std::set<TypeParam> vs;
88 while (vs.size() != kValues) { 86 for (size_t i = 0; i < 128; ++i) {
89 TypeParam v; 87 TypeParam v;
90 this->rng()->NextBytes(&v, sizeof(v)); 88 this->rng()->NextBytes(&v, sizeof(v));
91 vs.insert(v); 89 vs.insert(v);
92 } 90 }
93 std::set<size_t> hs; 91 std::set<size_t> hs;
94 for (const auto& v : vs) { 92 for (const auto& v : vs) {
95 hash<TypeParam> h; 93 hash<TypeParam> h;
96 hs.insert(h(v)); 94 hs.insert(h(v));
97 } 95 }
98 EXPECT_LE(kMinHashes, hs.size()); 96 EXPECT_LE(vs.size() / 4u, hs.size());
99 } 97 }
100 98
101 99
102 namespace { 100 namespace {
103 101
104 struct Foo { 102 struct Foo {
105 int x; 103 int x;
106 double y; 104 double y;
107 }; 105 };
108 106
(...skipping 13 matching lines...) Expand all
122 TRACED_FOREACH(double, y, kDoubleValues) { 120 TRACED_FOREACH(double, y, kDoubleValues) {
123 hash<Foo> h; 121 hash<Foo> h;
124 Foo foo = {x, y}; 122 Foo foo = {x, y};
125 EXPECT_EQ(hash_combine(x, y), h(foo)); 123 EXPECT_EQ(hash_combine(x, y), h(foo));
126 } 124 }
127 } 125 }
128 } 126 }
129 127
130 } // namespace base 128 } // namespace base
131 } // namespace v8 129 } // namespace v8
OLDNEW
« no previous file with comments | « src/base/functional.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698