| 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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 { | 434 { |
| 435 return add<IdentityTranslatorType>(Extractor::extract(value), value)
; | 435 return add<IdentityTranslatorType>(Extractor::extract(value), value)
; |
| 436 } | 436 } |
| 437 | 437 |
| 438 // A special version of add() that finds the object by hashing and compa
ring | 438 // A special version of add() that finds the object by hashing and compa
ring |
| 439 // with some other type, to avoid the cost of type conversion if the obj
ect is already | 439 // with some other type, to avoid the cost of type conversion if the obj
ect is already |
| 440 // in the table. | 440 // in the table. |
| 441 template<typename HashTranslator, typename T, typename Extra> AddResult
add(const T& key, const Extra&); | 441 template<typename HashTranslator, typename T, typename Extra> AddResult
add(const T& key, const Extra&); |
| 442 template<typename HashTranslator, typename T, typename Extra> AddResult
addPassingHashCode(const T& key, const Extra&); | 442 template<typename HashTranslator, typename T, typename Extra> AddResult
addPassingHashCode(const T& key, const Extra&); |
| 443 | 443 |
| 444 iterator find(KeyPeekInType); | 444 iterator find(KeyPeekInType key) { return find<IdentityTranslatorType>(k
ey); } |
| 445 const_iterator find(KeyPeekInType) const; | 445 const_iterator find(KeyPeekInType key) const { return find<IdentityTrans
latorType>(key); } |
| 446 bool contains(KeyPeekInType key) const { return lookup(key); } | 446 bool contains(KeyPeekInType key) const { return contains<IdentityTransla
torType>(key); } |
| 447 | 447 |
| 448 template<typename HashTranslator, typename T> iterator find(const T&); | 448 template<typename HashTranslator, typename T> iterator find(const T&); |
| 449 template<typename HashTranslator, typename T> const_iterator find(const
T&) const; | 449 template<typename HashTranslator, typename T> const_iterator find(const
T&) const; |
| 450 template<typename HashTranslator, typename T> bool contains(const T& key
) const { return lookup<HashTranslator>(key); } | 450 template<typename HashTranslator, typename T> bool contains(const T&) co
nst; |
| 451 | 451 |
| 452 void remove(KeyPeekInType); | 452 void remove(KeyPeekInType); |
| 453 void remove(iterator); | 453 void remove(iterator); |
| 454 void remove(const_iterator); | 454 void remove(const_iterator); |
| 455 void clear(); | 455 void clear(); |
| 456 | 456 |
| 457 static bool isEmptyBucket(const ValueType& value) { return isHashTraitsE
mptyValue<KeyTraits>(Extractor::extract(value)); } | 457 static bool isEmptyBucket(const ValueType& value) { return isHashTraitsE
mptyValue<KeyTraits>(Extractor::extract(value)); } |
| 458 static bool isDeletedBucket(const ValueType& value) { return KeyTraits::
isDeletedValue(Extractor::extract(value)); } | 458 static bool isDeletedBucket(const ValueType& value) { return KeyTraits::
isDeletedValue(Extractor::extract(value)); } |
| 459 static bool isEmptyOrDeletedBucket(const ValueType& value) { return Hash
TableHelper<ValueType, Extractor, KeyTraits>:: isEmptyOrDeletedBucket(value); } | 459 static bool isEmptyOrDeletedBucket(const ValueType& value) { return Hash
TableHelper<ValueType, Extractor, KeyTraits>:: isEmptyOrDeletedBucket(value); } |
| 460 | 460 |
| 461 ValueType* lookup(KeyPeekInType key) { return lookup<IdentityTranslatorT
ype, KeyPeekInType>(key); } | 461 ValueType* lookup(KeyPeekInType key) { return lookup<IdentityTranslatorT
ype, KeyPeekInType>(key); } |
| 462 const ValueType* lookup(KeyPeekInType key) const { return lookup<Identit
yTranslatorType, KeyPeekInType>(key); } | |
| 463 template<typename HashTranslator, typename T> ValueType* lookup(T); | 462 template<typename HashTranslator, typename T> ValueType* lookup(T); |
| 464 template<typename HashTranslator, typename T> const ValueType* lookup(T)
const; | 463 template<typename HashTranslator, typename T> const ValueType* lookup(T)
const; |
| 465 | 464 |
| 466 typedef int HasInlinedTraceMethodMarker; | 465 typedef int HasInlinedTraceMethodMarker; |
| 467 template<typename VisitorDispatcher> void trace(VisitorDispatcher); | 466 template<typename VisitorDispatcher> void trace(VisitorDispatcher); |
| 468 | 467 |
| 469 #if ENABLE(ASSERT) | 468 #if ENABLE(ASSERT) |
| 470 int64_t modifications() const { return m_modifications; } | 469 int64_t modifications() const { return m_modifications; } |
| 471 void registerModification() { m_modifications++; } | 470 void registerModification() { m_modifications++; } |
| 472 // HashTable and collections that build on it do not support | 471 // HashTable and collections that build on it do not support |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 #if DUMP_HASHTABLE_STATS_PER_TABLE | 891 #if DUMP_HASHTABLE_STATS_PER_TABLE |
| 893 ++m_stats->numReinserts; | 892 ++m_stats->numReinserts; |
| 894 #endif | 893 #endif |
| 895 Value* newEntry = lookupForWriting(Extractor::extract(entry)).first; | 894 Value* newEntry = lookupForWriting(Extractor::extract(entry)).first; |
| 896 Mover<ValueType, Allocator>::move(entry, *newEntry); | 895 Mover<ValueType, Allocator>::move(entry, *newEntry); |
| 897 | 896 |
| 898 return newEntry; | 897 return newEntry; |
| 899 } | 898 } |
| 900 | 899 |
| 901 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | 900 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> |
| 902 inline auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTrait
s, Allocator>::find(KeyPeekInType key) -> iterator { | |
| 903 if (ValueType* entry = lookup(key)) | |
| 904 return makeKnownGoodIterator(entry); | |
| 905 return end(); | |
| 906 } | |
| 907 | |
| 908 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | |
| 909 inline auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTrait
s, Allocator>::find(KeyPeekInType key) const -> const_iterator { | |
| 910 if (ValueType* entry = const_cast<HashTable*>(this)->lookup(key)) | |
| 911 return makeKnownGoodConstIterator(entry); | |
| 912 return end(); | |
| 913 } | |
| 914 | |
| 915 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | |
| 916 template <typename HashTranslator, typename T> | 901 template <typename HashTranslator, typename T> |
| 917 inline typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyT
raits, Allocator>::iterator HashTable<Key, Value, Extractor, HashFunctions, Trai
ts, KeyTraits, Allocator>::find(const T& key) | 902 inline typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyT
raits, Allocator>::iterator HashTable<Key, Value, Extractor, HashFunctions, Trai
ts, KeyTraits, Allocator>::find(const T& key) |
| 918 { | 903 { |
| 919 ValueType* entry = lookup<HashTranslator>(key); | 904 ValueType* entry = lookup<HashTranslator>(key); |
| 920 if (!entry) | 905 if (!entry) |
| 921 return end(); | 906 return end(); |
| 922 | 907 |
| 923 return makeKnownGoodIterator(entry); | 908 return makeKnownGoodIterator(entry); |
| 924 } | 909 } |
| 925 | 910 |
| 926 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | 911 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> |
| 927 template <typename HashTranslator, typename T> | 912 template <typename HashTranslator, typename T> |
| 928 inline typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyT
raits, Allocator>::const_iterator HashTable<Key, Value, Extractor, HashFunctions
, Traits, KeyTraits, Allocator>::find(const T& key) const | 913 inline typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyT
raits, Allocator>::const_iterator HashTable<Key, Value, Extractor, HashFunctions
, Traits, KeyTraits, Allocator>::find(const T& key) const |
| 929 { | 914 { |
| 930 ValueType* entry = const_cast<HashTable*>(this)->lookup<HashTranslator>(
key); | 915 ValueType* entry = const_cast<HashTable*>(this)->lookup<HashTranslator>(
key); |
| 931 if (!entry) | 916 if (!entry) |
| 932 return end(); | 917 return end(); |
| 933 | 918 |
| 934 return makeKnownGoodConstIterator(entry); | 919 return makeKnownGoodConstIterator(entry); |
| 935 } | 920 } |
| 936 | 921 |
| 937 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> | 922 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> |
| 923 template <typename HashTranslator, typename T> |
| 924 bool HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo
cator>::contains(const T& key) const |
| 925 { |
| 926 return const_cast<HashTable*>(this)->lookup<HashTranslator>(key); |
| 927 } |
| 928 |
| 929 template<typename Key, typename Value, typename Extractor, typename HashFunc
tions, typename Traits, typename KeyTraits, typename Allocator> |
| 938 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo
cator>::remove(ValueType* pos) | 930 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo
cator>::remove(ValueType* pos) |
| 939 { | 931 { |
| 940 registerModification(); | 932 registerModification(); |
| 941 #if DUMP_HASHTABLE_STATS | 933 #if DUMP_HASHTABLE_STATS |
| 942 atomicIncrement(&HashTableStats::numRemoves); | 934 atomicIncrement(&HashTableStats::numRemoves); |
| 943 #endif | 935 #endif |
| 944 #if DUMP_HASHTABLE_STATS_PER_TABLE | 936 #if DUMP_HASHTABLE_STATS_PER_TABLE |
| 945 ++m_stats->numRemoves; | 937 ++m_stats->numRemoves; |
| 946 #endif | 938 #endif |
| 947 | 939 |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 CollectionIterator end(toBeRemoved.end()); | 1441 CollectionIterator end(toBeRemoved.end()); |
| 1450 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) | 1442 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) |
| 1451 collection.remove(*it); | 1443 collection.remove(*it); |
| 1452 } | 1444 } |
| 1453 | 1445 |
| 1454 } // namespace WTF | 1446 } // namespace WTF |
| 1455 | 1447 |
| 1456 #include "wtf/HashIterators.h" | 1448 #include "wtf/HashIterators.h" |
| 1457 | 1449 |
| 1458 #endif // WTF_HashTable_h | 1450 #endif // WTF_HashTable_h |
| OLD | NEW |