OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkTMultiMap_DEFINED | 8 #ifndef SkTMultiMap_DEFINED |
9 #define SkTMultiMap_DEFINED | 9 #define SkTMultiMap_DEFINED |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return list->fValue; | 95 return list->fValue; |
96 } | 96 } |
97 list = list->fNext; | 97 list = list->fNext; |
98 } | 98 } |
99 return nullptr; | 99 return nullptr; |
100 } | 100 } |
101 | 101 |
102 int count() const { return fCount; } | 102 int count() const { return fCount; } |
103 | 103 |
104 #ifdef SK_DEBUG | 104 #ifdef SK_DEBUG |
| 105 class ConstIter { |
| 106 public: |
| 107 explicit ConstIter(const SkTMultiMap* mmap) |
| 108 : fIter(&(mmap->fHash)) |
| 109 , fList(nullptr) { |
| 110 if (!fIter.done()) { |
| 111 fList = &(*fIter); |
| 112 } |
| 113 } |
| 114 |
| 115 bool done() const { |
| 116 return fIter.done(); |
| 117 } |
| 118 |
| 119 const T* operator*() { |
| 120 SkASSERT(fList); |
| 121 return fList->fValue; |
| 122 } |
| 123 |
| 124 void operator++() { |
| 125 if (fList) { |
| 126 fList = fList->fNext; |
| 127 } |
| 128 if (!fList) { |
| 129 ++fIter; |
| 130 if (!fIter.done()) { |
| 131 fList = &(*fIter); |
| 132 } |
| 133 } |
| 134 } |
| 135 |
| 136 private: |
| 137 typename SkTDynamicHash<ValueList, Key>::ConstIter fIter; |
| 138 const ValueList* fList; |
| 139 }; |
| 140 |
| 141 bool has(const T* value, const Key& key) const { |
| 142 for (ValueList* list = fHash.find(key); list; list = list->fNext) { |
| 143 if (list->fValue == value) { |
| 144 return true; |
| 145 } |
| 146 } |
| 147 return false; |
| 148 } |
| 149 |
105 // This is not particularly fast and only used for validation, so debug only
. | 150 // This is not particularly fast and only used for validation, so debug only
. |
106 int countForKey(const Key& key) const { | 151 int countForKey(const Key& key) const { |
107 int count = 0; | 152 int count = 0; |
108 ValueList* list = fHash.find(key); | 153 ValueList* list = fHash.find(key); |
109 while (list) { | 154 while (list) { |
110 list = list->fNext; | 155 list = list->fNext; |
111 ++count; | 156 ++count; |
112 } | 157 } |
113 return count; | 158 return count; |
114 } | 159 } |
115 #endif | 160 #endif |
116 | 161 |
117 private: | 162 private: |
118 SkTDynamicHash<ValueList, Key> fHash; | 163 SkTDynamicHash<ValueList, Key> fHash; |
119 int fCount; | 164 int fCount; |
120 }; | 165 }; |
121 | 166 |
122 #endif | 167 #endif |
OLD | NEW |