1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_unordered_set.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,398 @@
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_SET_H
1.24 +#define _STLP_INTERNAL_UNORDERED_SET_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(UnorderedSetTraitsT, Const_traits)
1.34 +
1.35 +template <class _Value, _STLP_DFL_TMPL_PARAM(_HashFcn,hash<_Value>),
1.36 + _STLP_DFL_TMPL_PARAM(_EqualKey,equal_to<_Value>),
1.37 + _STLP_DEFAULT_ALLOCATOR_SELECT(_Value) >
1.38 +class unordered_set
1.39 +#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
1.40 + : public __stlport_class<unordered_set<_Value, _HashFcn, _EqualKey, _Alloc> >
1.41 +#endif
1.42 +{
1.43 + typedef unordered_set<_Value, _HashFcn, _EqualKey, _Alloc> _Self;
1.44 + //Specific iterator traits creation
1.45 + typedef _STLP_PRIV _UnorderedSetTraitsT<_Value> _UnorderedSetTraits;
1.46 +public:
1.47 + typedef hashtable<_Value, _Value, _HashFcn,
1.48 + _UnorderedSetTraits, _STLP_PRIV _Identity<_Value>, _EqualKey, _Alloc> _Ht;
1.49 +public:
1.50 + typedef typename _Ht::key_type key_type;
1.51 + typedef typename _Ht::value_type value_type;
1.52 + typedef typename _Ht::hasher hasher;
1.53 + typedef typename _Ht::key_equal key_equal;
1.54 +
1.55 + typedef typename _Ht::size_type size_type;
1.56 + typedef typename _Ht::difference_type difference_type;
1.57 + typedef typename _Ht::pointer pointer;
1.58 + typedef typename _Ht::const_pointer const_pointer;
1.59 + typedef typename _Ht::reference reference;
1.60 + typedef typename _Ht::const_reference const_reference;
1.61 +
1.62 + typedef typename _Ht::iterator iterator;
1.63 + typedef typename _Ht::const_iterator const_iterator;
1.64 + typedef typename _Ht::local_iterator local_iterator;
1.65 + typedef typename _Ht::const_local_iterator const_local_iterator;
1.66 +
1.67 + typedef typename _Ht::allocator_type allocator_type;
1.68 +
1.69 + hasher hash_function() const { return _M_ht.hash_funct(); }
1.70 + key_equal key_eq() const { return _M_ht.key_eq(); }
1.71 + allocator_type get_allocator() const { return _M_ht.get_allocator(); }
1.72 +
1.73 +private:
1.74 + _Ht _M_ht;
1.75 + _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
1.76 +
1.77 +public:
1.78 + explicit unordered_set(size_type __n = 100, const hasher& __hf = hasher(),
1.79 + const key_equal& __eql = key_equal(),
1.80 + const allocator_type& __a = allocator_type())
1.81 + : _M_ht(__n, __hf, __eql, __a) {}
1.82 +
1.83 + unordered_set(__move_source<_Self> src)
1.84 + : _M_ht(__move_source<_Ht>(src.get()._M_ht)) {}
1.85 +
1.86 +#if defined (_STLP_MEMBER_TEMPLATES)
1.87 + template <class _InputIterator>
1.88 + unordered_set(_InputIterator __f, _InputIterator __l,
1.89 + size_type __n = 100, const hasher& __hf = hasher(),
1.90 + const key_equal& __eql = key_equal(),
1.91 + const allocator_type& __a = allocator_type())
1.92 + : _M_ht(__n, __hf, __eql, __a)
1.93 + { _M_ht.insert_unique(__f, __l); }
1.94 +#else
1.95 + unordered_set(const value_type* __f, const value_type* __l,
1.96 + size_type __n = 100, const hasher& __hf = hasher(),
1.97 + const key_equal& __eql = key_equal(),
1.98 + const allocator_type& __a = allocator_type())
1.99 + : _M_ht(__n, __hf, __eql, __a)
1.100 + { _M_ht.insert_unique(__f, __l); }
1.101 +
1.102 + unordered_set(const_iterator __f, const_iterator __l,
1.103 + size_type __n = 100, const hasher& __hf = hasher(),
1.104 + const key_equal& __eql = key_equal(),
1.105 + const allocator_type& __a = allocator_type())
1.106 + : _M_ht(__n, __hf, __eql, __a)
1.107 + { _M_ht.insert_unique(__f, __l); }
1.108 +#endif /*_STLP_MEMBER_TEMPLATES */
1.109 +
1.110 + _Self& operator = (const _Self& __other)
1.111 + { _M_ht = __other._M_ht; return *this; }
1.112 +
1.113 + size_type size() const { return _M_ht.size(); }
1.114 + size_type max_size() const { return _M_ht.max_size(); }
1.115 + bool empty() const { return _M_ht.empty(); }
1.116 + void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
1.117 +
1.118 + iterator begin() { return _M_ht.begin(); }
1.119 + iterator end() { return _M_ht.end(); }
1.120 + const_iterator begin() const { return _M_ht.begin(); }
1.121 + const_iterator end() const { return _M_ht.end(); }
1.122 +
1.123 + pair<iterator, bool> insert(const value_type& __obj)
1.124 + { return _M_ht.insert_unique(__obj); }
1.125 + iterator insert(const_iterator /*__hint*/, const value_type& __obj)
1.126 + { return _M_ht.insert_unique(__obj); }
1.127 +#if defined (_STLP_MEMBER_TEMPLATES)
1.128 + template <class _InputIterator>
1.129 + void insert(_InputIterator __f, _InputIterator __l)
1.130 +#else
1.131 + void insert(const_iterator __f, const_iterator __l)
1.132 + {_M_ht.insert_unique(__f, __l); }
1.133 + void insert(const value_type* __f, const value_type* __l)
1.134 +#endif
1.135 + { _M_ht.insert_unique(__f,__l); }
1.136 +
1.137 + _STLP_TEMPLATE_FOR_CONT_EXT
1.138 + iterator find(const _KT& __key) { return _M_ht.find(__key); }
1.139 + _STLP_TEMPLATE_FOR_CONT_EXT
1.140 + const_iterator find(const _KT& __key) const { return _M_ht.find(__key); }
1.141 +
1.142 + _STLP_TEMPLATE_FOR_CONT_EXT
1.143 + size_type count(const _KT& __key) const { return _M_ht.count(__key); }
1.144 +
1.145 + _STLP_TEMPLATE_FOR_CONT_EXT
1.146 + pair<iterator, iterator> equal_range(const _KT& __key)
1.147 + { return _M_ht.equal_range(__key); }
1.148 + _STLP_TEMPLATE_FOR_CONT_EXT
1.149 + pair<const_iterator, const_iterator> equal_range(const _KT& __key) const
1.150 + { return _M_ht.equal_range(__key); }
1.151 +
1.152 + size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
1.153 + void erase(const_iterator __it) { _M_ht.erase(__it); }
1.154 + void erase(const_iterator __f, const_iterator __l) { _M_ht.erase(__f, __l); }
1.155 + void clear() { _M_ht.clear(); }
1.156 +
1.157 + size_type bucket_count() const { return _M_ht.bucket_count(); }
1.158 + size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
1.159 + size_type bucket_size(size_type __n) const { return _M_ht.elems_in_bucket(__n); }
1.160 + _STLP_TEMPLATE_FOR_CONT_EXT
1.161 + size_type bucket(const _KT& __k) const { return _M_ht.bucket(__k); }
1.162 + local_iterator begin(size_type __n) { return _M_ht.begin(__n); }
1.163 + local_iterator end(size_type __n) { return _M_ht.end(__n); }
1.164 + const_local_iterator begin(size_type __n) const { return _M_ht.begin(__n); }
1.165 + const_local_iterator end(size_type __n) const { return _M_ht.end(__n); }
1.166 +
1.167 + float load_factor() const { return _M_ht.load_factor(); }
1.168 + float max_load_factor() const { return _M_ht.max_load_factor(); }
1.169 + void max_load_factor(float __val) { _M_ht.max_load_factor(__val); }
1.170 + void rehash(size_type __hint) { _M_ht.rehash(__hint); }
1.171 +};
1.172 +
1.173 +//Specific iterator traits creation
1.174 +_STLP_CREATE_HASH_ITERATOR_TRAITS(UnorderedMultisetTraitsT, Const_traits)
1.175 +
1.176 +template <class _Value, _STLP_DFL_TMPL_PARAM(_HashFcn,hash<_Value>),
1.177 + _STLP_DFL_TMPL_PARAM(_EqualKey,equal_to<_Value>),
1.178 + _STLP_DEFAULT_ALLOCATOR_SELECT(_Value) >
1.179 +class unordered_multiset
1.180 +#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
1.181 + : public __stlport_class<unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc> >
1.182 +#endif
1.183 +{
1.184 + typedef unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc> _Self;
1.185 + //Specific iterator traits creation
1.186 + typedef _STLP_PRIV _UnorderedMultisetTraitsT<_Value> _UnorderedMultisetTraits;
1.187 +public:
1.188 + typedef hashtable<_Value, _Value, _HashFcn,
1.189 + _UnorderedMultisetTraits, _STLP_PRIV _Identity<_Value>, _EqualKey, _Alloc> _Ht;
1.190 +
1.191 + typedef typename _Ht::key_type key_type;
1.192 + typedef typename _Ht::value_type value_type;
1.193 + typedef typename _Ht::hasher hasher;
1.194 + typedef typename _Ht::key_equal key_equal;
1.195 +
1.196 + typedef typename _Ht::size_type size_type;
1.197 + typedef typename _Ht::difference_type difference_type;
1.198 + typedef typename _Ht::pointer pointer;
1.199 + typedef typename _Ht::const_pointer const_pointer;
1.200 + typedef typename _Ht::reference reference;
1.201 + typedef typename _Ht::const_reference const_reference;
1.202 +
1.203 + typedef typename _Ht::iterator iterator;
1.204 + typedef typename _Ht::const_iterator const_iterator;
1.205 + typedef typename _Ht::local_iterator local_iterator;
1.206 + typedef typename _Ht::const_local_iterator const_local_iterator;
1.207 +
1.208 + typedef typename _Ht::allocator_type allocator_type;
1.209 +
1.210 + hasher hash_function() const { return _M_ht.hash_funct(); }
1.211 + key_equal key_eq() const { return _M_ht.key_eq(); }
1.212 + allocator_type get_allocator() const { return _M_ht.get_allocator(); }
1.213 +
1.214 +private:
1.215 + _Ht _M_ht;
1.216 + _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
1.217 +
1.218 +public:
1.219 + explicit unordered_multiset(size_type __n = 100, const hasher& __hf = hasher(),
1.220 + const key_equal& __eql = key_equal(),
1.221 + const allocator_type& __a = allocator_type())
1.222 + : _M_ht(__n, __hf, __eql, __a) {}
1.223 +
1.224 + unordered_multiset(__move_source<_Self> src)
1.225 + : _M_ht(__move_source<_Ht>(src.get()._M_ht)) {}
1.226 +
1.227 +#if defined (_STLP_MEMBER_TEMPLATES)
1.228 + template <class _InputIterator>
1.229 + unordered_multiset(_InputIterator __f, _InputIterator __l,
1.230 + size_type __n = 100, const hasher& __hf = hasher(),
1.231 + const key_equal& __eql = key_equal(),
1.232 + const allocator_type& __a = allocator_type())
1.233 + : _M_ht(__n, __hf, __eql, __a)
1.234 + { _M_ht.insert_equal(__f, __l); }
1.235 +#else
1.236 + unordered_multiset(const value_type* __f, const value_type* __l,
1.237 + size_type __n = 100, const hasher& __hf = hasher(),
1.238 + const key_equal& __eql = key_equal(),
1.239 + const allocator_type& __a = allocator_type())
1.240 + : _M_ht(__n, __hf, __eql, __a)
1.241 + { _M_ht.insert_equal(__f, __l); }
1.242 +
1.243 + unordered_multiset(const_iterator __f, const_iterator __l,
1.244 + size_type __n = 100, const hasher& __hf = hasher(),
1.245 + const key_equal& __eql = key_equal(),
1.246 + const allocator_type& __a = allocator_type())
1.247 + : _M_ht(__n, __hf, __eql, __a)
1.248 + { _M_ht.insert_equal(__f, __l); }
1.249 +#endif /*_STLP_MEMBER_TEMPLATES */
1.250 +
1.251 + _Self& operator = (const _Self& __other)
1.252 + { _M_ht = __other._M_ht; return *this; }
1.253 +
1.254 + size_type size() const { return _M_ht.size(); }
1.255 + size_type max_size() const { return _M_ht.max_size(); }
1.256 + bool empty() const { return _M_ht.empty(); }
1.257 + void swap(_Self& hs) { _M_ht.swap(hs._M_ht); }
1.258 +
1.259 + iterator begin() { return _M_ht.begin(); }
1.260 + iterator end() { return _M_ht.end(); }
1.261 + const_iterator begin() const { return _M_ht.begin(); }
1.262 + const_iterator end() const { return _M_ht.end(); }
1.263 +
1.264 + iterator insert(const value_type& __obj)
1.265 + { return _M_ht.insert_equal(__obj); }
1.266 + iterator insert(const_iterator /*__hint*/, const value_type& __obj)
1.267 + { return _M_ht.insert_equal(__obj); }
1.268 +#if defined (_STLP_MEMBER_TEMPLATES)
1.269 + template <class _InputIterator>
1.270 + void insert(_InputIterator __f, _InputIterator __l)
1.271 +#else
1.272 + void insert(const value_type* __f, const value_type* __l)
1.273 + { _M_ht.insert_equal(__f,__l); }
1.274 + void insert(const_iterator __f, const_iterator __l)
1.275 +#endif /*_STLP_MEMBER_TEMPLATES */
1.276 + { _M_ht.insert_equal(__f, __l); }
1.277 +
1.278 + _STLP_TEMPLATE_FOR_CONT_EXT
1.279 + iterator find(const _KT& __key) { return _M_ht.find(__key); }
1.280 + _STLP_TEMPLATE_FOR_CONT_EXT
1.281 + const_iterator find(const _KT& __key) const { return _M_ht.find(__key); }
1.282 +
1.283 + _STLP_TEMPLATE_FOR_CONT_EXT
1.284 + size_type count(const _KT& __key) const { return _M_ht.count(__key); }
1.285 +
1.286 + _STLP_TEMPLATE_FOR_CONT_EXT
1.287 + pair<iterator, iterator> equal_range(const _KT& __key)
1.288 + { return _M_ht.equal_range(__key); }
1.289 + _STLP_TEMPLATE_FOR_CONT_EXT
1.290 + pair<const_iterator, const_iterator> equal_range(const _KT& __key) const
1.291 + { return _M_ht.equal_range(__key); }
1.292 +
1.293 + size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
1.294 + void erase(const_iterator __it) { _M_ht.erase(__it); }
1.295 + void erase(const_iterator __f, const_iterator __l) { _M_ht.erase(__f, __l); }
1.296 + void clear() { _M_ht.clear(); }
1.297 +
1.298 + size_type bucket_count() const { return _M_ht.bucket_count(); }
1.299 + size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
1.300 + size_type bucket_size(size_type __n) const { return _M_ht.elems_in_bucket(__n); }
1.301 + _STLP_TEMPLATE_FOR_CONT_EXT
1.302 + size_type bucket(const _KT& __k) const { return _M_ht.bucket(__k); }
1.303 + local_iterator begin(size_type __n) { return _M_ht.begin(__n); }
1.304 + local_iterator end(size_type __n) { return _M_ht.end(__n); }
1.305 + const_local_iterator begin(size_type __n) const { return _M_ht.begin(__n); }
1.306 + const_local_iterator end(size_type __n) const { return _M_ht.end(__n); }
1.307 +
1.308 + float load_factor() const { return _M_ht.load_factor(); }
1.309 + float max_load_factor() const { return _M_ht.max_load_factor(); }
1.310 + void max_load_factor(float __val) { _M_ht.max_load_factor(__val); }
1.311 + void rehash(size_type __hint) { _M_ht.rehash(__hint); }
1.312 +};
1.313 +
1.314 +#define _STLP_TEMPLATE_HEADER template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
1.315 +#define _STLP_TEMPLATE_CONTAINER unordered_set<_Value,_HashFcn,_EqualKey,_Alloc>
1.316 +
1.317 +#include <stl/_relops_hash_cont.h>
1.318 +
1.319 +#undef _STLP_TEMPLATE_CONTAINER
1.320 +#define _STLP_TEMPLATE_CONTAINER unordered_multiset<_Value,_HashFcn,_EqualKey,_Alloc>
1.321 +#include <stl/_relops_hash_cont.h>
1.322 +
1.323 +#undef _STLP_TEMPLATE_CONTAINER
1.324 +#undef _STLP_TEMPLATE_HEADER
1.325 +
1.326 +// Specialization of insert_iterator so that it will work for unordered_set
1.327 +// and unordered_multiset.
1.328 +
1.329 +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
1.330 +template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
1.331 +struct __move_traits<unordered_set<_Value, _HashFcn, _EqualKey, _Alloc> > :
1.332 + _STLP_PRIV __move_traits_aux<typename unordered_set<_Value, _HashFcn, _EqualKey, _Alloc>::_Ht>
1.333 +{};
1.334 +
1.335 +template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
1.336 +struct __move_traits<unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc> > :
1.337 + _STLP_PRIV __move_traits_aux<typename unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc>::_Ht>
1.338 +{};
1.339 +
1.340 +template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
1.341 +class insert_iterator<unordered_set<_Value, _HashFcn, _EqualKey, _Alloc> > {
1.342 +protected:
1.343 + typedef unordered_set<_Value, _HashFcn, _EqualKey, _Alloc> _Container;
1.344 + _Container* container;
1.345 +public:
1.346 + typedef _Container container_type;
1.347 + typedef output_iterator_tag iterator_category;
1.348 + typedef void value_type;
1.349 + typedef void difference_type;
1.350 + typedef void pointer;
1.351 + typedef void reference;
1.352 +
1.353 + insert_iterator(_Container& __x) : container(&__x) {}
1.354 + insert_iterator(_Container& __x, typename _Container::iterator)
1.355 + : container(&__x) {}
1.356 + insert_iterator<_Container>&
1.357 + operator=(const typename _Container::value_type& __val) {
1.358 + container->insert(__val);
1.359 + return *this;
1.360 + }
1.361 + insert_iterator<_Container>& operator*() { return *this; }
1.362 + insert_iterator<_Container>& operator++() { return *this; }
1.363 + insert_iterator<_Container>& operator++(int) { return *this; }
1.364 +};
1.365 +
1.366 +template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
1.367 +class insert_iterator<unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc> > {
1.368 +protected:
1.369 + typedef unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc> _Container;
1.370 + _Container* container;
1.371 + typename _Container::iterator iter;
1.372 +public:
1.373 + typedef _Container container_type;
1.374 + typedef output_iterator_tag iterator_category;
1.375 + typedef void value_type;
1.376 + typedef void difference_type;
1.377 + typedef void pointer;
1.378 + typedef void reference;
1.379 +
1.380 + insert_iterator(_Container& __x) : container(&__x) {}
1.381 + insert_iterator(_Container& __x, typename _Container::iterator)
1.382 + : container(&__x) {}
1.383 + insert_iterator<_Container>&
1.384 + operator=(const typename _Container::value_type& __val) {
1.385 + container->insert(__val);
1.386 + return *this;
1.387 + }
1.388 + insert_iterator<_Container>& operator*() { return *this; }
1.389 + insert_iterator<_Container>& operator++() { return *this; }
1.390 + insert_iterator<_Container>& operator++(int) { return *this; }
1.391 +};
1.392 +#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
1.393 +
1.394 +_STLP_END_NAMESPACE
1.395 +
1.396 +#endif /* _STLP_INTERNAL_UNORDERED_SET_H */
1.397 +
1.398 +// Local Variables:
1.399 +// mode:C++
1.400 +// End:
1.401 +