| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 SkTHash_DEFINED | 8 #ifndef SkTHash_DEFINED |
| 9 #define SkTHash_DEFINED | 9 #define SkTHash_DEFINED |
| 10 | 10 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // Copy an item into the set. | 230 // Copy an item into the set. |
| 231 void add(const T& item) { fTable.set(item); } | 231 void add(const T& item) { fTable.set(item); } |
| 232 | 232 |
| 233 // Is this item in the set? | 233 // Is this item in the set? |
| 234 bool contains(const T& item) const { return SkToBool(this->find(item)); } | 234 bool contains(const T& item) const { return SkToBool(this->find(item)); } |
| 235 | 235 |
| 236 // If an item equal to this is in the set, return a pointer to it, otherwise
null. | 236 // If an item equal to this is in the set, return a pointer to it, otherwise
null. |
| 237 // This pointer remains valid until the next call to add(). | 237 // This pointer remains valid until the next call to add(). |
| 238 const T* find(const T& item) const { return fTable.find(item); } | 238 const T* find(const T& item) const { return fTable.find(item); } |
| 239 | 239 |
| 240 // Call fn on every item in the set. You may not mutate anything. |
| 241 template <typename Fn> // f(T), f(const T&) |
| 242 void foreach (Fn&& fn) const { |
| 243 fTable.foreach (fn); |
| 244 } |
| 245 |
| 240 private: | 246 private: |
| 241 struct Traits { | 247 struct Traits { |
| 242 static const T& GetKey(const T& item) { return item; } | 248 static const T& GetKey(const T& item) { return item; } |
| 243 static uint32_t Hash(const T& item) { return HashT(item); } | 249 static uint32_t Hash(const T& item) { return HashT(item); } |
| 244 }; | 250 }; |
| 245 SkTHashTable<T, T, Traits> fTable; | 251 SkTHashTable<T, T, Traits> fTable; |
| 246 }; | 252 }; |
| 247 | 253 |
| 248 #endif//SkTHash_DEFINED | 254 #endif//SkTHash_DEFINED |
| OLD | NEW |