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); }
38 static void translate(ValueType& location, RawKeyType key,
const MappedType& mapped)
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> {
53 typedef typename KeyTraits::TraitType
KeyType;
59 typedef HashArg HashFunctions;
80 const_iterator begin()
const;
81 const_iterator end()
const;
83 iterator find(
const KeyType&);
84 iterator find(RawKeyType);
85 const_iterator find(
const KeyType&)
const;
86 const_iterator find(RawKeyType)
const;
87 bool contains(
const KeyType&)
const;
88 bool contains(RawKeyType)
const;
89 MappedType
get(
const KeyType&)
const;
90 MappedType
get(RawKeyType)
const;
91 MappedType inlineGet(RawKeyType)
const;
96 pair<iterator, bool>
set(
const KeyType&,
const MappedType&);
97 pair<iterator, bool>
set(RawKeyType,
const MappedType&);
102 pair<iterator, bool> add(
const KeyType&,
const MappedType&);
103 pair<iterator, bool> add(RawKeyType,
const MappedType&);
105 void remove(
const KeyType&);
106 void remove(RawKeyType);
107 void remove(iterator);
110 MappedType take(
const KeyType&);
111 MappedType take(RawKeyType);
114 pair<iterator, bool> inlineAdd(
const KeyType&,
const MappedType&);
115 pair<iterator, bool> inlineAdd(RawKeyType,
const MappedType&);
117 HashTableType m_impl;
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>
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)
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>
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>
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>
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 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 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)
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)
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)
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
KeyTraits::TraitType KeyType
ValueTraits::FirstTraits KeyTraits
ValueType::first_type KeyType
iterator find(const KeyType &)
HashTableType::iterator m_impl
MappedTraits::TraitType MappedType