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

Side by Side Diff: src/gpu/GrBinHashKey.h

Issue 402693003: Replace GrTHash with SkTDynamicHash (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix compiler complaints Created 6 years, 5 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/core/SkTDynamicHash.h ('k') | src/gpu/GrLayerCache.h » ('j') | 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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef GrBinHashKey_DEFINED 10 #ifndef GrBinHashKey_DEFINED
11 #define GrBinHashKey_DEFINED 11 #define GrBinHashKey_DEFINED
12 12
13 #include "SkChecksum.h"
13 #include "GrTypes.h" 14 #include "GrTypes.h"
14 15
15 /** 16 /**
17 * GrMurmur3HashKey is a hash key class that can take a data chunk of any prede termined
18 * length. It uses the Murmur3 hash function. It is intended to be used with
19 * SkTDynamicHash (where GrBinHashKey is for GrTHashTable).
20 */
21 template<size_t KEY_SIZE_IN_BYTES>
22 class GrMurmur3HashKey {
23 public:
24 GrMurmur3HashKey() {
25 this->reset();
26 }
27
28 void reset() {
29 fHash = 0;
30 #ifdef SK_DEBUG
31 fIsValid = false;
32 #endif
33 }
34
35 void setKeyData(const uint32_t* data) {
36 SK_COMPILE_ASSERT(KEY_SIZE_IN_BYTES % 4 == 0, key_size_mismatch);
37 memcpy(fData, data, KEY_SIZE_IN_BYTES);
38
39 fHash = SkChecksum::Murmur3(fData, KEY_SIZE_IN_BYTES);
40 #ifdef SK_DEBUG
41 fIsValid = true;
42 #endif
43 }
44
45 bool operator==(const GrMurmur3HashKey& other) const {
46 if (fHash != other.fHash) {
mtklein 2014/07/19 14:38:57 I've always had half a mind to cache the hash insi
robertphillips 2014/07/20 16:12:30 I think it is worth a try.
47 return false;
48 }
49
50 return !memcmp(fData, other.fData, KEY_SIZE_IN_BYTES);
51 }
52
53 uint32_t getHash() const {
54 SkASSERT(fIsValid);
55 return fHash;
56 }
57
58 const uint8_t* getData() const {
59 SkASSERT(fIsValid);
60 return reinterpret_cast<const uint8_t*>(fData);
61 }
62
63 private:
64 uint32_t fHash;
65 uint32_t fData[KEY_SIZE_IN_BYTES / sizeof(uint32_t)]; // Buffer for key sto rage.
66
67 #ifdef SK_DEBUG
68 public:
69 bool fIsValid;
70 #endif
71 };
72
73 /**
16 * GrBinHashKey is a hash key class that can take a data chunk of any predeterm ined 74 * GrBinHashKey is a hash key class that can take a data chunk of any predeterm ined
17 * length. The hash function used is the One-at-a-Time Hash 75 * length. The hash function used is the One-at-a-Time Hash
18 * (http://burtleburtle.net/bob/hash/doobs.html). 76 * (http://burtleburtle.net/bob/hash/doobs.html).
19 */ 77 */
20 template<size_t KEY_SIZE> 78 template<size_t KEY_SIZE>
21 class GrBinHashKey { 79 class GrBinHashKey {
22 public: 80 public:
23 enum { kKeySize = KEY_SIZE }; 81 enum { kKeySize = KEY_SIZE };
24 82
25 GrBinHashKey() { 83 GrBinHashKey() {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 uint32_t fHash; 151 uint32_t fHash;
94 uint32_t fData[KEY_SIZE / sizeof(uint32_t)]; // Buffer for key s torage. 152 uint32_t fData[KEY_SIZE / sizeof(uint32_t)]; // Buffer for key s torage.
95 153
96 #ifdef SK_DEBUG 154 #ifdef SK_DEBUG
97 public: 155 public:
98 bool fIsValid; 156 bool fIsValid;
99 #endif 157 #endif
100 }; 158 };
101 159
102 #endif 160 #endif
OLDNEW
« no previous file with comments | « src/core/SkTDynamicHash.h ('k') | src/gpu/GrLayerCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698