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

Side by Side Diff: src/core/SkTDynamicHash.h

Issue 177263005: Counterproposal to 182733007: Add iterator to SkTDynamicHash (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: DEF_TEST Created 6 years, 9 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 | « no previous file | tests/DynamicHashTest.cpp » ('j') | tests/DynamicHashTest.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
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() { 27 ~SkTDynamicHash() {
28 sk_free(fArray); 28 sk_free(fArray);
29 } 29 }
30 30
31 class Iter {
32 public:
33 explicit Iter(SkTDynamicHash* hash) : fHash(hash), fCurrentIndex(-1) {
34 SkASSERT(hash);
35 ++(*this);
36 }
37 bool done() const {
38 SkASSERT(fCurrentIndex <= fHash->fCapacity);
39 return fCurrentIndex == fHash->fCapacity;
40 }
41 T& operator*() const {
42 SkASSERT(!this->done());
43 return *this->current();
44 }
45 void operator++() {
46 do {
47 fCurrentIndex++;
48 } while (!this->done() && (this->current() == Empty() || this->curre nt() == Deleted()));
49 }
50
51 private:
52 T* current() const { return fHash->fArray[fCurrentIndex]; }
53
54 SkTDynamicHash* fHash;
55 int fCurrentIndex;
56 };
57
31 int count() const { return fCount; } 58 int count() const { return fCount; }
32 59
33 // Return the entry with this key if we have it, otherwise NULL. 60 // Return the entry with this key if we have it, otherwise NULL.
34 T* find(const Key& key) const { 61 T* find(const Key& key) const {
35 int index = this->firstIndex(key); 62 int index = this->firstIndex(key);
36 for (int round = 0; round < fCapacity; round++) { 63 for (int round = 0; round < fCapacity; round++) {
37 T* candidate = fArray[index]; 64 T* candidate = fArray[index];
38 if (Empty() == candidate) { 65 if (Empty() == candidate) {
39 return NULL; 66 return NULL;
40 } 67 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 return (index + round + 1) & this->hashMask(); 229 return (index + round + 1) & this->hashMask();
203 } 230 }
204 231
205 int fCount; // Number of non Empty(), non Deleted() entries in fArray. 232 int fCount; // Number of non Empty(), non Deleted() entries in fArray.
206 int fDeleted; // Number of Deleted() entries in fArray. 233 int fDeleted; // Number of Deleted() entries in fArray.
207 int fCapacity; // Number of entries in fArray. Always a power of 2. 234 int fCapacity; // Number of entries in fArray. Always a power of 2.
208 T** fArray; 235 T** fArray;
209 }; 236 };
210 237
211 #endif 238 #endif
OLDNEW
« no previous file with comments | « no previous file | tests/DynamicHashTest.cpp » ('j') | tests/DynamicHashTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698