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

Unified Diff: src/gpu/GrTMultiMap.h

Issue 401343002: Move GrTMultiMap to src/core and rename it (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « src/gpu/GrResourceCache.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrTMultiMap.h
diff --git a/src/gpu/GrTMultiMap.h b/src/gpu/GrTMultiMap.h
deleted file mode 100644
index 0007a04a2adb6c6dd535bbdf3dd2d5f5ac21663e..0000000000000000000000000000000000000000
--- a/src/gpu/GrTMultiMap.h
+++ /dev/null
@@ -1,110 +0,0 @@
-
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrTMultiMap_DEFINED
-#define GrTMultiMap_DEFINED
-
-#include "GrTypes.h"
-#include "SkTDynamicHash.h"
-
-/** A set that contains pointers to instances of T. Instances can be looked up with key Key.
- * Multiple (possibly same) values can have the same key.
- */
-template <typename T,
- typename Key,
- typename HashTraits=T>
-class GrTMultiMap {
- struct ValueList {
- explicit ValueList(T* value) : fValue(value), fNext(NULL) {}
-
- static const Key& GetKey(const ValueList& e) { return HashTraits::GetKey(*e.fValue); }
- static uint32_t Hash(const Key& key) { return HashTraits::Hash(key); }
- T* fValue;
- ValueList* fNext;
- };
-public:
- GrTMultiMap() : fCount(0) {}
-
- ~GrTMultiMap() {
- SkASSERT(fCount == 0);
- SkASSERT(fHash.count() == 0);
- }
-
- void insert(const Key& key, T* value) {
- ValueList* list = fHash.find(key);
- if (NULL != list) {
- // The new ValueList entry is inserted as the second element in the
- // linked list, and it will contain the value of the first element.
- ValueList* newEntry = SkNEW_ARGS(ValueList, (list->fValue));
- newEntry->fNext = list->fNext;
- // The existing first ValueList entry is updated to contain the
- // inserted value.
- list->fNext = newEntry;
- list->fValue = value;
- } else {
- fHash.add(SkNEW_ARGS(ValueList, (value)));
- }
-
- ++fCount;
- }
-
- void remove(const Key& key, const T* value) {
- ValueList* list = fHash.find(key);
- // Since we expect the caller to be fully aware of what is stored, just
- // assert that the caller removes an existing value.
- SkASSERT(NULL != list);
- ValueList* prev = NULL;
- while (list->fValue != value) {
- prev = list;
- list = list->fNext;
- }
-
- if (NULL != list->fNext) {
- ValueList* next = list->fNext;
- list->fValue = next->fValue;
- list->fNext = next->fNext;
- SkDELETE(next);
- } else if (NULL != prev) {
- prev->fNext = NULL;
- SkDELETE(list);
- } else {
- fHash.remove(key);
- SkDELETE(list);
- }
-
- --fCount;
- }
-
- T* find(const Key& key) const {
- ValueList* list = fHash.find(key);
- if (NULL != list) {
- return list->fValue;
- }
- return NULL;
- }
-
- template<class FindPredicate>
- T* find(const Key& key, const FindPredicate f) {
- ValueList* list = fHash.find(key);
- while (NULL != list) {
- if (f(list->fValue)){
- return list->fValue;
- }
- list = list->fNext;
- }
- return NULL;
- }
-
- int count() const { return fCount; }
-
-private:
- SkTDynamicHash<ValueList, Key> fHash;
- int fCount;
-};
-
-#endif
« no previous file with comments | « src/gpu/GrResourceCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698