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

Side by Side Diff: tests/DynamicHashTest.cpp

Issue 222473002: SkTDynamicHash: pick up GetKey(), Hash() from T by default. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 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
« no previous file with comments | « src/gpu/GrTMultiMap.h ('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 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 #include "SkTDynamicHash.h" 8 #include "SkTDynamicHash.h"
9 #include "Test.h" 9 #include "Test.h"
10 10
11 namespace { 11 namespace {
12 12
13 struct Entry { 13 struct Entry {
14 int key; 14 int key;
15 double value; 15 double value;
16
17 static const int& GetKey(const Entry& entry) { return entry.key; }
18 static uint32_t Hash(const int& key) { return key; }
16 }; 19 };
17 20
18 const int& GetKey(const Entry& entry) { return entry.key; }
19 uint32_t GetHash(const int& key) { return key; }
20 21
21 class Hash : public SkTDynamicHash<Entry, int, GetKey, GetHash> { 22 class Hash : public SkTDynamicHash<Entry, int> {
22 public: 23 public:
23 Hash() : INHERITED() {} 24 Hash() : INHERITED() {}
24 25
25 // Promote protected methods to public for this test. 26 // Promote protected methods to public for this test.
26 int capacity() const { return this->INHERITED::capacity(); } 27 int capacity() const { return this->INHERITED::capacity(); }
27 int countCollisions(const int& key) const { return this->INHERITED::countCol lisions(key); } 28 int countCollisions(const int& key) const { return this->INHERITED::countCol lisions(key); }
28 29
29 private: 30 private:
30 typedef SkTDynamicHash<Entry, int, GetKey, GetHash> INHERITED; 31 typedef SkTDynamicHash<Entry, int> INHERITED;
31 }; 32 };
32 33
33 } // namespace 34 } // namespace
34 35
35 #define ASSERT(x) REPORTER_ASSERT(reporter, x) 36 #define ASSERT(x) REPORTER_ASSERT(reporter, x)
36 37
37 DEF_TEST(DynamicHash_growth, reporter) { 38 DEF_TEST(DynamicHash_growth, reporter) {
38 Entry a = { 1, 2.0 }; 39 Entry a = { 1, 2.0 };
39 Entry b = { 2, 3.0 }; 40 Entry b = { 2, 3.0 };
40 Entry c = { 3, 4.0 }; 41 Entry c = { 3, 4.0 };
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 for (Hash::Iter iter(&hash); !iter.done(); ++iter) { 176 for (Hash::Iter iter(&hash); !iter.done(); ++iter) {
176 int key = (*iter).key; 177 int key = (*iter).key;
177 keys[count] = key; 178 keys[count] = key;
178 ASSERT(key != 1); 179 ASSERT(key != 1);
179 ASSERT(hash.find(key) != NULL); 180 ASSERT(hash.find(key) != NULL);
180 ++count; 181 ++count;
181 } 182 }
182 ASSERT(2 == count); 183 ASSERT(2 == count);
183 ASSERT(keys[0] != keys[1]); 184 ASSERT(keys[0] != keys[1]);
184 } 185 }
OLDNEW
« no previous file with comments | « src/gpu/GrTMultiMap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698