Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed. |
| 3 * Copyright (C) 2008 David Levin <levin@chromium.org> | 3 * Copyright (C) 2008 David Levin <levin@chromium.org> |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 bool isNewEntry; | 211 bool isNewEntry; |
| 212 }; | 212 }; |
| 213 | 213 |
| 214 template<typename Value, typename Extractor, typename KeyTraits> | 214 template<typename Value, typename Extractor, typename KeyTraits> |
| 215 struct HashTableHelper { | 215 struct HashTableHelper { |
| 216 static bool isEmptyBucket(const Value& value) { return isHashTraitsEmpty Value<KeyTraits>(Extractor::extract(value)); } | 216 static bool isEmptyBucket(const Value& value) { return isHashTraitsEmpty Value<KeyTraits>(Extractor::extract(value)); } |
| 217 static bool isDeletedBucket(const Value& value) { return KeyTraits::isDe letedValue(Extractor::extract(value)); } | 217 static bool isDeletedBucket(const Value& value) { return KeyTraits::isDe letedValue(Extractor::extract(value)); } |
| 218 static bool isEmptyOrDeletedBucket(const Value& value) { return isEmptyB ucket(value) || isDeletedBucket(value); } | 218 static bool isEmptyOrDeletedBucket(const Value& value) { return isEmptyB ucket(value) || isDeletedBucket(value); } |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 // Don't declare a destructor for HeapAllocated hash tables. | |
| 222 template<typename Derived, bool isGarbageCollected> | |
| 223 class HashTableDestructorBase; | |
| 224 | |
| 225 template<typename Derived> | |
| 226 class HashTableDestructorBase<Derived, true> { }; | |
| 227 | |
| 228 template<typename Derived> | |
| 229 class HashTableDestructorBase<Derived, false> { | |
| 230 public: | |
| 231 ~HashTableDestructorBase() { static_cast<Derived*>(this)->finalize(); } | |
| 232 }; | |
| 233 | |
| 221 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> | 234 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> |
| 222 class HashTable { | 235 class HashTable : public HashTableDestructorBase<HashTable<Key, Value, Extra ctor, HashFunctions, Traits, KeyTraits, Allocator>, Allocator::isGarbageCollecte d> { |
|
Mikhail
2014/03/11 09:58:13
imho this inheritance looks a bit over-complicated
zerny-chromium
2014/03/11 10:04:48
The issue with doing so is that then HashTable wil
Mikhail
2014/03/11 12:02:53
Ah I see, thanks for the explanation.
| |
| 223 public: | 236 public: |
| 224 typedef HashTableIterator<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator> iterator; | 237 typedef HashTableIterator<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator> iterator; |
| 225 typedef HashTableConstIterator<Key, Value, Extractor, HashFunctions, Tra its, KeyTraits, Allocator> const_iterator; | 238 typedef HashTableConstIterator<Key, Value, Extractor, HashFunctions, Tra its, KeyTraits, Allocator> const_iterator; |
| 226 typedef Traits ValueTraits; | 239 typedef Traits ValueTraits; |
| 227 typedef Key KeyType; | 240 typedef Key KeyType; |
| 228 typedef typename KeyTraits::PeekInType KeyPeekInType; | 241 typedef typename KeyTraits::PeekInType KeyPeekInType; |
| 229 typedef typename KeyTraits::PassInType KeyPassInType; | 242 typedef typename KeyTraits::PassInType KeyPassInType; |
| 230 typedef Value ValueType; | 243 typedef Value ValueType; |
| 231 typedef typename Traits::PeekInType ValuePeekInType; | 244 typedef typename Traits::PeekInType ValuePeekInType; |
| 232 typedef IdentityHashTranslator<HashFunctions> IdentityTranslatorType; | 245 typedef IdentityHashTranslator<HashFunctions> IdentityTranslatorType; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 for (int i = 1; i <= maxCollisions; i++) { | 284 for (int i = 1; i <= maxCollisions; i++) { |
| 272 dataLogF(" %d lookups with exactly %d collisions (%.2f%% , %.2f%% with this many or more)\n", collisionGraph[i], i, 100.0 * (collisionGraph [i] - collisionGraph[i+1]) / numAccesses, 100.0 * collisionGraph[i] / numAccesse s); | 285 dataLogF(" %d lookups with exactly %d collisions (%.2f%% , %.2f%% with this many or more)\n", collisionGraph[i], i, 100.0 * (collisionGraph [i] - collisionGraph[i+1]) / numAccesses, 100.0 * collisionGraph[i] / numAccesse s); |
| 273 } | 286 } |
| 274 dataLogF("%d rehashes\n", numRehashes); | 287 dataLogF("%d rehashes\n", numRehashes); |
| 275 dataLogF("%d reinserts\n", numReinserts); | 288 dataLogF("%d reinserts\n", numReinserts); |
| 276 } | 289 } |
| 277 }; | 290 }; |
| 278 #endif | 291 #endif |
| 279 | 292 |
| 280 HashTable(); | 293 HashTable(); |
| 281 ~HashTable() | 294 void finalize() |
| 282 { | 295 { |
| 283 if (Allocator::isGarbageCollected) | 296 ASSERT(!Allocator::isGarbageCollected); |
| 284 return; | |
| 285 if (LIKELY(!m_table)) | 297 if (LIKELY(!m_table)) |
| 286 return; | 298 return; |
| 287 deallocateTable(m_table, m_tableSize); | 299 deallocateTable(m_table, m_tableSize); |
| 288 m_table = 0; | 300 m_table = 0; |
| 289 } | 301 } |
| 290 | 302 |
| 291 HashTable(const HashTable&); | 303 HashTable(const HashTable&); |
| 292 void swap(HashTable&); | 304 void swap(HashTable&); |
| 293 HashTable& operator=(const HashTable&); | 305 HashTable& operator=(const HashTable&); |
| 294 | 306 |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 inline bool operator!=(const HashTableIteratorAdapter<T, U>& a, const HashTa bleConstIteratorAdapter<T, U>& b) | 1180 inline bool operator!=(const HashTableIteratorAdapter<T, U>& a, const HashTa bleConstIteratorAdapter<T, U>& b) |
| 1169 { | 1181 { |
| 1170 return a.m_impl != b.m_impl; | 1182 return a.m_impl != b.m_impl; |
| 1171 } | 1183 } |
| 1172 | 1184 |
| 1173 } // namespace WTF | 1185 } // namespace WTF |
| 1174 | 1186 |
| 1175 #include "wtf/HashIterators.h" | 1187 #include "wtf/HashIterators.h" |
| 1176 | 1188 |
| 1177 #endif // WTF_HashTable_h | 1189 #endif // WTF_HashTable_h |
| OLD | NEW |