Chromium Code Reviews| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 } | 128 } |
| 129 | 129 |
| 130 void reset() { | 130 void reset() { |
| 131 fCount = 0; | 131 fCount = 0; |
| 132 fDeleted = 0; | 132 fDeleted = 0; |
| 133 fCapacity = 0; | 133 fCapacity = 0; |
| 134 sk_free(fArray); | 134 sk_free(fArray); |
| 135 fArray = NULL; | 135 fArray = NULL; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void deleteAll() { | |
|
mtklein
2014/07/22 13:54:30
I think you can do both of these just as easily fr
jvanverth1
2014/07/22 14:14:07
Yup, just had that discussion here. Done.
| |
| 139 int index = 0; | |
| 140 while (index < fCapacity) { | |
| 141 if (fArray[index] != Empty() && fArray[index] != Deleted()) { | |
| 142 SkDELETE(fArray[index]); | |
| 143 } | |
| 144 ++index; | |
| 145 } | |
| 146 this->reset(); | |
| 147 } | |
| 148 | |
| 149 void freeAll() { | |
| 150 int index = 0; | |
| 151 while (index < fCapacity) { | |
| 152 if (fArray[index] != Empty() && fArray[index] != Deleted()) { | |
| 153 sk_free(fArray[index]); | |
| 154 } | |
| 155 ++index; | |
| 156 } | |
| 157 this->reset(); | |
| 158 } | |
| 159 | |
| 138 protected: | 160 protected: |
| 139 // These methods are used by tests only. | 161 // These methods are used by tests only. |
| 140 | 162 |
| 141 int capacity() const { return fCapacity; } | 163 int capacity() const { return fCapacity; } |
| 142 | 164 |
| 143 // How many collisions do we go through before finding where this entry shou ld be inserted? | 165 // How many collisions do we go through before finding where this entry shou ld be inserted? |
| 144 int countCollisions(const Key& key) const { | 166 int countCollisions(const Key& key) const { |
| 145 int index = this->firstIndex(key); | 167 int index = this->firstIndex(key); |
| 146 for (int round = 0; round < fCapacity; round++) { | 168 for (int round = 0; round < fCapacity; round++) { |
| 147 SkASSERT(index >= 0 && index < fCapacity); | 169 SkASSERT(index >= 0 && index < fCapacity); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 static const Key& GetKey(const T& t) { return Traits::GetKey(t); } | 302 static const Key& GetKey(const T& t) { return Traits::GetKey(t); } |
| 281 static uint32_t Hash(const Key& key) { return Traits::Hash(key); } | 303 static uint32_t Hash(const Key& key) { return Traits::Hash(key); } |
| 282 | 304 |
| 283 int fCount; // Number of non Empty(), non Deleted() entries in fArray. | 305 int fCount; // Number of non Empty(), non Deleted() entries in fArray. |
| 284 int fDeleted; // Number of Deleted() entries in fArray. | 306 int fDeleted; // Number of Deleted() entries in fArray. |
| 285 int fCapacity; // Number of entries in fArray. Always a power of 2. | 307 int fCapacity; // Number of entries in fArray. Always a power of 2. |
| 286 T** fArray; | 308 T** fArray; |
| 287 }; | 309 }; |
| 288 | 310 |
| 289 #endif | 311 #endif |
| OLD | NEW |