| 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 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 SkASSERT(0); // countCollisions: should be unreachable | 85 SkASSERT(0); // countCollisions: should be unreachable |
| 86 return -1; | 86 return -1; |
| 87 } | 87 } |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 // We have two special values to indicate an empty or deleted entry. | 90 // We have two special values to indicate an empty or deleted entry. |
| 91 static T* Empty() { return reinterpret_cast<T*>(0); } // i.e. NULL | 91 static T* Empty() { return reinterpret_cast<T*>(0); } // i.e. NULL |
| 92 static T* Deleted() { return reinterpret_cast<T*>(1); } // Also an invalid
pointer. | 92 static T* Deleted() { return reinterpret_cast<T*>(1); } // Also an invalid
pointer. |
| 93 | 93 |
| 94 static T** AllocArray(int capacity) { | 94 static T** AllocArray(int capacity) { |
| 95 T** array = (T**)sk_malloc_throw(sizeof(T*) * capacity); | 95 return (T**)sk_calloc_throw(sizeof(T*) * capacity); // All cells == Emp
ty(). |
| 96 sk_bzero(array, sizeof(T*) * capacity); // All cells == Empty(). | |
| 97 return array; | |
| 98 } | 96 } |
| 99 | 97 |
| 100 void reset(int capacity) { | 98 void reset(int capacity) { |
| 101 fCount = 0; | 99 fCount = 0; |
| 102 fDeleted = 0; | 100 fDeleted = 0; |
| 103 fCapacity = capacity; | 101 fCapacity = capacity; |
| 104 fArray = AllocArray(fCapacity); | 102 fArray = AllocArray(fCapacity); |
| 105 } | 103 } |
| 106 | 104 |
| 107 bool validate() const { | 105 bool validate() const { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 return (index + round + 1) & this->hashMask(); | 230 return (index + round + 1) & this->hashMask(); |
| 233 } | 231 } |
| 234 | 232 |
| 235 int fCount; // Number of non Empty(), non Deleted() entries in fArray. | 233 int fCount; // Number of non Empty(), non Deleted() entries in fArray. |
| 236 int fDeleted; // Number of Deleted() entries in fArray. | 234 int fDeleted; // Number of Deleted() entries in fArray. |
| 237 int fCapacity; // Number of entries in fArray. Always a power of 2. | 235 int fCapacity; // Number of entries in fArray. Always a power of 2. |
| 238 T** fArray; | 236 T** fArray; |
| 239 }; | 237 }; |
| 240 | 238 |
| 241 #endif | 239 #endif |
| OLD | NEW |