Changeset 51566 in webkit for trunk/JavaScriptCore/wtf/HashMap.h
- Timestamp:
- Dec 1, 2009, 4:05:30 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/HashMap.h
r45120 r51566 84 84 MappedType take(const KeyType&); // efficient combination of get with remove 85 85 86 // An alternate version of find() that finds the object by hashing and comparing 87 // with some other type, to avoid the cost of type conversion. HashTranslator 88 // must have the following function members: 89 // static unsigned hash(const T&); 90 // static bool equal(const ValueType&, const T&); 91 template<typename T, typename HashTranslator> iterator find(const T&); 92 template<typename T, typename HashTranslator> const_iterator find(const T&) const; 93 template<typename T, typename HashTranslator> bool contains(const T&) const; 94 95 // An alternate version of add() that finds the object by hashing and comparing 96 // with some other type, to avoid the cost of type conversion if the object is already 97 // in the table. HashTranslator must have the following function members: 98 // static unsigned hash(const T&); 99 // static bool equal(const ValueType&, const T&); 100 // static translate(ValueType&, const T&, unsigned hashCode); 101 template<typename T, typename HashTranslator> pair<iterator, bool> add(const T&, const MappedType&); 102 86 103 private: 87 104 pair<iterator, bool> inlineAdd(const KeyType&, const MappedType&); … … 108 125 }; 109 126 127 template<typename ValueType, typename ValueTraits, typename T, typename Translator> 128 struct HashMapTranslatorAdapter { 129 typedef typename ValueType::first_type KeyType; 130 typedef typename ValueType::second_type MappedType; 131 132 static unsigned hash(const T& key) { return Translator::hash(key); } 133 static bool equal(const KeyType& a, const T& b) { return Translator::equal(a, b); } 134 static void translate(ValueType& location, const T& key, const MappedType&, unsigned hashCode) 135 { 136 Translator::translate(location.first, key, hashCode); 137 } 138 }; 139 110 140 template<typename T, typename U, typename V, typename W, typename X> 111 141 inline void HashMap<T, U, V, W, X>::swap(HashMap& other) … … 172 202 { 173 203 return m_impl.contains(key); 204 } 205 206 template<typename T, typename U, typename V, typename W, typename X> 207 template<typename TYPE, typename HashTranslator> 208 inline typename HashMap<T, U, V, W, X>::iterator 209 HashMap<T, U, V, W, X>::find(const TYPE& value) 210 { 211 typedef HashMapTranslatorAdapter<ValueType, ValueTraits, TYPE, HashTranslator> Adapter; 212 return m_impl.template find<TYPE, Adapter>(value); 213 } 214 215 template<typename T, typename U, typename V, typename W, typename X> 216 template<typename TYPE, typename HashTranslator> 217 inline typename HashMap<T, U, V, W, X>::const_iterator 218 HashMap<T, U, V, W, X>::find(const TYPE& value) const 219 { 220 typedef HashMapTranslatorAdapter<ValueType, ValueTraits, TYPE, HashTranslator> Adapter; 221 return m_impl.template find<TYPE, Adapter>(value); 222 } 223 224 template<typename T, typename U, typename V, typename W, typename X> 225 template<typename TYPE, typename HashTranslator> 226 inline bool 227 HashMap<T, U, V, W, X>::contains(const TYPE& value) const 228 { 229 typedef HashMapTranslatorAdapter<ValueType, ValueTraits, TYPE, HashTranslator> Adapter; 230 return m_impl.template contains<TYPE, Adapter>(value); 174 231 } 175 232 … … 192 249 } 193 250 return result; 251 } 252 253 template<typename T, typename U, typename V, typename W, typename X> 254 template<typename TYPE, typename HashTranslator> 255 pair<typename HashMap<T, U, V, W, X>::iterator, bool> 256 HashMap<T, U, V, W, X>::add(const TYPE& key, const MappedType& value) 257 { 258 typedef HashMapTranslatorAdapter<ValueType, ValueTraits, TYPE, HashTranslator> Adapter; 259 return m_impl.template addPassingHashCode<TYPE, MappedType, Adapter>(key, value); 194 260 } 195 261
Note:
See TracChangeset
for help on using the changeset viewer.