| 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 typename HashTraits=T> |
| 21 uint32_t (Hash)(const Key&)> | |
| 22 class GrTMultiMap { | 21 class GrTMultiMap { |
| 23 struct ValueList { | 22 struct ValueList { |
| 24 explicit ValueList(T* value) : fValue(value), fNext(NULL) {} | 23 explicit ValueList(T* value) : fValue(value), fNext(NULL) {} |
| 25 | 24 |
| 26 static const Key& ListGetKey(const ValueList& e) { return GetKey(*e.fVal
ue); } | 25 static const Key& GetKey(const ValueList& e) { return HashTraits::GetKey
(*e.fValue); } |
| 27 static uint32_t ListHash(const Key& key) { return Hash(key); } | 26 static uint32_t Hash(const Key& key) { return HashTraits::Hash(key); } |
| 28 T* fValue; | 27 T* fValue; |
| 29 ValueList* fNext; | 28 ValueList* fNext; |
| 30 }; | 29 }; |
| 31 public: | 30 public: |
| 32 GrTMultiMap() : fCount(0) {} | 31 GrTMultiMap() : fCount(0) {} |
| 33 | 32 |
| 34 ~GrTMultiMap() { | 33 ~GrTMultiMap() { |
| 35 SkASSERT(fCount == 0); | 34 SkASSERT(fCount == 0); |
| 36 SkASSERT(fHash.count() == 0); | 35 SkASSERT(fHash.count() == 0); |
| 37 } | 36 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 return list->fValue; | 96 return list->fValue; |
| 98 } | 97 } |
| 99 list = list->fNext; | 98 list = list->fNext; |
| 100 } | 99 } |
| 101 return NULL; | 100 return NULL; |
| 102 } | 101 } |
| 103 | 102 |
| 104 int count() const { return fCount; } | 103 int count() const { return fCount; } |
| 105 | 104 |
| 106 private: | 105 private: |
| 107 SkTDynamicHash<ValueList, | 106 SkTDynamicHash<ValueList, Key> fHash; |
| 108 Key, | |
| 109 ValueList::ListGetKey, | |
| 110 ValueList::ListHash> fHash; | |
| 111 int fCount; | 107 int fCount; |
| 112 }; | 108 }; |
| 113 | 109 |
| 114 #endif | 110 #endif |
| OLD | NEW |