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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // An alternate version of find() that finds the object by hashing and | 86 // An alternate version of find() that finds the object by hashing and |
87 // comparing with some other type, to avoid the cost of type | 87 // comparing with some other type, to avoid the cost of type |
88 // conversion. HashTranslator must have the following function members: | 88 // conversion. HashTranslator must have the following function members: |
89 // static unsigned hash(const T&); | 89 // static unsigned hash(const T&); |
90 // static bool equal(const ValueType&, const T&); | 90 // static bool equal(const ValueType&, const T&); |
91 template <typename HashTranslator, typename T> iterator find(const T&) const
; | 91 template <typename HashTranslator, typename T> iterator find(const T&) const
; |
92 template <typename HashTranslator, typename T> bool contains(const T&) const
; | 92 template <typename HashTranslator, typename T> bool contains(const T&) const
; |
93 | 93 |
94 // The return value is a pair of an iterator to the new value's location, | 94 // The return value is a pair of an iterator to the new value's location, |
95 // and a bool that is true if an new entry was added. | 95 // and a bool that is true if an new entry was added. |
96 AddResult add(ValuePassInType); | 96 template <typename IncomingValueType> |
| 97 AddResult add(IncomingValueType&&); |
97 | 98 |
98 // An alternate version of add() that finds the object by hashing and | 99 // An alternate version of add() that finds the object by hashing and |
99 // comparing with some other type, to avoid the cost of type conversion if | 100 // comparing with some other type, to avoid the cost of type conversion if |
100 // the object is already in the table. HashTranslator must have the | 101 // the object is already in the table. HashTranslator must have the |
101 // following function members: | 102 // following function members: |
102 // static unsigned hash(const T&); | 103 // static unsigned hash(const T&); |
103 // static bool equal(const ValueType&, const T&); | 104 // static bool equal(const ValueType&, const T&); |
104 // static translate(ValueType&, const T&, unsigned hashCode); | 105 // static translate(ValueType&, T&&, unsigned hashCode); |
105 template <typename HashTranslator, typename T> AddResult add(const T&); | 106 template <typename HashTranslator, typename T> AddResult addWithTranslator(T
&&); |
106 | 107 |
107 void remove(ValuePeekInType); | 108 void remove(ValuePeekInType); |
108 void remove(iterator); | 109 void remove(iterator); |
109 void clear(); | 110 void clear(); |
110 template <typename Collection> | 111 template <typename Collection> |
111 void removeAll(const Collection& toBeRemoved) { WTF::removeAll(*this, toBeRe
moved); } | 112 void removeAll(const Collection& toBeRemoved) { WTF::removeAll(*this, toBeRe
moved); } |
112 | 113 |
113 ValuePassOutType take(iterator); | 114 ValuePassOutType take(iterator); |
114 ValuePassOutType take(ValuePeekInType); | 115 ValuePassOutType take(ValuePeekInType); |
115 ValuePassOutType takeAny(); | 116 ValuePassOutType takeAny(); |
116 | 117 |
117 template <typename VisitorDispatcher> | 118 template <typename VisitorDispatcher> |
118 void trace(VisitorDispatcher visitor) { m_impl.trace(visitor); } | 119 void trace(VisitorDispatcher visitor) { m_impl.trace(visitor); } |
119 | 120 |
120 private: | 121 private: |
121 HashTableType m_impl; | 122 HashTableType m_impl; |
122 }; | 123 }; |
123 | 124 |
124 struct IdentityExtractor { | 125 struct IdentityExtractor { |
125 STATIC_ONLY(IdentityExtractor); | 126 STATIC_ONLY(IdentityExtractor); |
126 template <typename T> | 127 template <typename T> |
127 static const T& extract(const T& t) { return t; } | 128 static const T& extract(const T& t) { return t; } |
128 }; | 129 }; |
129 | 130 |
130 template <typename Translator> | 131 template <typename Translator> |
131 struct HashSetTranslatorAdapter { | 132 struct HashSetTranslatorAdapter { |
132 STATIC_ONLY(HashSetTranslatorAdapter); | 133 STATIC_ONLY(HashSetTranslatorAdapter); |
133 template <typename T> static unsigned hash(const T& key) { return Translator
::hash(key); } | 134 template <typename T> static unsigned hash(const T& key) { return Translator
::hash(key); } |
134 template <typename T, typename U> static bool equal(const T& a, const U& b)
{ return Translator::equal(a, b); } | 135 template <typename T, typename U> static bool equal(const T& a, const U& b)
{ return Translator::equal(a, b); } |
135 template <typename T, typename U> static void translate(T& location, const U
& key, const U&, unsigned hashCode) | 136 template <typename T, typename U, typename V> static void translate(T& locat
ion, U&& key, const V&, unsigned hashCode) |
136 { | 137 { |
137 Translator::translate(location, key, hashCode); | 138 Translator::translate(location, std::forward<U>(key), hashCode); |
138 } | 139 } |
139 }; | 140 }; |
140 | 141 |
141 template <typename T, typename U, typename V, typename W> | 142 template <typename T, typename U, typename V, typename W> |
142 inline unsigned HashSet<T, U, V, W>::size() const | 143 inline unsigned HashSet<T, U, V, W>::size() const |
143 { | 144 { |
144 return m_impl.size(); | 145 return m_impl.size(); |
145 } | 146 } |
146 | 147 |
147 template <typename T, typename U, typename V, typename W> | 148 template <typename T, typename U, typename V, typename W> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 190 } |
190 | 191 |
191 template <typename Value, typename HashFunctions, typename Traits, typename Allo
cator> | 192 template <typename Value, typename HashFunctions, typename Traits, typename Allo
cator> |
192 template <typename HashTranslator, typename T> | 193 template <typename HashTranslator, typename T> |
193 inline bool HashSet<Value, HashFunctions, Traits, Allocator>::contains(const T&
value) const | 194 inline bool HashSet<Value, HashFunctions, Traits, Allocator>::contains(const T&
value) const |
194 { | 195 { |
195 return m_impl.template contains<HashSetTranslatorAdapter<HashTranslator>>(va
lue); | 196 return m_impl.template contains<HashSetTranslatorAdapter<HashTranslator>>(va
lue); |
196 } | 197 } |
197 | 198 |
198 template <typename T, typename U, typename V, typename W> | 199 template <typename T, typename U, typename V, typename W> |
199 inline typename HashSet<T, U, V, W>::AddResult HashSet<T, U, V, W>::add(ValuePas
sInType value) | 200 template <typename IncomingValueType> |
| 201 inline typename HashSet<T, U, V, W>::AddResult HashSet<T, U, V, W>::add(Incoming
ValueType&& value) |
200 { | 202 { |
201 return m_impl.add(value); | 203 return m_impl.add(std::forward<IncomingValueType>(value)); |
202 } | 204 } |
203 | 205 |
204 template <typename Value, typename HashFunctions, typename Traits, typename Allo
cator> | 206 template <typename Value, typename HashFunctions, typename Traits, typename Allo
cator> |
205 template <typename HashTranslator, typename T> | 207 template <typename HashTranslator, typename T> |
206 inline typename HashSet<Value, HashFunctions, Traits, Allocator>::AddResult | 208 inline typename HashSet<Value, HashFunctions, Traits, Allocator>::AddResult |
207 HashSet<Value, HashFunctions, Traits, Allocator>::add(const T& value) | 209 HashSet<Value, HashFunctions, Traits, Allocator>::addWithTranslator(T&& value) |
208 { | 210 { |
209 return m_impl.template addPassingHashCode<HashSetTranslatorAdapter<HashTrans
lator>>(value, value); | 211 // Forward only the first argument, because the second argument isn't actual
ly used in HashSetTranslatorAdapter. |
| 212 return m_impl.template addPassingHashCode<HashSetTranslatorAdapter<HashTrans
lator>>(std::forward<T>(value), value); |
210 } | 213 } |
211 | 214 |
212 template <typename T, typename U, typename V, typename W> | 215 template <typename T, typename U, typename V, typename W> |
213 inline void HashSet<T, U, V, W>::remove(iterator it) | 216 inline void HashSet<T, U, V, W>::remove(iterator it) |
214 { | 217 { |
215 m_impl.remove(it.m_impl); | 218 m_impl.remove(it.m_impl); |
216 } | 219 } |
217 | 220 |
218 template <typename T, typename U, typename V, typename W> | 221 template <typename T, typename U, typename V, typename W> |
219 inline void HashSet<T, U, V, W>::remove(ValuePeekInType value) | 222 inline void HashSet<T, U, V, W>::remove(ValuePeekInType value) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 struct NeedsTracing<HashSet<T, U, V>> { | 276 struct NeedsTracing<HashSet<T, U, V>> { |
274 static const bool value = false; | 277 static const bool value = false; |
275 }; | 278 }; |
276 #endif | 279 #endif |
277 | 280 |
278 } // namespace WTF | 281 } // namespace WTF |
279 | 282 |
280 using WTF::HashSet; | 283 using WTF::HashSet; |
281 | 284 |
282 #endif // WTF_HashSet_h | 285 #endif // WTF_HashSet_h |
OLD | NEW |