Changeset 11739 in webkit for trunk/JavaScriptCore/kxmlcore/HashMap.h
- Timestamp:
- Dec 22, 2005, 5:52:43 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kxmlcore/HashMap.h
r11561 r11739 31 31 32 32 template<typename PairType> 33 inline typename PairType::first_type extractFirst(const PairType& value)33 inline typename PairType::first_type const& extractFirst(const PairType& value) 34 34 { 35 35 return value.first; 36 36 } 37 38 template<typename Key, typename Mapped, typename HashFunctions> 39 class HashMapTranslator 40 { 41 typedef pair<Key, Mapped> ValueType; 42 43 public: 44 static unsigned hash(const Key& key) 45 { 46 return HashFunctions::hash(key); 47 } 48 49 static bool equal(const Key& a, const Key& b) 50 { 51 return HashFunctions::equal(a, b); 52 } 53 54 static void translate(ValueType& location, const Key& key, const Mapped& mapped, unsigned) 55 { 56 ValueType tmp(key, mapped); 57 swap(tmp, location); 58 } 59 }; 60 37 61 38 62 template<typename Key, typename Mapped, typename HashFunctions = DefaultHash<Key>, typename KeyTraits = HashTraits<Key>, typename MappedTraits = HashTraits<Mapped> > … … 41 65 typedef Key KeyType; 42 66 typedef Mapped MappedType; 43 typedef std::pair<Key, Mapped> ValueType;67 typedef pair<Key, Mapped> ValueType; 44 68 typedef PairHashTraits<KeyTraits, MappedTraits> ValueTraits; 45 69 private: 46 typedef HashTable<KeyType, ValueType, extractFirst<ValueType>, HashFunctions, ValueTraits> ImplType; 70 typedef HashTable<KeyType, ValueType, extractFirst<ValueType>, HashFunctions, ValueTraits, KeyTraits> ImplType; 71 typedef HashMapTranslator<Key, Mapped, HashFunctions> TranslatorType; 47 72 public: 48 73 typedef typename ImplType::iterator iterator; … … 69 94 // return value is a pair of the iterator to the key location, 70 95 // and a boolean that's true if a new value was actually added 71 std::pair<iterator, bool> set(const KeyType &key, const MappedType &mapped);96 pair<iterator, bool> set(const KeyType &key, const MappedType &mapped); 72 97 73 98 // does nothing if key is already present 74 99 // return value is a pair of the iterator to the key location, 75 100 // and a boolean that's true if a new value was actually added 76 std::pair<iterator, bool> add(const KeyType &key, const MappedType &mapped);101 pair<iterator, bool> add(const KeyType &key, const MappedType &mapped); 77 102 78 103 void remove(const KeyType& key); … … 81 106 82 107 private: 108 pair<iterator, bool> inlineAdd(const KeyType &key, const MappedType &mapped); 109 83 110 ImplType m_impl; 84 111 }; … … 145 172 146 173 template<typename Key, typename Mapped, typename HashFunctions, typename KeyTraits, typename MappedTraits> 147 std::pair<typename HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::iterator, bool> HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::set(const KeyType &key, const MappedType &mapped) 148 { 149 pair<iterator, bool> result = m_impl.insert(ValueType(key, mapped)); 150 // the insert call above won't change anything if the key is 174 pair<typename HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::iterator, bool> HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::inlineAdd(const KeyType &key, const MappedType &mapped) 175 { 176 return m_impl.template insert<KeyType, MappedType, TranslatorType>(key, mapped); 177 } 178 179 template<typename Key, typename Mapped, typename HashFunctions, typename KeyTraits, typename MappedTraits> 180 pair<typename HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::iterator, bool> HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::set(const KeyType &key, const MappedType &mapped) 181 { 182 pair<iterator, bool> result = inlineAdd(key, mapped); 183 // the add call above won't change anything if the key is 151 184 // already there; in that case, make sure to set the value. 152 185 if (!result.second) … … 156 189 157 190 template<typename Key, typename Mapped, typename HashFunctions, typename KeyTraits, typename MappedTraits> 158 std::pair<typename HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::iterator, bool> HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::add(const KeyType &key, const MappedType &mapped)159 { 160 return m_impl.insert(ValueType(key, mapped));191 pair<typename HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::iterator, bool> HashMap<Key, Mapped, HashFunctions, KeyTraits, MappedTraits>::add(const KeyType &key, const MappedType &mapped) 192 { 193 return inlineAdd(key, mapped); 161 194 } 162 195
Note:
See TracChangeset
for help on using the changeset viewer.