| OLD | NEW |
| 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 #ifndef SkTDynamicHash_DEFINED | 8 #ifndef SkTDynamicHash_DEFINED |
| 9 #define SkTDynamicHash_DEFINED | 9 #define SkTDynamicHash_DEFINED |
| 10 | 10 |
| 11 #include "SkMath.h" | 11 #include "SkMath.h" |
| 12 #include "SkTemplates.h" | 12 #include "SkTemplates.h" |
| 13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
| 14 | 14 |
| 15 template <typename T, | 15 template <typename T, |
| 16 typename Key, | 16 typename Key, |
| 17 const Key& (GetKey)(const T&), | 17 const Key& (GetKey)(const T&), |
| 18 uint32_t (Hash)(const Key&), | 18 uint32_t (Hash)(const Key&), |
| 19 bool (Equal)(const T&, const Key&), | 19 bool (Equal)(const T&, const Key&), |
| 20 int kGrowPercent = 75> // Larger -> more memory efficient, but slower
. | 20 int kGrowPercent = 75> // Larger -> more memory efficient, but slower
. |
| 21 class SkTDynamicHash { | 21 class SkTDynamicHash { |
| 22 public: | 22 public: |
| 23 SkTDynamicHash() : fCount(0), fDeleted(0), fCapacity(0), fArray(NULL) { | 23 SkTDynamicHash() : fCount(0), fDeleted(0), fCapacity(0), fArray(NULL) { |
| 24 SkASSERT(this->validate()); | 24 SkASSERT(this->validate()); |
| 25 } | 25 } |
| 26 | 26 |
| 27 SkTDynamicHash(const SkTDynamicHash& other) { |
| 28 fCount = other.fCount; |
| 29 fDeleted = other.fDeleted; |
| 30 fCapacity = other.fCapacity; |
| 31 fArray = (T**)sk_calloc_throw(sizeof(T*) * fCapacity); |
| 32 for (int i = 0; i < fCapacity; ++i) { |
| 33 fArray[i] = other.fArray[i]; |
| 34 } |
| 35 } |
| 36 |
| 27 ~SkTDynamicHash() { | 37 ~SkTDynamicHash() { |
| 28 sk_free(fArray); | 38 sk_free(fArray); |
| 29 } | 39 } |
| 30 | 40 |
| 31 class Iter { | 41 class Iter { |
| 32 public: | 42 public: |
| 33 explicit Iter(SkTDynamicHash* hash) : fHash(hash), fCurrentIndex(-1) { | 43 explicit Iter(SkTDynamicHash* hash) : fHash(hash), fCurrentIndex(-1) { |
| 34 SkASSERT(hash); | 44 SkASSERT(hash); |
| 35 ++(*this); | 45 ++(*this); |
| 36 } | 46 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 return (index + round + 1) & this->hashMask(); | 239 return (index + round + 1) & this->hashMask(); |
| 230 } | 240 } |
| 231 | 241 |
| 232 int fCount; // Number of non Empty(), non Deleted() entries in fArray. | 242 int fCount; // Number of non Empty(), non Deleted() entries in fArray. |
| 233 int fDeleted; // Number of Deleted() entries in fArray. | 243 int fDeleted; // Number of Deleted() entries in fArray. |
| 234 int fCapacity; // Number of entries in fArray. Always a power of 2. | 244 int fCapacity; // Number of entries in fArray. Always a power of 2. |
| 235 T** fArray; | 245 T** fArray; |
| 236 }; | 246 }; |
| 237 | 247 |
| 238 #endif | 248 #endif |
| OLD | NEW |