| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 iterator find(const ValueType& value) { return m_impl.find(value); } | 79 iterator find(const ValueType& value) { return m_impl.find(value); } |
| 80 const_iterator find(const ValueType& value) const { | 80 const_iterator find(const ValueType& value) const { |
| 81 return m_impl.find(value); | 81 return m_impl.find(value); |
| 82 } | 82 } |
| 83 bool contains(const ValueType& value) const { return m_impl.contains(value); } | 83 bool contains(const ValueType& value) const { return m_impl.contains(value); } |
| 84 unsigned count(const ValueType& value) const { return m_impl.at(value); } | 84 unsigned count(const ValueType& value) const { return m_impl.at(value); } |
| 85 | 85 |
| 86 // Increases the count if an equal value is already present the return value | 86 // Increases the count if an equal value is already present the return value |
| 87 // is a pair of an iterator to the new value's location, and a bool that is | 87 // is a pair of an iterator to the new value's location, and a bool that is |
| 88 // true if an new entry was added. | 88 // true if an new entry was added. |
| 89 AddResult add(const ValueType&); | 89 AddResult insert(const ValueType&); |
| 90 | 90 |
| 91 // Generalized add(), adding the value N times. | 91 // Generalized add(), adding the value N times. |
| 92 AddResult add(const ValueType&, unsigned); | 92 AddResult insert(const ValueType&, unsigned); |
| 93 | 93 |
| 94 // Reduces the count of the value, and removes it if count goes down to | 94 // Reduces the count of the value, and removes it if count goes down to |
| 95 // zero, returns true if the value is removed. | 95 // zero, returns true if the value is removed. |
| 96 bool remove(const ValueType& value) { return remove(find(value)); } | 96 bool remove(const ValueType& value) { return remove(find(value)); } |
| 97 bool remove(iterator); | 97 bool remove(iterator); |
| 98 | 98 |
| 99 // Removes the value, regardless of its count. | 99 // Removes the value, regardless of its count. |
| 100 void removeAll(const ValueType& value) { removeAll(find(value)); } | 100 void removeAll(const ValueType& value) { removeAll(find(value)); } |
| 101 void removeAll(iterator); | 101 void removeAll(iterator); |
| 102 | 102 |
| 103 // Clears the whole set. | 103 // Clears the whole set. |
| 104 void clear() { m_impl.clear(); } | 104 void clear() { m_impl.clear(); } |
| 105 | 105 |
| 106 Vector<Value> asVector() const; | 106 Vector<Value> asVector() const; |
| 107 | 107 |
| 108 template <typename VisitorDispatcher> | 108 template <typename VisitorDispatcher> |
| 109 void trace(VisitorDispatcher visitor) { | 109 void trace(VisitorDispatcher visitor) { |
| 110 m_impl.trace(visitor); | 110 m_impl.trace(visitor); |
| 111 } | 111 } |
| 112 | 112 |
| 113 private: | 113 private: |
| 114 ImplType m_impl; | 114 ImplType m_impl; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 template <typename T, typename U, typename V, typename W> | 117 template <typename T, typename U, typename V, typename W> |
| 118 inline typename HashCountedSet<T, U, V, W>::AddResult | 118 inline typename HashCountedSet<T, U, V, W>::AddResult |
| 119 HashCountedSet<T, U, V, W>::add(const ValueType& value, unsigned count) { | 119 HashCountedSet<T, U, V, W>::insert(const ValueType& value, unsigned count) { |
| 120 DCHECK_GT(count, 0u); | 120 DCHECK_GT(count, 0u); |
| 121 AddResult result = m_impl.insert(value, 0); | 121 AddResult result = m_impl.insert(value, 0); |
| 122 result.storedValue->value += count; | 122 result.storedValue->value += count; |
| 123 return result; | 123 return result; |
| 124 } | 124 } |
| 125 | 125 |
| 126 template <typename T, typename U, typename V, typename W> | 126 template <typename T, typename U, typename V, typename W> |
| 127 inline typename HashCountedSet<T, U, V, W>::AddResult | 127 inline typename HashCountedSet<T, U, V, W>::AddResult |
| 128 HashCountedSet<T, U, V, W>::add(const ValueType& value) { | 128 HashCountedSet<T, U, V, W>::insert(const ValueType& value) { |
| 129 return add(value, 1u); | 129 return insert(value, 1u); |
| 130 } | 130 } |
| 131 | 131 |
| 132 template <typename T, typename U, typename V, typename W> | 132 template <typename T, typename U, typename V, typename W> |
| 133 inline bool HashCountedSet<T, U, V, W>::remove(iterator it) { | 133 inline bool HashCountedSet<T, U, V, W>::remove(iterator it) { |
| 134 if (it == end()) | 134 if (it == end()) |
| 135 return false; | 135 return false; |
| 136 | 136 |
| 137 unsigned oldVal = it->value; | 137 unsigned oldVal = it->value; |
| 138 DCHECK(oldVal); | 138 DCHECK(oldVal); |
| 139 unsigned newVal = oldVal - 1; | 139 unsigned newVal = oldVal - 1; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 Vector<T> vector; | 179 Vector<T> vector; |
| 180 copyToVector(*this, vector); | 180 copyToVector(*this, vector); |
| 181 return vector; | 181 return vector; |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace WTF | 184 } // namespace WTF |
| 185 | 185 |
| 186 using WTF::HashCountedSet; | 186 using WTF::HashCountedSet; |
| 187 | 187 |
| 188 #endif // WTF_HashCountedSet_h | 188 #endif // WTF_HashCountedSet_h |
| OLD | NEW |