| 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 11 matching lines...) Expand all Loading... |
| 22 // If the key is large and stored inside T, you may want to make K a const&. | 22 // If the key is large and stored inside T, you may want to make K a const&. |
| 23 // Similarly, if T is large you might want it to be a pointer. | 23 // Similarly, if T is large you might want it to be a pointer. |
| 24 template <typename T, typename K, typename Traits = T> | 24 template <typename T, typename K, typename Traits = T> |
| 25 class SkTHashTable : SkNoncopyable { | 25 class SkTHashTable : SkNoncopyable { |
| 26 public: | 26 public: |
| 27 SkTHashTable() : fCount(0), fRemoved(0), fCapacity(0) {} | 27 SkTHashTable() : fCount(0), fRemoved(0), fCapacity(0) {} |
| 28 | 28 |
| 29 // Clear the table. | 29 // Clear the table. |
| 30 void reset() { | 30 void reset() { |
| 31 this->~SkTHashTable(); | 31 this->~SkTHashTable(); |
| 32 SkNEW_PLACEMENT(this, SkTHashTable); | 32 new (this) SkTHashTable; |
| 33 } | 33 } |
| 34 | 34 |
| 35 // How many entries are in the table? | 35 // How many entries are in the table? |
| 36 int count() const { return fCount; } | 36 int count() const { return fCount; } |
| 37 | 37 |
| 38 // Approximately how many bytes of memory do we use beyond sizeof(*this)? | 38 // Approximately how many bytes of memory do we use beyond sizeof(*this)? |
| 39 size_t approxBytesUsed() const { return fCapacity * sizeof(Slot); } | 39 size_t approxBytesUsed() const { return fCapacity * sizeof(Slot); } |
| 40 | 40 |
| 41 // !!!!!!!!!!!!!!!!! CAUTION !!!!!!!!!!!!!
!!!! | 41 // !!!!!!!!!!!!!!!!! CAUTION !!!!!!!!!!!!!
!!!! |
| 42 // set(), find() and foreach() all allow mutable access to table entries. | 42 // set(), find() and foreach() all allow mutable access to table entries. |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 292 |
| 293 private: | 293 private: |
| 294 struct Traits { | 294 struct Traits { |
| 295 static const T& GetKey(const T& item) { return item; } | 295 static const T& GetKey(const T& item) { return item; } |
| 296 static uint32_t Hash(const T& item) { return HashT(item); } | 296 static uint32_t Hash(const T& item) { return HashT(item); } |
| 297 }; | 297 }; |
| 298 SkTHashTable<T, T, Traits> fTable; | 298 SkTHashTable<T, T, Traits> fTable; |
| 299 }; | 299 }; |
| 300 | 300 |
| 301 #endif//SkTHash_DEFINED | 301 #endif//SkTHash_DEFINED |
| OLD | NEW |