aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkTMultiMap.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SkTMultiMap.h')
-rw-r--r--src/core/SkTMultiMap.h51
1 files changed, 37 insertions, 14 deletions
diff --git a/src/core/SkTMultiMap.h b/src/core/SkTMultiMap.h
index 3d6e38e454..987a306661 100644
--- a/src/core/SkTMultiMap.h
+++ b/src/core/SkTMultiMap.h
@@ -34,6 +34,7 @@ public:
for ( ; !iter.done(); ++iter) {
ValueList* next;
for (ValueList* cur = &(*iter); cur; cur = next) {
+ HashTraits::OnFree(cur->fValue);
next = cur->fNext;
delete cur;
}
@@ -69,20 +70,7 @@ public:
list = list->fNext;
}
- if (list->fNext) {
- ValueList* next = list->fNext;
- list->fValue = next->fValue;
- list->fNext = next->fNext;
- delete next;
- } else if (prev) {
- prev->fNext = nullptr;
- delete list;
- } else {
- fHash.remove(key);
- delete list;
- }
-
- --fCount;
+ this->internalRemove(prev, list, key);
}
T* find(const Key& key) const {
@@ -105,6 +93,23 @@ public:
return nullptr;
}
+ template<class FindPredicate>
+ T* findAndRemove(const Key& key, const FindPredicate f) {
+ ValueList* list = fHash.find(key);
+
+ ValueList* prev = nullptr;
+ while (list) {
+ if (f(list->fValue)){
+ T* value = list->fValue;
+ this->internalRemove(prev, list, key);
+ return value;
+ }
+ prev = list;
+ list = list->fNext;
+ }
+ return nullptr;
+ }
+
int count() const { return fCount; }
#ifdef SK_DEBUG
@@ -168,6 +173,24 @@ public:
private:
SkTDynamicHash<ValueList, Key> fHash;
int fCount;
+
+ void internalRemove(ValueList* prev, ValueList* elem, const Key& key) {
+ if (elem->fNext) {
+ ValueList* next = elem->fNext;
+ elem->fValue = next->fValue;
+ elem->fNext = next->fNext;
+ delete next;
+ } else if (prev) {
+ prev->fNext = nullptr;
+ delete elem;
+ } else {
+ fHash.remove(key);
+ delete elem;
+ }
+
+ --fCount;
+ }
+
};
#endif