| 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 SkTMultiMap_DEFINED |
| 10 #define GrTMultiMap_DEFINED | 10 #define SkTMultiMap_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 typename HashTraits=T> | 20 typename HashTraits=T> |
| 21 class GrTMultiMap { | 21 class SkTMultiMap { |
| 22 struct ValueList { | 22 struct ValueList { |
| 23 explicit ValueList(T* value) : fValue(value), fNext(NULL) {} | 23 explicit ValueList(T* value) : fValue(value), fNext(NULL) {} |
| 24 | 24 |
| 25 static const Key& GetKey(const ValueList& e) { return HashTraits::GetKey
(*e.fValue); } | 25 static const Key& GetKey(const ValueList& e) { return HashTraits::GetKey
(*e.fValue); } |
| 26 static uint32_t Hash(const Key& key) { return HashTraits::Hash(key); } | 26 static uint32_t Hash(const Key& key) { return HashTraits::Hash(key); } |
| 27 T* fValue; | 27 T* fValue; |
| 28 ValueList* fNext; | 28 ValueList* fNext; |
| 29 }; | 29 }; |
| 30 public: | 30 public: |
| 31 GrTMultiMap() : fCount(0) {} | 31 SkTMultiMap() : fCount(0) {} |
| 32 | 32 |
| 33 ~GrTMultiMap() { | 33 ~SkTMultiMap() { |
| 34 SkASSERT(fCount == 0); | 34 SkASSERT(fCount == 0); |
| 35 SkASSERT(fHash.count() == 0); | 35 SkASSERT(fHash.count() == 0); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void insert(const Key& key, T* value) { | 38 void insert(const Key& key, T* value) { |
| 39 ValueList* list = fHash.find(key); | 39 ValueList* list = fHash.find(key); |
| 40 if (NULL != list) { | 40 if (NULL != list) { |
| 41 // The new ValueList entry is inserted as the second element in the | 41 // The new ValueList entry is inserted as the second element in the |
| 42 // linked list, and it will contain the value of the first element. | 42 // linked list, and it will contain the value of the first element. |
| 43 ValueList* newEntry = SkNEW_ARGS(ValueList, (list->fValue)); | 43 ValueList* newEntry = SkNEW_ARGS(ValueList, (list->fValue)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 int count() const { return fCount; } | 103 int count() const { return fCount; } |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 SkTDynamicHash<ValueList, Key> fHash; | 106 SkTDynamicHash<ValueList, Key> fHash; |
| 107 int fCount; | 107 int fCount; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 #endif | 110 #endif |
| OLD | NEW |