1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_unordered_map.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,427 @@
1.4 +/*
1.5 + * Copyright (c) 2004
1.6 + * Francois Dumont
1.7 + *
1.8 + * This material is provided "as is", with absolutely no warranty expressed
1.9 + * or implied. Any use is at your own risk.
1.10 + *
1.11 + * Permission to use or copy this software for any purpose is hereby granted
1.12 + * without fee, provided the above notices are retained on all copies.
1.13 + * Permission to modify the code and to distribute modified code is granted,
1.14 + * provided the above notices are retained, and a notice that the code was
1.15 + * modified is included with the above copyright notice.
1.16 + *
1.17 + */
1.18 +
1.19 +/* NOTE: This is an internal header file, included by other STL headers.
1.20 + * You should not attempt to use it directly.
1.21 + */
1.22 +
1.23 +#ifndef _STLP_INTERNAL_UNORDERED_MAP_H
1.24 +#define _STLP_INTERNAL_UNORDERED_MAP_H
1.25 +
1.26 +#ifndef _STLP_INTERNAL_HASHTABLE_H
1.27 +# include <stl/_hashtable.h>
1.28 +#endif
1.29 +
1.30 +_STLP_BEGIN_NAMESPACE
1.31 +
1.32 +//Specific iterator traits creation
1.33 +_STLP_CREATE_HASH_ITERATOR_TRAITS(UnorderedMapTraitsT, traits)
1.34 +
1.35 +template <class _Key, class _Tp, _STLP_DFL_TMPL_PARAM(_HashFcn,hash<_Key>),
1.36 + _STLP_DFL_TMPL_PARAM(_EqualKey,equal_to<_Key>),
1.37 + _STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
1.38 +class unordered_map
1.39 +#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
1.40 + : public __stlport_class<unordered_map<_Key, _Tp, _HashFcn, _EqualKey, _Alloc> >
1.41 +#endif
1.42 +{
1.43 +private:
1.44 + typedef unordered_map<_Key, _Tp, _HashFcn, _EqualKey, _Alloc> _Self;
1.45 +public:
1.46 + typedef _Key key_type;
1.47 + typedef _Tp data_type;
1.48 + typedef _Tp mapped_type;
1.49 +#if !defined (__DMC__)
1.50 + typedef pair<const key_type, data_type> value_type;
1.51 +#else
1.52 + typedef pair<key_type, data_type> value_type;
1.53 +#endif
1.54 +private:
1.55 + //Specific iterator traits creation
1.56 + typedef _STLP_PRIV _UnorderedMapTraitsT<value_type> _UnorderedMapTraits;
1.57 +
1.58 +public:
1.59 + typedef hashtable<value_type, key_type, _HashFcn, _UnorderedMapTraits,
1.60 + _STLP_SELECT1ST(value_type, _Key), _EqualKey, _Alloc > _Ht;
1.61 +
1.62 + typedef typename _Ht::hasher hasher;
1.63 + typedef typename _Ht::key_equal key_equal;
1.64 +
1.65 + typedef typename _Ht::size_type size_type;
1.66 + typedef typename _Ht::difference_type difference_type;
1.67 + typedef typename _Ht::pointer pointer;
1.68 + typedef typename _Ht::const_pointer const_pointer;
1.69 + typedef typename _Ht::reference reference;
1.70 + typedef typename _Ht::const_reference const_reference;
1.71 +
1.72 + typedef typename _Ht::iterator iterator;
1.73 + typedef typename _Ht::const_iterator const_iterator;
1.74 + typedef typename _Ht::local_iterator local_iterator;
1.75 + typedef typename _Ht::const_local_iterator const_local_iterator;
1.76 +
1.77 + typedef typename _Ht::allocator_type allocator_type;
1.78 +
1.79 + hasher hash_function() const { return _M_ht.hash_funct(); }
1.80 + key_equal key_eq() const { return _M_ht.key_eq(); }
1.81 + allocator_type get_allocator() const { return _M_ht.get_allocator(); }
1.82 +
1.83 +private:
1.84 + _Ht _M_ht;
1.85 + _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
1.86 +
1.87 +public:
1.88 + explicit unordered_map(size_type __n = 100, const hasher& __hf = hasher(),
1.89 + const key_equal& __eql = key_equal(),
1.90 + const allocator_type& __a = allocator_type())
1.91 + : _M_ht(__n, __hf, __eql, __a) {}
1.92 +
1.93 + unordered_map(__move_source<_Self> src)
1.94 + : _M_ht(__move_source<_Ht>(src.get()._M_ht)) {}
1.95 +
1.96 +#if defined (_STLP_MEMBER_TEMPLATES)
1.97 + template <class _InputIterator>
1.98 + unordered_map(_InputIterator __f, _InputIterator __l,
1.99 + size_type __n = 100, const hasher& __hf = hasher(),
1.100 + const key_equal& __eql = key_equal(),
1.101 + const allocator_type& __a = allocator_type())
1.102 + : _M_ht(__n, __hf, __eql, __a)
1.103 + { _M_ht.insert_unique(__f, __l); }
1.104 +#else
1.105 + unordered_map(const value_type* __f, const value_type* __l,
1.106 + size_type __n = 100, const hasher& __hf = hasher(),
1.107 + const key_equal& __eql = key_equal(),
1.108 + const allocator_type& __a = allocator_type())
1.109 + : _M_ht(__n, __hf, __eql, __a)
1.110 + { _M_ht.insert_unique(__f, __l); }
1.111 +
1.112 + unordered_map(const_iterator __f, const_iterator __l,
1.113 + size_type __n = 100, const hasher& __hf = hasher(),
1.114 + const key_equal& __eql = key_equal(),
1.115 + const allocator_type& __a = allocator_type())
1.116 + : _M_ht(__n, __hf, __eql, __a)
1.117 + { _M_ht.insert_unique(__f, __l); }
1.118 +#endif /*_STLP_MEMBER_TEMPLATES */
1.119 +
1.120 + _Self& operator = (const _Self& __other)
1.121 + { _M_ht = __other._M_ht; return *this; }
1.122 +
1.123 + size_type size() const { return _M_ht.size(); }
1.124 + size_type max_size() const { return _M_ht.max_size(); }
1.125 + bool empty() const { return _M_ht.empty(); }
1.126 + void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
1.127 +
1.128 + iterator begin() { return _M_ht.begin(); }
1.129 + iterator end() { return _M_ht.end(); }
1.130 + const_iterator begin() const { return _M_ht.begin(); }
1.131 + const_iterator end() const { return _M_ht.end(); }
1.132 +
1.133 + pair<iterator,bool> insert(const value_type& __obj)
1.134 + { return _M_ht.insert_unique(__obj); }
1.135 + iterator insert(const_iterator /*__hint*/, const value_type& __obj)
1.136 + { return _M_ht.insert_unique(__obj); }
1.137 +#if defined (_STLP_MEMBER_TEMPLATES)
1.138 + template <class _InputIterator>
1.139 + void insert(_InputIterator __f, _InputIterator __l)
1.140 +#else
1.141 + void insert(const value_type* __f, const value_type* __l)
1.142 + { _M_ht.insert_unique(__f,__l); }
1.143 + void insert(const_iterator __f, const_iterator __l)
1.144 +#endif /*_STLP_MEMBER_TEMPLATES */
1.145 + { _M_ht.insert_unique(__f, __l); }
1.146 +
1.147 + _STLP_TEMPLATE_FOR_CONT_EXT
1.148 + iterator find(const _KT& __key) { return _M_ht.find(__key); }
1.149 + _STLP_TEMPLATE_FOR_CONT_EXT
1.150 + const_iterator find(const _KT& __key) const { return _M_ht.find(__key); }
1.151 +
1.152 + _STLP_TEMPLATE_FOR_CONT_EXT
1.153 + _Tp& operator[](const _KT& __key) {
1.154 + iterator __it = _M_ht.find(__key);
1.155 + return (__it == _M_ht.end() ?
1.156 + _M_ht._M_insert(value_type(__key, _STLP_DEFAULT_CONSTRUCTED(_Tp))).second :
1.157 + (*__it).second );
1.158 + }
1.159 +
1.160 + _STLP_TEMPLATE_FOR_CONT_EXT
1.161 + size_type count(const _KT& __key) const { return _M_ht.count(__key); }
1.162 +
1.163 + _STLP_TEMPLATE_FOR_CONT_EXT
1.164 + pair<iterator, iterator> equal_range(const _KT& __key)
1.165 + { return _M_ht.equal_range(__key); }
1.166 + _STLP_TEMPLATE_FOR_CONT_EXT
1.167 + pair<const_iterator, const_iterator> equal_range(const _KT& __key) const
1.168 + { return _M_ht.equal_range(__key); }
1.169 +
1.170 + size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
1.171 + void erase(const_iterator __it) { _M_ht.erase(__it); }
1.172 + void erase(const_iterator __f, const_iterator __l) { _M_ht.erase(__f, __l); }
1.173 + void clear() { _M_ht.clear(); }
1.174 +
1.175 + size_type bucket_count() const { return _M_ht.bucket_count(); }
1.176 + size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
1.177 + size_type bucket_size(size_type __n) const { return _M_ht.elems_in_bucket(__n); }
1.178 + _STLP_TEMPLATE_FOR_CONT_EXT
1.179 + size_type bucket(const _KT& __k) const { return _M_ht.bucket(__k); }
1.180 + local_iterator begin(size_type __n) { return _M_ht.begin(__n); }
1.181 + local_iterator end(size_type __n) { return _M_ht.end(__n); }
1.182 + const_local_iterator begin(size_type __n) const { return _M_ht.begin(__n); }
1.183 + const_local_iterator end(size_type __n) const { return _M_ht.end(__n); }
1.184 +
1.185 + float load_factor() const { return _M_ht.load_factor(); }
1.186 + float max_load_factor() const { return _M_ht.max_load_factor(); }
1.187 + void max_load_factor(float __val) { _M_ht.max_load_factor(__val); }
1.188 + void rehash(size_type __hint) { _M_ht.rehash(__hint); }
1.189 +};
1.190 +
1.191 +//Specific iterator traits creation
1.192 +_STLP_CREATE_HASH_ITERATOR_TRAITS(UnorderedMultimapTraitsT, traits)
1.193 +
1.194 +template <class _Key, class _Tp, _STLP_DFL_TMPL_PARAM(_HashFcn,hash<_Key>),
1.195 + _STLP_DFL_TMPL_PARAM(_EqualKey,equal_to<_Key>),
1.196 + _STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
1.197 +class unordered_multimap
1.198 +#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
1.199 + : public __stlport_class<unordered_multimap<_Key, _Tp, _HashFcn, _EqualKey, _Alloc> >
1.200 +#endif
1.201 +{
1.202 +private:
1.203 + typedef unordered_multimap<_Key, _Tp, _HashFcn, _EqualKey, _Alloc> _Self;
1.204 +public:
1.205 + typedef _Key key_type;
1.206 + typedef _Tp data_type;
1.207 + typedef _Tp mapped_type;
1.208 +#if !defined (__DMC__)
1.209 + typedef pair<const key_type, data_type> value_type;
1.210 +#else
1.211 + typedef pair<key_type, data_type> value_type;
1.212 +#endif
1.213 +private:
1.214 + //Specific iterator traits creation
1.215 + typedef _STLP_PRIV _UnorderedMultimapTraitsT<value_type> _UnorderedMultimapTraits;
1.216 +
1.217 +public:
1.218 + typedef hashtable<value_type, key_type, _HashFcn, _UnorderedMultimapTraits,
1.219 + _STLP_SELECT1ST(value_type, _Key), _EqualKey, _Alloc > _Ht;
1.220 +
1.221 + typedef typename _Ht::hasher hasher;
1.222 + typedef typename _Ht::key_equal key_equal;
1.223 +
1.224 + typedef typename _Ht::size_type size_type;
1.225 + typedef typename _Ht::difference_type difference_type;
1.226 + typedef typename _Ht::pointer pointer;
1.227 + typedef typename _Ht::const_pointer const_pointer;
1.228 + typedef typename _Ht::reference reference;
1.229 + typedef typename _Ht::const_reference const_reference;
1.230 +
1.231 + typedef typename _Ht::iterator iterator;
1.232 + typedef typename _Ht::const_iterator const_iterator;
1.233 + typedef typename _Ht::local_iterator local_iterator;
1.234 + typedef typename _Ht::const_local_iterator const_local_iterator;
1.235 +
1.236 + typedef typename _Ht::allocator_type allocator_type;
1.237 +
1.238 + hasher hash_function() const { return _M_ht.hash_funct(); }
1.239 + key_equal key_eq() const { return _M_ht.key_eq(); }
1.240 + allocator_type get_allocator() const { return _M_ht.get_allocator(); }
1.241 +
1.242 +private:
1.243 + _Ht _M_ht;
1.244 + _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
1.245 +
1.246 +public:
1.247 + explicit unordered_multimap(size_type __n = 100, const hasher& __hf = hasher(),
1.248 + const key_equal& __eql = key_equal(),
1.249 + const allocator_type& __a = allocator_type())
1.250 + : _M_ht(__n, __hf, __eql, __a) {}
1.251 +
1.252 + unordered_multimap(__move_source<_Self> src)
1.253 + : _M_ht(__move_source<_Ht>(src.get()._M_ht)) {}
1.254 +
1.255 +#if defined (_STLP_MEMBER_TEMPLATES)
1.256 + template <class _InputIterator>
1.257 + unordered_multimap(_InputIterator __f, _InputIterator __l,
1.258 + size_type __n = 100, const hasher& __hf = hasher(),
1.259 + const key_equal& __eql = key_equal(),
1.260 + const allocator_type& __a = allocator_type())
1.261 + : _M_ht(__n, __hf, __eql, __a)
1.262 + { _M_ht.insert_equal(__f, __l); }
1.263 +#else
1.264 + unordered_multimap(const value_type* __f, const value_type* __l,
1.265 + size_type __n = 100, const hasher& __hf = hasher(),
1.266 + const key_equal& __eql = key_equal(),
1.267 + const allocator_type& __a = allocator_type())
1.268 + : _M_ht(__n, __hf, __eql, __a)
1.269 + { _M_ht.insert_equal(__f, __l); }
1.270 +
1.271 + unordered_multimap(const_iterator __f, const_iterator __l,
1.272 + size_type __n = 100, const hasher& __hf = hasher(),
1.273 + const key_equal& __eql = key_equal(),
1.274 + const allocator_type& __a = allocator_type())
1.275 + : _M_ht(__n, __hf, __eql, __a)
1.276 + { _M_ht.insert_equal(__f, __l); }
1.277 +#endif /*_STLP_MEMBER_TEMPLATES */
1.278 +
1.279 + _Self& operator = (const _Self& __other)
1.280 + { _M_ht = __other._M_ht; return *this; }
1.281 +
1.282 + size_type size() const { return _M_ht.size(); }
1.283 + size_type max_size() const { return _M_ht.max_size(); }
1.284 + bool empty() const { return _M_ht.empty(); }
1.285 + void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
1.286 +
1.287 + iterator begin() { return _M_ht.begin(); }
1.288 + iterator end() { return _M_ht.end(); }
1.289 + const_iterator begin() const { return _M_ht.begin(); }
1.290 + const_iterator end() const { return _M_ht.end(); }
1.291 +
1.292 + iterator insert(const value_type& __obj)
1.293 + { return _M_ht.insert_equal(__obj); }
1.294 + iterator insert(const_iterator /*__hint*/, const value_type& __obj)
1.295 + { return _M_ht.insert_equal(__obj); }
1.296 +#if defined (_STLP_MEMBER_TEMPLATES)
1.297 + template <class _InputIterator>
1.298 + void insert(_InputIterator __f, _InputIterator __l)
1.299 +#else
1.300 + void insert(const value_type* __f, const value_type* __l)
1.301 + { _M_ht.insert_equal(__f,__l); }
1.302 + void insert(const_iterator __f, const_iterator __l)
1.303 +#endif /*_STLP_MEMBER_TEMPLATES */
1.304 + { _M_ht.insert_equal(__f, __l); }
1.305 +
1.306 + _STLP_TEMPLATE_FOR_CONT_EXT
1.307 + iterator find(const _KT& __key) { return _M_ht.find(__key); }
1.308 + _STLP_TEMPLATE_FOR_CONT_EXT
1.309 + const_iterator find(const _KT& __key) const { return _M_ht.find(__key); }
1.310 +
1.311 + _STLP_TEMPLATE_FOR_CONT_EXT
1.312 + size_type count(const _KT& __key) const { return _M_ht.count(__key); }
1.313 +
1.314 + _STLP_TEMPLATE_FOR_CONT_EXT
1.315 + pair<iterator, iterator> equal_range(const _KT& __key)
1.316 + { return _M_ht.equal_range(__key); }
1.317 + _STLP_TEMPLATE_FOR_CONT_EXT
1.318 + pair<const_iterator, const_iterator> equal_range(const _KT& __key) const
1.319 + { return _M_ht.equal_range(__key); }
1.320 +
1.321 + size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
1.322 + void erase(const_iterator __it) { _M_ht.erase(__it); }
1.323 + void erase(const_iterator __f, const_iterator __l) { _M_ht.erase(__f, __l); }
1.324 + void clear() { _M_ht.clear(); }
1.325 +
1.326 + size_type bucket_count() const { return _M_ht.bucket_count(); }
1.327 + size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
1.328 + size_type bucket_size(size_type __n) const { return _M_ht.elems_in_bucket(__n); }
1.329 + _STLP_TEMPLATE_FOR_CONT_EXT
1.330 + size_type bucket(const _KT& __k) const { return _M_ht.bucket(__k); }
1.331 + local_iterator begin(size_type __n) { return _M_ht.begin(__n); }
1.332 + local_iterator end(size_type __n) { return _M_ht.end(__n); }
1.333 + const_local_iterator begin(size_type __n) const { return _M_ht.begin(__n); }
1.334 + const_local_iterator end(size_type __n) const { return _M_ht.end(__n); }
1.335 +
1.336 + float load_factor() const { return _M_ht.load_factor(); }
1.337 + float max_load_factor() const { return _M_ht.max_load_factor(); }
1.338 + void max_load_factor(float __val) { _M_ht.max_load_factor(__val); }
1.339 + void rehash(size_type __hint) { _M_ht.rehash(__hint); }
1.340 +};
1.341 +
1.342 +#define _STLP_TEMPLATE_HEADER template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
1.343 +#define _STLP_TEMPLATE_CONTAINER unordered_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>
1.344 +
1.345 +#include <stl/_relops_hash_cont.h>
1.346 +
1.347 +#undef _STLP_TEMPLATE_CONTAINER
1.348 +#define _STLP_TEMPLATE_CONTAINER unordered_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>
1.349 +
1.350 +#include <stl/_relops_hash_cont.h>
1.351 +
1.352 +#undef _STLP_TEMPLATE_CONTAINER
1.353 +#undef _STLP_TEMPLATE_HEADER
1.354 +
1.355 +// Specialization of insert_iterator so that it will work for unordered_map
1.356 +// and unordered_multimap.
1.357 +
1.358 +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
1.359 +template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
1.360 +struct __move_traits<unordered_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> > :
1.361 + _STLP_PRIV __move_traits_help<typename unordered_map<_Key, _Tp, _HashFn, _EqKey, _Alloc>::_Ht>
1.362 +{};
1.363 +
1.364 +template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
1.365 +struct __move_traits<unordered_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> > :
1.366 + _STLP_PRIV __move_traits_help<typename unordered_map<_Key, _Tp, _HashFn, _EqKey, _Alloc>::_Ht>
1.367 +{};
1.368 +
1.369 +template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
1.370 +class insert_iterator<unordered_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
1.371 +protected:
1.372 + typedef unordered_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
1.373 + _Container* container;
1.374 +public:
1.375 + typedef _Container container_type;
1.376 + typedef output_iterator_tag iterator_category;
1.377 + typedef void value_type;
1.378 + typedef void difference_type;
1.379 + typedef void pointer;
1.380 + typedef void reference;
1.381 +
1.382 + insert_iterator(_Container& __x) : container(&__x) {}
1.383 + insert_iterator(_Container& __x, typename _Container::iterator)
1.384 + : container(&__x) {}
1.385 + insert_iterator<_Container>&
1.386 + operator=(const typename _Container::value_type& __val) {
1.387 + container->insert(__val);
1.388 + return *this;
1.389 + }
1.390 + insert_iterator<_Container>& operator*() { return *this; }
1.391 + insert_iterator<_Container>& operator++() { return *this; }
1.392 + insert_iterator<_Container>& operator++(int) { return *this; }
1.393 +};
1.394 +
1.395 +template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
1.396 +class insert_iterator<unordered_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
1.397 +protected:
1.398 + typedef unordered_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
1.399 + _Container* container;
1.400 + typename _Container::iterator iter;
1.401 +public:
1.402 + typedef _Container container_type;
1.403 + typedef output_iterator_tag iterator_category;
1.404 + typedef void value_type;
1.405 + typedef void difference_type;
1.406 + typedef void pointer;
1.407 + typedef void reference;
1.408 +
1.409 + insert_iterator(_Container& __x) : container(&__x) {}
1.410 + insert_iterator(_Container& __x, typename _Container::iterator)
1.411 + : container(&__x) {}
1.412 + insert_iterator<_Container>&
1.413 + operator=(const typename _Container::value_type& __val) {
1.414 + container->insert(__val);
1.415 + return *this;
1.416 + }
1.417 + insert_iterator<_Container>& operator*() { return *this; }
1.418 + insert_iterator<_Container>& operator++() { return *this; }
1.419 + insert_iterator<_Container>& operator++(int) { return *this; }
1.420 +};
1.421 +
1.422 +#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
1.423 +
1.424 +_STLP_END_NAMESPACE
1.425 +
1.426 +#endif /* _STLP_INTERNAL_UNORDERED_MAP_H */
1.427 +
1.428 +// Local Variables:
1.429 +// mode:C++
1.430 +// End: