5 * This material is provided "as is", with absolutely no warranty expressed
6 * or implied. Any use is at your own risk.
8 * Permission to use or copy this software for any purpose is hereby granted
9 * without fee, provided the above notices are retained on all copies.
10 * Permission to modify the code and to distribute modified code is granted,
11 * provided the above notices are retained, and a notice that the code was
12 * modified is included with the above copyright notice.
16 /* NOTE: This is an internal header file, included by other STL headers.
17 * You should not attempt to use it directly.
20 #ifndef _STLP_INTERNAL_UNORDERED_SET_H
21 #define _STLP_INTERNAL_UNORDERED_SET_H
23 #ifndef _STLP_INTERNAL_HASHTABLE_H
24 # include <stl/_hashtable.h>
29 //Specific iterator traits creation
30 _STLP_CREATE_HASH_ITERATOR_TRAITS(UnorderedSetTraitsT, Const_traits)
32 template <class _Value, _STLP_DFL_TMPL_PARAM(_HashFcn,hash<_Value>),
33 _STLP_DFL_TMPL_PARAM(_EqualKey,equal_to<_Value>),
34 _STLP_DEFAULT_ALLOCATOR_SELECT(_Value) >
36 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
37 : public __stlport_class<unordered_set<_Value, _HashFcn, _EqualKey, _Alloc> >
40 typedef unordered_set<_Value, _HashFcn, _EqualKey, _Alloc> _Self;
41 //Specific iterator traits creation
42 typedef _STLP_PRIV _UnorderedSetTraitsT<_Value> _UnorderedSetTraits;
44 typedef hashtable<_Value, _Value, _HashFcn,
45 _UnorderedSetTraits, _STLP_PRIV _Identity<_Value>, _EqualKey, _Alloc> _Ht;
47 typedef typename _Ht::key_type key_type;
48 typedef typename _Ht::value_type value_type;
49 typedef typename _Ht::hasher hasher;
50 typedef typename _Ht::key_equal key_equal;
52 typedef typename _Ht::size_type size_type;
53 typedef typename _Ht::difference_type difference_type;
54 typedef typename _Ht::pointer pointer;
55 typedef typename _Ht::const_pointer const_pointer;
56 typedef typename _Ht::reference reference;
57 typedef typename _Ht::const_reference const_reference;
59 typedef typename _Ht::iterator iterator;
60 typedef typename _Ht::const_iterator const_iterator;
61 typedef typename _Ht::local_iterator local_iterator;
62 typedef typename _Ht::const_local_iterator const_local_iterator;
64 typedef typename _Ht::allocator_type allocator_type;
66 hasher hash_function() const { return _M_ht.hash_funct(); }
67 key_equal key_eq() const { return _M_ht.key_eq(); }
68 allocator_type get_allocator() const { return _M_ht.get_allocator(); }
72 _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
75 explicit unordered_set(size_type __n = 100, const hasher& __hf = hasher(),
76 const key_equal& __eql = key_equal(),
77 const allocator_type& __a = allocator_type())
78 : _M_ht(__n, __hf, __eql, __a) {}
80 unordered_set(__move_source<_Self> src)
81 : _M_ht(__move_source<_Ht>(src.get()._M_ht)) {}
83 #if defined (_STLP_MEMBER_TEMPLATES)
84 template <class _InputIterator>
85 unordered_set(_InputIterator __f, _InputIterator __l,
86 size_type __n = 100, const hasher& __hf = hasher(),
87 const key_equal& __eql = key_equal(),
88 const allocator_type& __a = allocator_type())
89 : _M_ht(__n, __hf, __eql, __a)
90 { _M_ht.insert_unique(__f, __l); }
92 unordered_set(const value_type* __f, const value_type* __l,
93 size_type __n = 100, const hasher& __hf = hasher(),
94 const key_equal& __eql = key_equal(),
95 const allocator_type& __a = allocator_type())
96 : _M_ht(__n, __hf, __eql, __a)
97 { _M_ht.insert_unique(__f, __l); }
99 unordered_set(const_iterator __f, const_iterator __l,
100 size_type __n = 100, const hasher& __hf = hasher(),
101 const key_equal& __eql = key_equal(),
102 const allocator_type& __a = allocator_type())
103 : _M_ht(__n, __hf, __eql, __a)
104 { _M_ht.insert_unique(__f, __l); }
105 #endif /*_STLP_MEMBER_TEMPLATES */
107 _Self& operator = (const _Self& __other)
108 { _M_ht = __other._M_ht; return *this; }
110 size_type size() const { return _M_ht.size(); }
111 size_type max_size() const { return _M_ht.max_size(); }
112 bool empty() const { return _M_ht.empty(); }
113 void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
115 iterator begin() { return _M_ht.begin(); }
116 iterator end() { return _M_ht.end(); }
117 const_iterator begin() const { return _M_ht.begin(); }
118 const_iterator end() const { return _M_ht.end(); }
120 pair<iterator, bool> insert(const value_type& __obj)
121 { return _M_ht.insert_unique(__obj); }
122 iterator insert(const_iterator /*__hint*/, const value_type& __obj)
123 { return _M_ht.insert_unique(__obj); }
124 #if defined (_STLP_MEMBER_TEMPLATES)
125 template <class _InputIterator>
126 void insert(_InputIterator __f, _InputIterator __l)
128 void insert(const_iterator __f, const_iterator __l)
129 {_M_ht.insert_unique(__f, __l); }
130 void insert(const value_type* __f, const value_type* __l)
132 { _M_ht.insert_unique(__f,__l); }
134 _STLP_TEMPLATE_FOR_CONT_EXT
135 iterator find(const _KT& __key) { return _M_ht.find(__key); }
136 _STLP_TEMPLATE_FOR_CONT_EXT
137 const_iterator find(const _KT& __key) const { return _M_ht.find(__key); }
139 _STLP_TEMPLATE_FOR_CONT_EXT
140 size_type count(const _KT& __key) const { return _M_ht.count(__key); }
142 _STLP_TEMPLATE_FOR_CONT_EXT
143 pair<iterator, iterator> equal_range(const _KT& __key)
144 { return _M_ht.equal_range(__key); }
145 _STLP_TEMPLATE_FOR_CONT_EXT
146 pair<const_iterator, const_iterator> equal_range(const _KT& __key) const
147 { return _M_ht.equal_range(__key); }
149 size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
150 void erase(const_iterator __it) { _M_ht.erase(__it); }
151 void erase(const_iterator __f, const_iterator __l) { _M_ht.erase(__f, __l); }
152 void clear() { _M_ht.clear(); }
154 size_type bucket_count() const { return _M_ht.bucket_count(); }
155 size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
156 size_type bucket_size(size_type __n) const { return _M_ht.elems_in_bucket(__n); }
157 _STLP_TEMPLATE_FOR_CONT_EXT
158 size_type bucket(const _KT& __k) const { return _M_ht.bucket(__k); }
159 local_iterator begin(size_type __n) { return _M_ht.begin(__n); }
160 local_iterator end(size_type __n) { return _M_ht.end(__n); }
161 const_local_iterator begin(size_type __n) const { return _M_ht.begin(__n); }
162 const_local_iterator end(size_type __n) const { return _M_ht.end(__n); }
164 float load_factor() const { return _M_ht.load_factor(); }
165 float max_load_factor() const { return _M_ht.max_load_factor(); }
166 void max_load_factor(float __val) { _M_ht.max_load_factor(__val); }
167 void rehash(size_type __hint) { _M_ht.rehash(__hint); }
170 //Specific iterator traits creation
171 _STLP_CREATE_HASH_ITERATOR_TRAITS(UnorderedMultisetTraitsT, Const_traits)
173 template <class _Value, _STLP_DFL_TMPL_PARAM(_HashFcn,hash<_Value>),
174 _STLP_DFL_TMPL_PARAM(_EqualKey,equal_to<_Value>),
175 _STLP_DEFAULT_ALLOCATOR_SELECT(_Value) >
176 class unordered_multiset
177 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
178 : public __stlport_class<unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc> >
181 typedef unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc> _Self;
182 //Specific iterator traits creation
183 typedef _STLP_PRIV _UnorderedMultisetTraitsT<_Value> _UnorderedMultisetTraits;
185 typedef hashtable<_Value, _Value, _HashFcn,
186 _UnorderedMultisetTraits, _STLP_PRIV _Identity<_Value>, _EqualKey, _Alloc> _Ht;
188 typedef typename _Ht::key_type key_type;
189 typedef typename _Ht::value_type value_type;
190 typedef typename _Ht::hasher hasher;
191 typedef typename _Ht::key_equal key_equal;
193 typedef typename _Ht::size_type size_type;
194 typedef typename _Ht::difference_type difference_type;
195 typedef typename _Ht::pointer pointer;
196 typedef typename _Ht::const_pointer const_pointer;
197 typedef typename _Ht::reference reference;
198 typedef typename _Ht::const_reference const_reference;
200 typedef typename _Ht::iterator iterator;
201 typedef typename _Ht::const_iterator const_iterator;
202 typedef typename _Ht::local_iterator local_iterator;
203 typedef typename _Ht::const_local_iterator const_local_iterator;
205 typedef typename _Ht::allocator_type allocator_type;
207 hasher hash_function() const { return _M_ht.hash_funct(); }
208 key_equal key_eq() const { return _M_ht.key_eq(); }
209 allocator_type get_allocator() const { return _M_ht.get_allocator(); }
213 _STLP_KEY_TYPE_FOR_CONT_EXT(key_type)
216 explicit unordered_multiset(size_type __n = 100, const hasher& __hf = hasher(),
217 const key_equal& __eql = key_equal(),
218 const allocator_type& __a = allocator_type())
219 : _M_ht(__n, __hf, __eql, __a) {}
221 unordered_multiset(__move_source<_Self> src)
222 : _M_ht(__move_source<_Ht>(src.get()._M_ht)) {}
224 #if defined (_STLP_MEMBER_TEMPLATES)
225 template <class _InputIterator>
226 unordered_multiset(_InputIterator __f, _InputIterator __l,
227 size_type __n = 100, const hasher& __hf = hasher(),
228 const key_equal& __eql = key_equal(),
229 const allocator_type& __a = allocator_type())
230 : _M_ht(__n, __hf, __eql, __a)
231 { _M_ht.insert_equal(__f, __l); }
233 unordered_multiset(const value_type* __f, const value_type* __l,
234 size_type __n = 100, const hasher& __hf = hasher(),
235 const key_equal& __eql = key_equal(),
236 const allocator_type& __a = allocator_type())
237 : _M_ht(__n, __hf, __eql, __a)
238 { _M_ht.insert_equal(__f, __l); }
240 unordered_multiset(const_iterator __f, const_iterator __l,
241 size_type __n = 100, const hasher& __hf = hasher(),
242 const key_equal& __eql = key_equal(),
243 const allocator_type& __a = allocator_type())
244 : _M_ht(__n, __hf, __eql, __a)
245 { _M_ht.insert_equal(__f, __l); }
246 #endif /*_STLP_MEMBER_TEMPLATES */
248 _Self& operator = (const _Self& __other)
249 { _M_ht = __other._M_ht; return *this; }
251 size_type size() const { return _M_ht.size(); }
252 size_type max_size() const { return _M_ht.max_size(); }
253 bool empty() const { return _M_ht.empty(); }
254 void swap(_Self& hs) { _M_ht.swap(hs._M_ht); }
256 iterator begin() { return _M_ht.begin(); }
257 iterator end() { return _M_ht.end(); }
258 const_iterator begin() const { return _M_ht.begin(); }
259 const_iterator end() const { return _M_ht.end(); }
261 iterator insert(const value_type& __obj)
262 { return _M_ht.insert_equal(__obj); }
263 iterator insert(const_iterator /*__hint*/, const value_type& __obj)
264 { return _M_ht.insert_equal(__obj); }
265 #if defined (_STLP_MEMBER_TEMPLATES)
266 template <class _InputIterator>
267 void insert(_InputIterator __f, _InputIterator __l)
269 void insert(const value_type* __f, const value_type* __l)
270 { _M_ht.insert_equal(__f,__l); }
271 void insert(const_iterator __f, const_iterator __l)
272 #endif /*_STLP_MEMBER_TEMPLATES */
273 { _M_ht.insert_equal(__f, __l); }
275 _STLP_TEMPLATE_FOR_CONT_EXT
276 iterator find(const _KT& __key) { return _M_ht.find(__key); }
277 _STLP_TEMPLATE_FOR_CONT_EXT
278 const_iterator find(const _KT& __key) const { return _M_ht.find(__key); }
280 _STLP_TEMPLATE_FOR_CONT_EXT
281 size_type count(const _KT& __key) const { return _M_ht.count(__key); }
283 _STLP_TEMPLATE_FOR_CONT_EXT
284 pair<iterator, iterator> equal_range(const _KT& __key)
285 { return _M_ht.equal_range(__key); }
286 _STLP_TEMPLATE_FOR_CONT_EXT
287 pair<const_iterator, const_iterator> equal_range(const _KT& __key) const
288 { return _M_ht.equal_range(__key); }
290 size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
291 void erase(const_iterator __it) { _M_ht.erase(__it); }
292 void erase(const_iterator __f, const_iterator __l) { _M_ht.erase(__f, __l); }
293 void clear() { _M_ht.clear(); }
295 size_type bucket_count() const { return _M_ht.bucket_count(); }
296 size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
297 size_type bucket_size(size_type __n) const { return _M_ht.elems_in_bucket(__n); }
298 _STLP_TEMPLATE_FOR_CONT_EXT
299 size_type bucket(const _KT& __k) const { return _M_ht.bucket(__k); }
300 local_iterator begin(size_type __n) { return _M_ht.begin(__n); }
301 local_iterator end(size_type __n) { return _M_ht.end(__n); }
302 const_local_iterator begin(size_type __n) const { return _M_ht.begin(__n); }
303 const_local_iterator end(size_type __n) const { return _M_ht.end(__n); }
305 float load_factor() const { return _M_ht.load_factor(); }
306 float max_load_factor() const { return _M_ht.max_load_factor(); }
307 void max_load_factor(float __val) { _M_ht.max_load_factor(__val); }
308 void rehash(size_type __hint) { _M_ht.rehash(__hint); }
311 #define _STLP_TEMPLATE_HEADER template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
312 #define _STLP_TEMPLATE_CONTAINER unordered_set<_Value,_HashFcn,_EqualKey,_Alloc>
314 #include <stl/_relops_hash_cont.h>
316 #undef _STLP_TEMPLATE_CONTAINER
317 #define _STLP_TEMPLATE_CONTAINER unordered_multiset<_Value,_HashFcn,_EqualKey,_Alloc>
318 #include <stl/_relops_hash_cont.h>
320 #undef _STLP_TEMPLATE_CONTAINER
321 #undef _STLP_TEMPLATE_HEADER
323 // Specialization of insert_iterator so that it will work for unordered_set
324 // and unordered_multiset.
326 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
327 template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
328 struct __move_traits<unordered_set<_Value, _HashFcn, _EqualKey, _Alloc> > :
329 _STLP_PRIV __move_traits_aux<typename unordered_set<_Value, _HashFcn, _EqualKey, _Alloc>::_Ht>
332 template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
333 struct __move_traits<unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc> > :
334 _STLP_PRIV __move_traits_aux<typename unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc>::_Ht>
337 template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
338 class insert_iterator<unordered_set<_Value, _HashFcn, _EqualKey, _Alloc> > {
340 typedef unordered_set<_Value, _HashFcn, _EqualKey, _Alloc> _Container;
341 _Container* container;
343 typedef _Container container_type;
344 typedef output_iterator_tag iterator_category;
345 typedef void value_type;
346 typedef void difference_type;
347 typedef void pointer;
348 typedef void reference;
350 insert_iterator(_Container& __x) : container(&__x) {}
351 insert_iterator(_Container& __x, typename _Container::iterator)
353 insert_iterator<_Container>&
354 operator=(const typename _Container::value_type& __val) {
355 container->insert(__val);
358 insert_iterator<_Container>& operator*() { return *this; }
359 insert_iterator<_Container>& operator++() { return *this; }
360 insert_iterator<_Container>& operator++(int) { return *this; }
363 template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
364 class insert_iterator<unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc> > {
366 typedef unordered_multiset<_Value, _HashFcn, _EqualKey, _Alloc> _Container;
367 _Container* container;
368 typename _Container::iterator iter;
370 typedef _Container container_type;
371 typedef output_iterator_tag iterator_category;
372 typedef void value_type;
373 typedef void difference_type;
374 typedef void pointer;
375 typedef void reference;
377 insert_iterator(_Container& __x) : container(&__x) {}
378 insert_iterator(_Container& __x, typename _Container::iterator)
380 insert_iterator<_Container>&
381 operator=(const typename _Container::value_type& __val) {
382 container->insert(__val);
385 insert_iterator<_Container>& operator*() { return *this; }
386 insert_iterator<_Container>& operator++() { return *this; }
387 insert_iterator<_Container>& operator++(int) { return *this; }
389 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
393 #endif /* _STLP_INTERNAL_UNORDERED_SET_H */