| 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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 return m_tableSize; | 449 return m_tableSize; |
| 450 } | 450 } |
| 451 bool isEmpty() const | 451 bool isEmpty() const |
| 452 { | 452 { |
| 453 ASSERT(!m_accessForbidden); | 453 ASSERT(!m_accessForbidden); |
| 454 return !m_keyCount; | 454 return !m_keyCount; |
| 455 } | 455 } |
| 456 | 456 |
| 457 void reserveCapacityForSize(unsigned size); | 457 void reserveCapacityForSize(unsigned size); |
| 458 | 458 |
| 459 AddResult add(ValuePassInType value) | 459 template <typename IncomingValueType> |
| 460 AddResult add(IncomingValueType&& value) |
| 460 { | 461 { |
| 461 return add<IdentityTranslatorType>(Extractor::extract(value), value); | 462 return add<IdentityTranslatorType>(Extractor::extract(value), std::forwa
rd<IncomingValueType>(value)); |
| 462 } | 463 } |
| 463 | 464 |
| 464 // A special version of add() that finds the object by hashing and comparing | 465 // A special version of add() that finds the object by hashing and comparing |
| 465 // with some other type, to avoid the cost of type conversion if the object | 466 // with some other type, to avoid the cost of type conversion if the object |
| 466 // is already in the table. | 467 // is already in the table. |
| 467 template <typename HashTranslator, typename T, typename Extra> AddResult add
(T&& key, Extra&&); | 468 template <typename HashTranslator, typename T, typename Extra> AddResult add
(T&& key, Extra&&); |
| 468 template <typename HashTranslator, typename T, typename Extra> AddResult add
PassingHashCode(const T& key, const Extra&); | 469 template <typename HashTranslator, typename T, typename Extra> AddResult add
PassingHashCode(T&& key, Extra&&); |
| 469 | 470 |
| 470 iterator find(KeyPeekInType key) { return find<IdentityTranslatorType>(key);
} | 471 iterator find(KeyPeekInType key) { return find<IdentityTranslatorType>(key);
} |
| 471 const_iterator find(KeyPeekInType key) const { return find<IdentityTranslato
rType>(key); } | 472 const_iterator find(KeyPeekInType key) const { return find<IdentityTranslato
rType>(key); } |
| 472 bool contains(KeyPeekInType key) const { return contains<IdentityTranslatorT
ype>(key); } | 473 bool contains(KeyPeekInType key) const { return contains<IdentityTranslatorT
ype>(key); } |
| 473 | 474 |
| 474 template <typename HashTranslator, typename T> iterator find(const T&); | 475 template <typename HashTranslator, typename T> iterator find(const T&); |
| 475 template <typename HashTranslator, typename T> const_iterator find(const T&)
const; | 476 template <typename HashTranslator, typename T> const_iterator find(const T&)
const; |
| 476 template <typename HashTranslator, typename T> bool contains(const T&) const
; | 477 template <typename HashTranslator, typename T> bool contains(const T&) const
; |
| 477 | 478 |
| 478 void remove(KeyPeekInType); | 479 void remove(KeyPeekInType); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 ++m_keyCount; | 857 ++m_keyCount; |
| 857 | 858 |
| 858 if (shouldExpand()) | 859 if (shouldExpand()) |
| 859 entry = expand(entry); | 860 entry = expand(entry); |
| 860 | 861 |
| 861 return AddResult(this, entry, true); | 862 return AddResult(this, entry, true); |
| 862 } | 863 } |
| 863 | 864 |
| 864 template <typename Key, typename Value, typename Extractor, typename HashFunctio
ns, typename Traits, typename KeyTraits, typename Allocator> | 865 template <typename Key, typename Value, typename Extractor, typename HashFunctio
ns, typename Traits, typename KeyTraits, typename Allocator> |
| 865 template <typename HashTranslator, typename T, typename Extra> | 866 template <typename HashTranslator, typename T, typename Extra> |
| 866 typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo
cator>::AddResult HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTra
its, Allocator>::addPassingHashCode(const T& key, const Extra& extra) | 867 typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo
cator>::AddResult HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTra
its, Allocator>::addPassingHashCode(T&& key, Extra&& extra) |
| 867 { | 868 { |
| 868 ASSERT(!m_accessForbidden); | 869 ASSERT(!m_accessForbidden); |
| 869 ASSERT(Allocator::isAllocationAllowed()); | 870 ASSERT(Allocator::isAllocationAllowed()); |
| 870 if (!m_table) | 871 if (!m_table) |
| 871 expand(); | 872 expand(); |
| 872 | 873 |
| 873 FullLookupType lookupResult = fullLookupForWriting<HashTranslator>(key); | 874 FullLookupType lookupResult = fullLookupForWriting<HashTranslator>(key); |
| 874 | 875 |
| 875 ValueType* entry = lookupResult.first.first; | 876 ValueType* entry = lookupResult.first.first; |
| 876 bool found = lookupResult.first.second; | 877 bool found = lookupResult.first.second; |
| 877 unsigned h = lookupResult.second; | 878 unsigned h = lookupResult.second; |
| 878 | 879 |
| 879 if (found) | 880 if (found) |
| 880 return AddResult(this, entry, false); | 881 return AddResult(this, entry, false); |
| 881 | 882 |
| 882 registerModification(); | 883 registerModification(); |
| 883 | 884 |
| 884 if (isDeletedBucket(*entry)) { | 885 if (isDeletedBucket(*entry)) { |
| 885 initializeBucket(*entry); | 886 initializeBucket(*entry); |
| 886 --m_deletedCount; | 887 --m_deletedCount; |
| 887 } | 888 } |
| 888 | 889 |
| 889 HashTranslator::translate(*entry, key, extra, h); | 890 HashTranslator::translate(*entry, std::forward<T>(key), std::forward<Extra>(
extra), h); |
| 890 ASSERT(!isEmptyOrDeletedBucket(*entry)); | 891 ASSERT(!isEmptyOrDeletedBucket(*entry)); |
| 891 | 892 |
| 892 ++m_keyCount; | 893 ++m_keyCount; |
| 893 if (shouldExpand()) | 894 if (shouldExpand()) |
| 894 entry = expand(entry); | 895 entry = expand(entry); |
| 895 | 896 |
| 896 return AddResult(this, entry, true); | 897 return AddResult(this, entry, true); |
| 897 } | 898 } |
| 898 | 899 |
| 899 template <typename Key, typename Value, typename Extractor, typename HashFunctio
ns, typename Traits, typename KeyTraits, typename Allocator> | 900 template <typename Key, typename Value, typename Extractor, typename HashFunctio
ns, typename Traits, typename KeyTraits, typename Allocator> |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1522 CollectionIterator end(toBeRemoved.end()); | 1523 CollectionIterator end(toBeRemoved.end()); |
| 1523 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) | 1524 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) |
| 1524 collection.remove(*it); | 1525 collection.remove(*it); |
| 1525 } | 1526 } |
| 1526 | 1527 |
| 1527 } // namespace WTF | 1528 } // namespace WTF |
| 1528 | 1529 |
| 1529 #include "wtf/HashIterators.h" | 1530 #include "wtf/HashIterators.h" |
| 1530 | 1531 |
| 1531 #endif // WTF_HashTable_h | 1532 #endif // WTF_HashTable_h |
| OLD | NEW |