| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 140 |
| 141 // replaces value but not key if key is already present return value is a | 141 // replaces value but not key if key is already present return value is a |
| 142 // pair of the iterator to the key location, and a boolean that's true if a | 142 // pair of the iterator to the key location, and a boolean that's true if a |
| 143 // new value was actually added | 143 // new value was actually added |
| 144 template <typename IncomingKeyType, typename IncomingMappedType> | 144 template <typename IncomingKeyType, typename IncomingMappedType> |
| 145 AddResult set(IncomingKeyType&&, IncomingMappedType&&); | 145 AddResult set(IncomingKeyType&&, IncomingMappedType&&); |
| 146 | 146 |
| 147 // does nothing if key is already present return value is a pair of the | 147 // does nothing if key is already present return value is a pair of the |
| 148 // iterator to the key location, and a boolean that's true if a new value | 148 // iterator to the key location, and a boolean that's true if a new value |
| 149 // was actually added | 149 // was actually added |
| 150 // TODO(pilgrim) remove deprecated add() method, use insert() instead | |
| 151 // https://crbug.com/662431 | |
| 152 template <typename IncomingKeyType, typename IncomingMappedType> | |
| 153 AddResult add(IncomingKeyType&&, IncomingMappedType&&); | |
| 154 template <typename IncomingKeyType, typename IncomingMappedType> | 150 template <typename IncomingKeyType, typename IncomingMappedType> |
| 155 AddResult insert(IncomingKeyType&&, IncomingMappedType&&); | 151 AddResult insert(IncomingKeyType&&, IncomingMappedType&&); |
| 156 | 152 |
| 157 // TODO(pilgrim) remove remove() method once all references migrated to | 153 // TODO(pilgrim) remove remove() method once all references migrated to |
| 158 // erase() | 154 // erase() |
| 159 // https://crbug.com/662431 | 155 // https://crbug.com/662431 |
| 160 void remove(KeyPeekInType); | 156 void remove(KeyPeekInType); |
| 161 void erase(KeyPeekInType); | 157 void erase(KeyPeekInType); |
| 162 void remove(iterator); | 158 void remove(iterator); |
| 163 void clear(); | 159 void clear(); |
| 164 template <typename Collection> | 160 template <typename Collection> |
| 165 void removeAll(const Collection& toBeRemoved) { | 161 void removeAll(const Collection& toBeRemoved) { |
| 166 WTF::removeAll(*this, toBeRemoved); | 162 WTF::removeAll(*this, toBeRemoved); |
| 167 } | 163 } |
| 168 | 164 |
| 169 MappedType take(KeyPeekInType); // efficient combination of get with remove | 165 MappedType take(KeyPeekInType); // efficient combination of get with remove |
| 170 | 166 |
| 171 // An alternate version of find() that finds the object by hashing and | 167 // An alternate version of find() that finds the object by hashing and |
| 172 // comparing with some other type, to avoid the cost of type | 168 // comparing with some other type, to avoid the cost of type |
| 173 // conversion. HashTranslator must have the following function members: | 169 // conversion. HashTranslator must have the following function members: |
| 174 // static unsigned hash(const T&); | 170 // static unsigned hash(const T&); |
| 175 // static bool equal(const ValueType&, const T&); | 171 // static bool equal(const ValueType&, const T&); |
| 176 template <typename HashTranslator, typename T> | 172 template <typename HashTranslator, typename T> |
| 177 iterator find(const T&); | 173 iterator find(const T&); |
| 178 template <typename HashTranslator, typename T> | 174 template <typename HashTranslator, typename T> |
| 179 const_iterator find(const T&) const; | 175 const_iterator find(const T&) const; |
| 180 template <typename HashTranslator, typename T> | 176 template <typename HashTranslator, typename T> |
| 181 bool contains(const T&) const; | 177 bool contains(const T&) const; |
| 182 | 178 |
| 183 // An alternate version of add() that finds the object by hashing and | 179 // An alternate version of insert() that finds the object by hashing and |
| 184 // comparing with some other type, to avoid the cost of type conversion if | 180 // comparing with some other type, to avoid the cost of type conversion if |
| 185 // the object is already in the table. HashTranslator must have the | 181 // the object is already in the table. HashTranslator must have the |
| 186 // following function members: | 182 // following function members: |
| 187 // static unsigned hash(const T&); | 183 // static unsigned hash(const T&); |
| 188 // static bool equal(const ValueType&, const T&); | 184 // static bool equal(const ValueType&, const T&); |
| 189 // static translate(ValueType&, const T&, unsigned hashCode); | 185 // static translate(ValueType&, const T&, unsigned hashCode); |
| 190 // TODO(pilgrim) remove deprecated add() method, use insert() instead | |
| 191 // https://crbug.com/662431 | |
| 192 template <typename HashTranslator, | 186 template <typename HashTranslator, |
| 193 typename IncomingKeyType, | 187 typename IncomingKeyType, |
| 194 typename IncomingMappedType> | 188 typename IncomingMappedType> |
| 195 AddResult add(IncomingKeyType&&, IncomingMappedType&&); | |
| 196 template <typename HashTranslator, | |
| 197 typename IncomingKeyType, | |
| 198 typename IncomingMappedType> | |
| 199 AddResult insert(IncomingKeyType&&, IncomingMappedType&&); | 189 AddResult insert(IncomingKeyType&&, IncomingMappedType&&); |
| 200 | 190 |
| 201 static bool isValidKey(KeyPeekInType); | 191 static bool isValidKey(KeyPeekInType); |
| 202 | 192 |
| 203 template <typename VisitorDispatcher> | 193 template <typename VisitorDispatcher> |
| 204 void trace(VisitorDispatcher visitor) { | 194 void trace(VisitorDispatcher visitor) { |
| 205 m_impl.trace(visitor); | 195 m_impl.trace(visitor); |
| 206 } | 196 } |
| 207 | 197 |
| 208 private: | 198 private: |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 | 558 |
| 569 template <typename T, | 559 template <typename T, |
| 570 typename U, | 560 typename U, |
| 571 typename V, | 561 typename V, |
| 572 typename W, | 562 typename W, |
| 573 typename X, | 563 typename X, |
| 574 typename Y> | 564 typename Y> |
| 575 template <typename HashTranslator, | 565 template <typename HashTranslator, |
| 576 typename IncomingKeyType, | 566 typename IncomingKeyType, |
| 577 typename IncomingMappedType> | 567 typename IncomingMappedType> |
| 578 auto HashMap<T, U, V, W, X, Y>::add(IncomingKeyType&& key, | |
| 579 IncomingMappedType&& mapped) -> AddResult { | |
| 580 return m_impl.template addPassingHashCode< | |
| 581 HashMapTranslatorAdapter<ValueTraits, HashTranslator>>( | |
| 582 std::forward<IncomingKeyType>(key), | |
| 583 std::forward<IncomingMappedType>(mapped)); | |
| 584 } | |
| 585 | |
| 586 template <typename T, | |
| 587 typename U, | |
| 588 typename V, | |
| 589 typename W, | |
| 590 typename X, | |
| 591 typename Y> | |
| 592 template <typename HashTranslator, | |
| 593 typename IncomingKeyType, | |
| 594 typename IncomingMappedType> | |
| 595 auto HashMap<T, U, V, W, X, Y>::insert(IncomingKeyType&& key, | 568 auto HashMap<T, U, V, W, X, Y>::insert(IncomingKeyType&& key, |
| 596 IncomingMappedType&& mapped) | 569 IncomingMappedType&& mapped) |
| 597 -> AddResult { | 570 -> AddResult { |
| 598 return m_impl.template addPassingHashCode< | 571 return m_impl.template addPassingHashCode< |
| 599 HashMapTranslatorAdapter<ValueTraits, HashTranslator>>( | 572 HashMapTranslatorAdapter<ValueTraits, HashTranslator>>( |
| 600 std::forward<IncomingKeyType>(key), | 573 std::forward<IncomingKeyType>(key), |
| 601 std::forward<IncomingMappedType>(mapped)); | 574 std::forward<IncomingMappedType>(mapped)); |
| 602 } | 575 } |
| 603 | 576 |
| 604 template <typename T, | 577 template <typename T, |
| 605 typename U, | 578 typename U, |
| 606 typename V, | 579 typename V, |
| 607 typename W, | 580 typename W, |
| 608 typename X, | 581 typename X, |
| 609 typename Y> | 582 typename Y> |
| 610 template <typename IncomingKeyType, typename IncomingMappedType> | 583 template <typename IncomingKeyType, typename IncomingMappedType> |
| 611 typename HashMap<T, U, V, W, X, Y>::AddResult HashMap<T, U, V, W, X, Y>::add( | |
| 612 IncomingKeyType&& key, | |
| 613 IncomingMappedType&& mapped) { | |
| 614 return inlineAdd(std::forward<IncomingKeyType>(key), | |
| 615 std::forward<IncomingMappedType>(mapped)); | |
| 616 } | |
| 617 | |
| 618 template <typename T, | |
| 619 typename U, | |
| 620 typename V, | |
| 621 typename W, | |
| 622 typename X, | |
| 623 typename Y> | |
| 624 template <typename IncomingKeyType, typename IncomingMappedType> | |
| 625 typename HashMap<T, U, V, W, X, Y>::AddResult HashMap<T, U, V, W, X, Y>::insert( | 584 typename HashMap<T, U, V, W, X, Y>::AddResult HashMap<T, U, V, W, X, Y>::insert( |
| 626 IncomingKeyType&& key, | 585 IncomingKeyType&& key, |
| 627 IncomingMappedType&& mapped) { | 586 IncomingMappedType&& mapped) { |
| 628 return inlineAdd(std::forward<IncomingKeyType>(key), | 587 return inlineAdd(std::forward<IncomingKeyType>(key), |
| 629 std::forward<IncomingMappedType>(mapped)); | 588 std::forward<IncomingMappedType>(mapped)); |
| 630 } | 589 } |
| 631 | 590 |
| 632 template <typename T, | 591 template <typename T, |
| 633 typename U, | 592 typename U, |
| 634 typename V, | 593 typename V, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 iterator end = collection.end().values(); | 751 iterator end = collection.end().values(); |
| 793 for (unsigned i = 0; it != end; ++it, ++i) | 752 for (unsigned i = 0; it != end; ++it, ++i) |
| 794 vector[i] = *it; | 753 vector[i] = *it; |
| 795 } | 754 } |
| 796 | 755 |
| 797 } // namespace WTF | 756 } // namespace WTF |
| 798 | 757 |
| 799 using WTF::HashMap; | 758 using WTF::HashMap; |
| 800 | 759 |
| 801 #endif // WTF_HashMap_h | 760 #endif // WTF_HashMap_h |
| OLD | NEW |