| OLD | NEW |
| 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" | |
| 14 #include "GrTypes.h" | 13 #include "GrTypes.h" |
| 15 | 14 |
| 16 /** | 15 /** |
| 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) { | |
| 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 /** | |
| 74 * GrBinHashKey is a hash key class that can take a data chunk of any predeterm
ined | 16 * GrBinHashKey is a hash key class that can take a data chunk of any predeterm
ined |
| 75 * length. The hash function used is the One-at-a-Time Hash | 17 * length. The hash function used is the One-at-a-Time Hash |
| 76 * (http://burtleburtle.net/bob/hash/doobs.html). | 18 * (http://burtleburtle.net/bob/hash/doobs.html). |
| 77 */ | 19 */ |
| 78 template<size_t KEY_SIZE> | 20 template<size_t KEY_SIZE> |
| 79 class GrBinHashKey { | 21 class GrBinHashKey { |
| 80 public: | 22 public: |
| 81 enum { kKeySize = KEY_SIZE }; | 23 enum { kKeySize = KEY_SIZE }; |
| 82 | 24 |
| 83 GrBinHashKey() { | 25 GrBinHashKey() { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 uint32_t fHash; | 93 uint32_t fHash; |
| 152 uint32_t fData[KEY_SIZE / sizeof(uint32_t)]; // Buffer for key s
torage. | 94 uint32_t fData[KEY_SIZE / sizeof(uint32_t)]; // Buffer for key s
torage. |
| 153 | 95 |
| 154 #ifdef SK_DEBUG | 96 #ifdef SK_DEBUG |
| 155 public: | 97 public: |
| 156 bool fIsValid; | 98 bool fIsValid; |
| 157 #endif | 99 #endif |
| 158 }; | 100 }; |
| 159 | 101 |
| 160 #endif | 102 #endif |
| OLD | NEW |