Chromium Code Reviews| Index: src/core/SkTDynamicHash.h |
| diff --git a/src/core/SkTDynamicHash.h b/src/core/SkTDynamicHash.h |
| index 445a45df8580c74bd096a7ec2e74f3bea135c5b9..f12e559c6b730456dbc590ef9388cbfab08a5319 100644 |
| --- a/src/core/SkTDynamicHash.h |
| +++ b/src/core/SkTDynamicHash.h |
| @@ -57,6 +57,33 @@ public: |
| int fCurrentIndex; |
| }; |
| + class ConstIter { |
| + public: |
| + explicit ConstIter(const SkTDynamicHash* hash) : fHash(hash), fCurrentIndex(-1) { |
| + SkASSERT(hash); |
| + ++(*this); |
| + } |
| + bool done() const { |
| + SkASSERT(fCurrentIndex <= fHash->fCapacity); |
| + return fCurrentIndex == fHash->fCapacity; |
| + } |
| + const T& operator*() const { |
| + SkASSERT(!this->done()); |
| + return *this->current(); |
| + } |
| + void operator++() { |
| + do { |
| + fCurrentIndex++; |
| + } while (!this->done() && (this->current() == Empty() || this->current() == Deleted())); |
| + } |
| + |
| + private: |
| + const T* current() const { return fHash->fArray[fCurrentIndex]; } |
| + |
| + const SkTDynamicHash* fHash; |
| + int fCurrentIndex; |
| + }; |
| + |
| int count() const { return fCount; } |
| // Return the entry with this key if we have it, otherwise NULL. |
| @@ -85,13 +112,39 @@ public: |
| SkASSERT(this->validate()); |
| } |
| - // Remove the entry with this key. We reqire that an entry with this key is present. |
| + // Remove the entry with this key. We require that an entry with this key is present. |
| void remove(const Key& key) { |
| SkASSERT(NULL != this->find(key)); |
| this->innerRemove(key); |
| SkASSERT(this->validate()); |
| } |
| + void rewind() { |
| + if (NULL != fArray) { |
| + sk_bzero(fArray, sizeof(T*)* fCapacity); |
| + } |
| + fCount = 0; |
| + fDeleted = 0; |
| + } |
| + |
| + void reset() { |
| + fCount = 0; |
| + fDeleted = 0; |
| + fCapacity = 0; |
| + sk_free(fArray); |
| + fArray = NULL; |
| + } |
| + |
| + // Note: functor is passed by value |
| + template<class Functor> |
|
mtklein
2014/07/17 19:36:20
I'd add a space between template and <
robertphillips
2014/07/17 20:02:46
Done.
|
| + void mutateAll(Functor f) { |
| + for (int i = 0; i < fCapacity; ++i) { |
| + if (Empty() != fArray[i] && Deleted() != fArray[i]) { |
| + f(*fArray[i]); |
| + } |
| + } |
| + } |
| + |
| protected: |
| // These methods are used by tests only. |