| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #ifndef GrTMultiMap_DEFINED | 9 #ifndef GrTMultiMap_DEFINED |
| 10 #define GrTMultiMap_DEFINED | 10 #define GrTMultiMap_DEFINED |
| 11 | 11 |
| 12 #include "GrTypes.h" | 12 #include "GrTypes.h" |
| 13 #include "SkTDynamicHash.h" | 13 #include "SkTDynamicHash.h" |
| 14 | 14 |
| 15 /** A set that contains pointers to instances of T. Instances can be looked up w
ith key Key. | 15 /** A set that contains pointers to instances of T. Instances can be looked up w
ith key Key. |
| 16 * Multiple (possibly same) values can have the same key. | 16 * Multiple (possibly same) values can have the same key. |
| 17 */ | 17 */ |
| 18 template <typename T, | 18 template <typename T, |
| 19 typename Key, | 19 typename Key, |
| 20 const Key& (GetKey)(const T&), | 20 const Key& (GetKey)(const T&), |
| 21 uint32_t (Hash)(const Key&), | 21 uint32_t (Hash)(const Key&)> |
| 22 bool (Equal)(const T&, const Key&)> | |
| 23 class GrTMultiMap { | 22 class GrTMultiMap { |
| 24 struct ValueList { | 23 struct ValueList { |
| 25 explicit ValueList(T* value) : fValue(value), fNext(NULL) {} | 24 explicit ValueList(T* value) : fValue(value), fNext(NULL) {} |
| 26 | 25 |
| 27 static const Key& ListGetKey(const ValueList& e) { return GetKey(*e.fVal
ue); } | 26 static const Key& ListGetKey(const ValueList& e) { return GetKey(*e.fVal
ue); } |
| 28 static uint32_t ListHash(const Key& key) { return Hash(key); } | 27 static uint32_t ListHash(const Key& key) { return Hash(key); } |
| 29 static bool ListEqual(const ValueList& a, const Key& b) { | |
| 30 return Equal(*a.fValue, b); | |
| 31 } | |
| 32 T* fValue; | 28 T* fValue; |
| 33 ValueList* fNext; | 29 ValueList* fNext; |
| 34 }; | 30 }; |
| 35 public: | 31 public: |
| 36 GrTMultiMap() : fCount(0) {} | 32 GrTMultiMap() : fCount(0) {} |
| 37 | 33 |
| 38 ~GrTMultiMap() { | 34 ~GrTMultiMap() { |
| 39 SkASSERT(fCount == 0); | 35 SkASSERT(fCount == 0); |
| 40 SkASSERT(fHash.count() == 0); | 36 SkASSERT(fHash.count() == 0); |
| 41 } | 37 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 100 } |
| 105 return NULL; | 101 return NULL; |
| 106 } | 102 } |
| 107 | 103 |
| 108 int count() const { return fCount; } | 104 int count() const { return fCount; } |
| 109 | 105 |
| 110 private: | 106 private: |
| 111 SkTDynamicHash<ValueList, | 107 SkTDynamicHash<ValueList, |
| 112 Key, | 108 Key, |
| 113 ValueList::ListGetKey, | 109 ValueList::ListGetKey, |
| 114 ValueList::ListHash, | 110 ValueList::ListHash> fHash; |
| 115 ValueList::ListEqual> fHash; | |
| 116 int fCount; | 111 int fCount; |
| 117 }; | 112 }; |
| 118 | 113 |
| 119 #endif | 114 #endif |
| OLD | NEW |