29 template<
typename RawKeyType,
typename ValueType,
typename ValueTraits,
typename HashFunctions>
31 typedef typename ValueType::first_type
KeyType;
33 typedef typename ValueTraits::FirstTraits
KeyTraits;
36 static unsigned hash(RawKeyType key) {
return HashFunctions::hash(key); }
37 static bool equal(
const KeyType& a, RawKeyType b) {
return HashFunctions::equal(a, b); }
41 location.second = mapped;
45 template<
typename T,
typename MappedArg,
typename HashArg,
typename KeyTraitsArg,
typename MappedTraitsArg>
46 class HashMap<
RefPtr<T>, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg> {
48 typedef KeyTraitsArg KeyTraits;
49 typedef MappedTraitsArg MappedTraits;
53 typedef typename KeyTraits::TraitType
KeyType;
59 typedef HashArg HashFunctions;
120 template<
typename T,
typename U,
typename V,
typename W,
typename X>
123 m_impl.swap(other.m_impl);
126 template<
typename T,
typename U,
typename V,
typename W,
typename X>
127 inline int HashMap<RefPtr<T>, U, V, W, X>::size()
const
129 return m_impl.size();
132 template<
typename T,
typename U,
typename V,
typename W,
typename X>
133 inline int HashMap<RefPtr<T>, U, V, W, X>::capacity()
const
135 return m_impl.capacity();
138 template<
typename T,
typename U,
typename V,
typename W,
typename X>
139 inline bool HashMap<RefPtr<T>, U, V, W, X>::isEmpty()
const
141 return m_impl.isEmpty();
144 template<
typename T,
typename U,
typename V,
typename W,
typename X>
145 inline typename HashMap<RefPtr<T>, U, V, W, X>::iterator HashMap<RefPtr<T>, U, V, W, X>::begin()
147 return m_impl.begin();
150 template<
typename T,
typename U,
typename V,
typename W,
typename X>
151 inline typename HashMap<RefPtr<T>, U, V, W, X>::iterator HashMap<RefPtr<T>, U, V, W, X>::end()
156 template<
typename T,
typename U,
typename V,
typename W,
typename X>
157 inline typename HashMap<RefPtr<T>, U, V, W, X>::const_iterator HashMap<RefPtr<T>, U, V, W, X>::begin()
const
159 return m_impl.begin();
162 template<
typename T,
typename U,
typename V,
typename W,
typename X>
163 inline typename HashMap<RefPtr<T>, U, V, W, X>::const_iterator HashMap<RefPtr<T>, U, V, W, X>::end()
const
168 template<
typename T,
typename U,
typename V,
typename W,
typename X>
169 inline typename HashMap<RefPtr<T>, U, V, W, X>::iterator HashMap<RefPtr<T>, U, V, W, X>::find(
const KeyType& key)
171 return m_impl.find(key);
174 template<
typename T,
typename U,
typename V,
typename W,
typename X>
175 inline typename HashMap<RefPtr<T>, U, V, W, X>::iterator HashMap<RefPtr<T>, U, V, W, X>::find(RawKeyType key)
177 return m_impl.template find<RawKeyType, RawKeyTranslator>(key);
180 template<
typename T,
typename U,
typename V,
typename W,
typename X>
181 inline typename HashMap<RefPtr<T>, U, V, W, X>::const_iterator HashMap<RefPtr<T>, U, V, W, X>::find(
const KeyType& key)
const
183 return m_impl.find(key);
186 template<
typename T,
typename U,
typename V,
typename W,
typename X>
187 inline typename HashMap<RefPtr<T>, U, V, W, X>::const_iterator HashMap<RefPtr<T>, U, V, W, X>::find(RawKeyType key)
const
189 return m_impl.template find<RawKeyType, RawKeyTranslator>(key);
192 template<
typename T,
typename U,
typename V,
typename W,
typename X>
193 inline bool HashMap<RefPtr<T>, U, V, W, X>::contains(
const KeyType& key)
const
195 return m_impl.contains(key);
198 template<
typename T,
typename U,
typename V,
typename W,
typename X>
199 inline bool HashMap<RefPtr<T>, U, V, W, X>::contains(RawKeyType key)
const
201 return m_impl.template contains<RawKeyType, RawKeyTranslator>(key);
204 template<
typename T,
typename U,
typename V,
typename W,
typename X>
205 inline pair<typename HashMap<RefPtr<T>, U, V, W, X>::iterator,
bool>
206 HashMap<RefPtr<T>, U, V, W, X>::inlineAdd(
const KeyType& key,
const MappedType& mapped)
208 typedef HashMapTranslator<ValueType, ValueTraits, HashFunctions> TranslatorType;
209 return m_impl.template add<KeyType, MappedType, TranslatorType>(key, mapped);
212 template<
typename T,
typename U,
typename V,
typename W,
typename X>
213 inline pair<typename HashMap<RefPtr<T>, U, V, W, X>::iterator,
bool>
214 HashMap<RefPtr<T>, U, V, W, X>::inlineAdd(RawKeyType key,
const MappedType& mapped)
216 return m_impl.template add<RawKeyType, MappedType, RawKeyTranslator>(key, mapped);
219 template<
typename T,
typename U,
typename V,
typename W,
typename X>
220 pair<typename HashMap<RefPtr<T>, U, V, W, X>::iterator,
bool>
221 HashMap<RefPtr<T>, U, V, W, X>::set(
const KeyType& key,
const MappedType& mapped)
223 pair<iterator, bool> result = inlineAdd(key, mapped);
224 if (!result.second) {
226 result.first->second = mapped;
231 template<
typename T,
typename U,
typename V,
typename W,
typename X>
232 pair<typename HashMap<RefPtr<T>, U, V, W, X>::iterator,
bool>
233 HashMap<RefPtr<T>, U, V, W, X>::set(RawKeyType key,
const MappedType& mapped)
235 pair<iterator, bool> result = inlineAdd(key, mapped);
236 if (!result.second) {
238 result.first->second = mapped;
243 template<
typename T,
typename U,
typename V,
typename W,
typename X>
244 pair<typename HashMap<RefPtr<T>, U, V, W, X>::iterator,
bool>
245 HashMap<RefPtr<T>, U, V, W, X>::add(
const KeyType& key,
const MappedType& mapped)
247 return inlineAdd(key, mapped);
250 template<
typename T,
typename U,
typename V,
typename W,
typename X>
251 pair<typename HashMap<RefPtr<T>, U, V, W, X>::iterator,
bool>
252 HashMap<RefPtr<T>, U, V, W, X>::add(RawKeyType key,
const MappedType& mapped)
254 return inlineAdd(key, mapped);
257 template<
typename T,
typename U,
typename V,
typename W,
typename MappedTraits>
258 typename HashMap<RefPtr<T>, U, V, W, MappedTraits>::MappedType
259 HashMap<RefPtr<T>, U, V, W, MappedTraits>::get(
const KeyType& key)
const
261 ValueType* entry =
const_cast<HashTableType&
>(m_impl).lookup(key);
263 return MappedTraits::emptyValue();
264 return entry->second;
267 template<
typename T,
typename U,
typename V,
typename W,
typename MappedTraits>
268 typename HashMap<RefPtr<T>, U, V, W, MappedTraits>::MappedType
269 inline HashMap<RefPtr<T>, U, V, W, MappedTraits>::inlineGet(RawKeyType key)
const
271 ValueType* entry =
const_cast<HashTableType&
>(m_impl).
template lookup<RawKeyType, RawKeyTranslator>(key);
273 return MappedTraits::emptyValue();
274 return entry->second;
277 template<
typename T,
typename U,
typename V,
typename W,
typename MappedTraits>
278 typename HashMap<RefPtr<T>, U, V, W, MappedTraits>::MappedType
279 HashMap<RefPtr<T>, U, V, W, MappedTraits>::get(RawKeyType key)
const
281 return inlineGet(key);
284 template<
typename T,
typename U,
typename V,
typename W,
typename X>
285 inline void HashMap<RefPtr<T>, U, V, W, X>::remove(iterator it)
287 if (it.m_impl == m_impl.end())
289 m_impl.checkTableConsistency();
290 m_impl.removeWithoutEntryConsistencyCheck(it.m_impl);
293 template<
typename T,
typename U,
typename V,
typename W,
typename X>
294 inline void HashMap<RefPtr<T>, U, V, W, X>::remove(
const KeyType& key)
299 template<
typename T,
typename U,
typename V,
typename W,
typename X>
300 inline void HashMap<RefPtr<T>, U, V, W, X>::remove(RawKeyType key)
305 template<
typename T,
typename U,
typename V,
typename W,
typename X>
306 inline void HashMap<RefPtr<T>, U, V, W, X>::clear()
311 template<
typename T,
typename U,
typename V,
typename W,
typename MappedTraits>
312 typename HashMap<RefPtr<T>, U, V, W, MappedTraits>::MappedType
313 HashMap<RefPtr<T>, U, V, W, MappedTraits>::take(
const KeyType& key)
316 iterator it = find(key);
318 return MappedTraits::emptyValue();
319 typename HashMap<RefPtr<T>, U, V, W, MappedTraits>::MappedType result = it->second;
324 template<
typename T,
typename U,
typename V,
typename W,
typename MappedTraits>
325 typename HashMap<RefPtr<T>, U, V, W, MappedTraits>::MappedType
326 HashMap<RefPtr<T>, U, V, W, MappedTraits>::take(RawKeyType key)
329 iterator it = find(key);
331 return MappedTraits::emptyValue();
332 typename HashMap<RefPtr<T>, U, V, W, MappedTraits>::MappedType result = it->second;
static void translate(ValueType &location, RawKeyType key, const MappedType &mapped)
static unsigned hash(RawKeyType key)
void swap(OwnArrayPtr< T > &a, OwnArrayPtr< T > &b)
bool contains(const KeyType &) const
ValueTraits::TraitType ValueType
static bool equal(const KeyType &a, RawKeyType b)
pair< typename FirstTraits::TraitType, typename SecondTraits::TraitType > TraitType
ValueTraits::SecondTraits MappedTraits
ValueType::second_type MappedType
pair< iterator, bool > add(const KeyType &, const MappedType &)
KeyTraits::TraitType KeyType
ValueTraits::FirstTraits KeyTraits
pair< iterator, bool > set(const KeyType &, const MappedType &)
ValueType::first_type KeyType
iterator find(const KeyType &)
MappedType take(const KeyType &)
MappedTraits::TraitType MappedType