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

Unified Diff: src/core/SkTDynamicHash.h

Issue 402693003: Replace GrTHash with SkTDynamicHash (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix initializer order Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/gpu/GrLayerCache.h » ('j') | src/gpu/GrLayerCache.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « no previous file | src/gpu/GrLayerCache.h » ('j') | src/gpu/GrLayerCache.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698