diff options
author | 2014-03-05 01:00:50 +0000 | |
---|---|---|
committer | 2014-03-05 01:00:50 +0000 | |
commit | 1f6cf695b30d2a7a4e7f046f04868a6e430b05b0 (patch) | |
tree | 03b1dd25e63c67efc53e47b87c13d0f23b9202cc /src/core | |
parent | e492ac4fb638678408e421c2b74dea106286bbbd (diff) |
Counterproposal to 182733007: Add iterator to SkTDynamicHash
BUG=skia:
R=egdaniel@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/177263005
git-svn-id: http://skia.googlecode.com/svn/trunk@13663 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkTDynamicHash.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/core/SkTDynamicHash.h b/src/core/SkTDynamicHash.h index 8f66c86d90..80570ae0ac 100644 --- a/src/core/SkTDynamicHash.h +++ b/src/core/SkTDynamicHash.h @@ -28,6 +28,33 @@ public: sk_free(fArray); } + class Iter { + public: + explicit Iter(SkTDynamicHash* hash) : fHash(hash), fCurrentIndex(-1) { + SkASSERT(hash); + ++(*this); + } + bool done() const { + SkASSERT(fCurrentIndex <= fHash->fCapacity); + return fCurrentIndex == fHash->fCapacity; + } + T& operator*() const { + SkASSERT(!this->done()); + return *this->current(); + } + void operator++() { + do { + fCurrentIndex++; + } while (!this->done() && (this->current() == Empty() || this->current() == Deleted())); + } + + private: + T* current() const { return fHash->fArray[fCurrentIndex]; } + + SkTDynamicHash* fHash; + int fCurrentIndex; + }; + int count() const { return fCount; } // Return the entry with this key if we have it, otherwise NULL. |