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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 iterator find(const ValueType& value) { return m_impl.find(value); } | 64 iterator find(const ValueType& value) { return m_impl.find(value); } |
65 const_iterator find(const ValueType& value) const { return m_impl.find(value
); } | 65 const_iterator find(const ValueType& value) const { return m_impl.find(value
); } |
66 bool contains(const ValueType& value ) const { return m_impl.contains(value)
; } | 66 bool contains(const ValueType& value ) const { return m_impl.contains(value)
; } |
67 unsigned count(const ValueType& value ) const { return m_impl.get(value); } | 67 unsigned count(const ValueType& value ) const { return m_impl.get(value); } |
68 | 68 |
69 // Increases the count if an equal value is already present the return value | 69 // Increases the count if an equal value is already present the return value |
70 // is a pair of an iterator to the new value's location, and a bool that is | 70 // is a pair of an iterator to the new value's location, and a bool that is |
71 // true if an new entry was added. | 71 // true if an new entry was added. |
72 AddResult add(const ValueType&); | 72 AddResult add(const ValueType&); |
73 | 73 |
| 74 // Generalized add(), adding the value N times. |
| 75 AddResult add(const ValueType&, unsigned); |
| 76 |
74 // Reduces the count of the value, and removes it if count goes down to | 77 // Reduces the count of the value, and removes it if count goes down to |
75 // zero, returns true if the value is removed. | 78 // zero, returns true if the value is removed. |
76 bool remove(const ValueType& value) { return remove(find(value)); } | 79 bool remove(const ValueType& value) { return remove(find(value)); } |
77 bool remove(iterator); | 80 bool remove(iterator); |
78 | 81 |
79 // Removes the value, regardless of its count. | 82 // Removes the value, regardless of its count. |
80 void removeAll(const ValueType& value) { removeAll(find(value)); } | 83 void removeAll(const ValueType& value) { removeAll(find(value)); } |
81 void removeAll(iterator); | 84 void removeAll(iterator); |
82 | 85 |
83 // Clears the whole set. | 86 // Clears the whole set. |
84 void clear() { m_impl.clear(); } | 87 void clear() { m_impl.clear(); } |
85 | 88 |
86 template <typename VisitorDispatcher> | 89 template <typename VisitorDispatcher> |
87 void trace(VisitorDispatcher visitor) { m_impl.trace(visitor); } | 90 void trace(VisitorDispatcher visitor) { m_impl.trace(visitor); } |
88 | 91 |
89 private: | 92 private: |
90 ImplType m_impl; | 93 ImplType m_impl; |
91 }; | 94 }; |
92 | 95 |
93 template <typename T, typename U, typename V, typename W> | 96 template <typename T, typename U, typename V, typename W> |
| 97 inline typename HashCountedSet<T, U, V, W>::AddResult HashCountedSet<T, U, V, W>
::add(const ValueType& value, unsigned count) |
| 98 { |
| 99 DCHECK_GT(count, 0u); |
| 100 AddResult result = m_impl.add(value, 0); |
| 101 result.storedValue->value += count; |
| 102 return result; |
| 103 } |
| 104 |
| 105 template <typename T, typename U, typename V, typename W> |
94 inline typename HashCountedSet<T, U, V, W>::AddResult HashCountedSet<T, U, V, W>
::add(const ValueType& value) | 106 inline typename HashCountedSet<T, U, V, W>::AddResult HashCountedSet<T, U, V, W>
::add(const ValueType& value) |
95 { | 107 { |
96 AddResult result = m_impl.add(value, 0); | 108 return add(value, 1u); |
97 ++result.storedValue->value; | |
98 return result; | |
99 } | 109 } |
100 | 110 |
101 template <typename T, typename U, typename V, typename W> | 111 template <typename T, typename U, typename V, typename W> |
102 inline bool HashCountedSet<T, U, V, W>::remove(iterator it) | 112 inline bool HashCountedSet<T, U, V, W>::remove(iterator it) |
103 { | 113 { |
104 if (it == end()) | 114 if (it == end()) |
105 return false; | 115 return false; |
106 | 116 |
107 unsigned oldVal = it->value; | 117 unsigned oldVal = it->value; |
108 ASSERT(oldVal); | 118 ASSERT(oldVal); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 iterator end = collection.end(); | 167 iterator end = collection.end(); |
158 for (unsigned i = 0; it != end; ++it, ++i) | 168 for (unsigned i = 0; it != end; ++it, ++i) |
159 vector[i] = (*it).key; | 169 vector[i] = (*it).key; |
160 } | 170 } |
161 | 171 |
162 } // namespace WTF | 172 } // namespace WTF |
163 | 173 |
164 using WTF::HashCountedSet; | 174 using WTF::HashCountedSet; |
165 | 175 |
166 #endif // WTF_HashCountedSet_h | 176 #endif // WTF_HashCountedSet_h |
OLD | NEW |