williamr@2
|
1 |
/*
|
williamr@2
|
2 |
*
|
williamr@2
|
3 |
* Copyright (c) 1994
|
williamr@2
|
4 |
* Hewlett-Packard Company
|
williamr@2
|
5 |
*
|
williamr@2
|
6 |
* Copyright (c) 1996,1997
|
williamr@2
|
7 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* Copyright (c) 1997
|
williamr@2
|
10 |
* Moscow Center for SPARC Technology
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Copyright (c) 1999
|
williamr@2
|
13 |
* Boris Fomitchev
|
williamr@2
|
14 |
*
|
williamr@2
|
15 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
16 |
* or implied. Any use is at your own risk.
|
williamr@2
|
17 |
*
|
williamr@2
|
18 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
19 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
20 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
21 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
22 |
* modified is included with the above copyright notice.
|
williamr@2
|
23 |
*
|
williamr@2
|
24 |
*/
|
williamr@2
|
25 |
|
williamr@2
|
26 |
/* NOTE: This is an internal header file, included by other STL headers.
|
williamr@2
|
27 |
* You should not attempt to use it directly.
|
williamr@2
|
28 |
*/
|
williamr@2
|
29 |
|
williamr@2
|
30 |
#ifndef _STLP_INTERNAL_HASH_SET_H
|
williamr@2
|
31 |
#define _STLP_INTERNAL_HASH_SET_H
|
williamr@2
|
32 |
|
williamr@2
|
33 |
#ifndef _STLP_INTERNAL_HASHTABLE_H
|
williamr@2
|
34 |
# include <stl/_hashtable.h>
|
williamr@2
|
35 |
#endif
|
williamr@2
|
36 |
|
williamr@2
|
37 |
# define hash_set __WORKAROUND_RENAME(hash_set)
|
williamr@2
|
38 |
# define hash_multiset __WORKAROUND_RENAME(hash_multiset)
|
williamr@2
|
39 |
|
williamr@2
|
40 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
41 |
|
williamr@2
|
42 |
template <class _Value, __DFL_TMPL_PARAM(_HashFcn,hash<_Value>),
|
williamr@2
|
43 |
__DFL_TMPL_PARAM(_EqualKey,equal_to<_Value>),
|
williamr@2
|
44 |
_STLP_DEFAULT_ALLOCATOR_SELECT(_Value) >
|
williamr@2
|
45 |
class hash_set
|
williamr@2
|
46 |
{
|
williamr@2
|
47 |
private:
|
williamr@2
|
48 |
typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>,
|
williamr@2
|
49 |
_EqualKey, _Alloc> _Ht;
|
williamr@2
|
50 |
typedef hash_set<_Value, _HashFcn, _EqualKey, _Alloc> _Self;
|
williamr@2
|
51 |
typedef typename _Ht::iterator _ht_iterator;
|
williamr@2
|
52 |
public:
|
williamr@2
|
53 |
typedef typename _Ht::key_type key_type;
|
williamr@2
|
54 |
typedef typename _Ht::value_type value_type;
|
williamr@2
|
55 |
typedef typename _Ht::hasher hasher;
|
williamr@2
|
56 |
typedef typename _Ht::key_equal key_equal;
|
williamr@2
|
57 |
|
williamr@2
|
58 |
typedef typename _Ht::size_type size_type;
|
williamr@2
|
59 |
typedef typename _Ht::difference_type difference_type;
|
williamr@2
|
60 |
typedef typename _Ht::pointer pointer;
|
williamr@2
|
61 |
typedef typename _Ht::const_pointer const_pointer;
|
williamr@2
|
62 |
typedef typename _Ht::reference reference;
|
williamr@2
|
63 |
typedef typename _Ht::const_reference const_reference;
|
williamr@2
|
64 |
|
williamr@2
|
65 |
// SunPro bug
|
williamr@2
|
66 |
typedef typename _Ht::const_iterator const_iterator;
|
williamr@2
|
67 |
typedef const_iterator iterator;
|
williamr@2
|
68 |
|
williamr@2
|
69 |
typedef typename _Ht::allocator_type allocator_type;
|
williamr@2
|
70 |
|
williamr@2
|
71 |
hasher hash_funct() const { return _M_ht.hash_funct(); }
|
williamr@2
|
72 |
key_equal key_eq() const { return _M_ht.key_eq(); }
|
williamr@2
|
73 |
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
|
williamr@2
|
74 |
|
williamr@2
|
75 |
private:
|
williamr@2
|
76 |
_Ht _M_ht;
|
williamr@2
|
77 |
|
williamr@2
|
78 |
public:
|
williamr@2
|
79 |
hash_set()
|
williamr@2
|
80 |
: _M_ht(100, hasher(), key_equal(), allocator_type()) {
|
williamr@2
|
81 |
_STLP_POP_IF_CHECK
|
williamr@2
|
82 |
}
|
williamr@2
|
83 |
|
williamr@2
|
84 |
# ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
85 |
hash_set(const _Self& __o) :
|
williamr@2
|
86 |
_M_ht(__o.size())
|
williamr@2
|
87 |
{
|
williamr@2
|
88 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
89 |
_M_ht = __o._M_ht;
|
williamr@2
|
90 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
91 |
}
|
williamr@2
|
92 |
# else
|
williamr@2
|
93 |
hash_set(const _Self& __o)
|
williamr@2
|
94 |
: _M_ht(__o._M_ht) {
|
williamr@2
|
95 |
}
|
williamr@2
|
96 |
# endif
|
williamr@2
|
97 |
explicit hash_set(size_type __n)
|
williamr@2
|
98 |
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {
|
williamr@2
|
99 |
_STLP_POP_IF_CHECK
|
williamr@2
|
100 |
}
|
williamr@2
|
101 |
hash_set(size_type __n, const hasher& __hf)
|
williamr@2
|
102 |
: _M_ht(__n, __hf, key_equal(), allocator_type()) {
|
williamr@2
|
103 |
_STLP_POP_IF_CHECK
|
williamr@2
|
104 |
}
|
williamr@2
|
105 |
hash_set(size_type __n, const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
106 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
107 |
: _M_ht(__n, __hf, __eql, __a) {
|
williamr@2
|
108 |
_STLP_POP_IF_CHECK
|
williamr@2
|
109 |
}
|
williamr@2
|
110 |
|
williamr@2
|
111 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
112 |
template <class _InputIterator>
|
williamr@2
|
113 |
hash_set(_InputIterator __f, _InputIterator __l)
|
williamr@2
|
114 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
115 |
{
|
williamr@2
|
116 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
117 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
118 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
119 |
}
|
williamr@2
|
120 |
template <class _InputIterator>
|
williamr@2
|
121 |
hash_set(_InputIterator __f, _InputIterator __l, size_type __n)
|
williamr@2
|
122 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
123 |
{
|
williamr@2
|
124 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
125 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
126 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
127 |
}
|
williamr@2
|
128 |
template <class _InputIterator>
|
williamr@2
|
129 |
hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
130 |
const hasher& __hf)
|
williamr@2
|
131 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
132 |
{
|
williamr@2
|
133 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
134 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
135 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
136 |
}
|
williamr@2
|
137 |
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
|
williamr@2
|
138 |
template <class _InputIterator>
|
williamr@2
|
139 |
hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
140 |
const hasher& __hf, const key_equal& __eql)
|
williamr@2
|
141 |
: _M_ht(__n, __hf, __eql, allocator_type())
|
williamr@2
|
142 |
{
|
williamr@2
|
143 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
144 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
145 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
146 |
}
|
williamr@2
|
147 |
# endif
|
williamr@2
|
148 |
template <class _InputIterator>
|
williamr@2
|
149 |
hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
150 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
151 |
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
|
williamr@2
|
152 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
153 |
{
|
williamr@2
|
154 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
155 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
156 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
157 |
}
|
williamr@2
|
158 |
#else
|
williamr@2
|
159 |
|
williamr@2
|
160 |
hash_set(const value_type* __f, const value_type* __l)
|
williamr@2
|
161 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
162 |
{
|
williamr@2
|
163 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
164 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
165 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
166 |
}
|
williamr@2
|
167 |
hash_set(const value_type* __f, const value_type* __l, size_type __n)
|
williamr@2
|
168 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
169 |
{
|
williamr@2
|
170 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
171 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
172 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
173 |
}
|
williamr@2
|
174 |
hash_set(const value_type* __f, const value_type* __l, size_type __n,
|
williamr@2
|
175 |
const hasher& __hf)
|
williamr@2
|
176 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
177 |
{
|
williamr@2
|
178 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
179 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
180 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
181 |
}
|
williamr@2
|
182 |
hash_set(const value_type* __f, const value_type* __l, size_type __n,
|
williamr@2
|
183 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
184 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
185 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
186 |
{
|
williamr@2
|
187 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
188 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
189 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
190 |
}
|
williamr@2
|
191 |
|
williamr@2
|
192 |
hash_set(const_iterator __f, const_iterator __l)
|
williamr@2
|
193 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
194 |
{
|
williamr@2
|
195 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
196 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
197 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
198 |
}
|
williamr@2
|
199 |
hash_set(const_iterator __f, const_iterator __l, size_type __n)
|
williamr@2
|
200 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
201 |
{
|
williamr@2
|
202 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
203 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
204 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
205 |
}
|
williamr@2
|
206 |
hash_set(const_iterator __f, const_iterator __l, size_type __n,
|
williamr@2
|
207 |
const hasher& __hf)
|
williamr@2
|
208 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
209 |
{
|
williamr@2
|
210 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
211 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
212 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
213 |
}
|
williamr@2
|
214 |
hash_set(const_iterator __f, const_iterator __l, size_type __n,
|
williamr@2
|
215 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
216 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
217 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
218 |
{
|
williamr@2
|
219 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
220 |
_M_ht.insert_unique(__f, __l);
|
williamr@2
|
221 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
222 |
}
|
williamr@2
|
223 |
#endif /*_STLP_MEMBER_TEMPLATES */
|
williamr@2
|
224 |
|
williamr@2
|
225 |
#ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
226 |
public:
|
williamr@2
|
227 |
static void* operator new (size_t __n, TLeave) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
228 |
static void* operator new (size_t __n) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
229 |
#endif
|
williamr@2
|
230 |
|
williamr@2
|
231 |
public:
|
williamr@2
|
232 |
size_type size() const { return _M_ht.size(); }
|
williamr@2
|
233 |
size_type max_size() const { return _M_ht.max_size(); }
|
williamr@2
|
234 |
bool empty() const { return _M_ht.empty(); }
|
williamr@2
|
235 |
void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
|
williamr@2
|
236 |
|
williamr@2
|
237 |
iterator begin() const { return _M_ht.begin(); }
|
williamr@2
|
238 |
iterator end() const { return _M_ht.end(); }
|
williamr@2
|
239 |
|
williamr@2
|
240 |
public:
|
williamr@2
|
241 |
pair<iterator, bool> insert(const value_type& __obj)
|
williamr@2
|
242 |
{
|
williamr@2
|
243 |
pair<_ht_iterator, bool> __p = _M_ht.insert_unique(__obj);
|
williamr@2
|
244 |
return pair<iterator,bool>(__REINTERPRET_CAST(const iterator&, __p.first), __p.second);
|
williamr@2
|
245 |
}
|
williamr@2
|
246 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
247 |
template <class _InputIterator>
|
williamr@2
|
248 |
void insert(_InputIterator __f, _InputIterator __l)
|
williamr@2
|
249 |
{ _M_ht.insert_unique(__f,__l); }
|
williamr@2
|
250 |
#else
|
williamr@2
|
251 |
void insert(const value_type* __f, const value_type* __l) {
|
williamr@2
|
252 |
_M_ht.insert_unique(__f,__l);
|
williamr@2
|
253 |
}
|
williamr@2
|
254 |
void insert(const_iterator __f, const_iterator __l)
|
williamr@2
|
255 |
{_M_ht.insert_unique(__f, __l); }
|
williamr@2
|
256 |
|
williamr@2
|
257 |
#endif /*_STLP_MEMBER_TEMPLATES */
|
williamr@2
|
258 |
pair<iterator, bool> insert_noresize(const value_type& __obj)
|
williamr@2
|
259 |
{
|
williamr@2
|
260 |
pair<_ht_iterator, bool> __p =
|
williamr@2
|
261 |
_M_ht.insert_unique_noresize(__obj);
|
williamr@2
|
262 |
return pair<iterator, bool>(__p.first, __p.second);
|
williamr@2
|
263 |
}
|
williamr@2
|
264 |
|
williamr@2
|
265 |
# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS )
|
williamr@2
|
266 |
template <class _KT>
|
williamr@2
|
267 |
iterator find(const _KT& __key) const { return _M_ht.find(__key); }
|
williamr@2
|
268 |
# else
|
williamr@2
|
269 |
iterator find(const key_type& __key) const { return _M_ht.find(__key); }
|
williamr@2
|
270 |
# endif
|
williamr@2
|
271 |
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
|
williamr@2
|
272 |
|
williamr@2
|
273 |
pair<iterator, iterator> equal_range(const key_type& __key) const
|
williamr@2
|
274 |
{ return _M_ht.equal_range(__key); }
|
williamr@2
|
275 |
|
williamr@2
|
276 |
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
|
williamr@2
|
277 |
void erase(iterator __it) { _M_ht.erase(__it); }
|
williamr@2
|
278 |
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
|
williamr@2
|
279 |
void clear() { _M_ht.clear(); }
|
williamr@2
|
280 |
|
williamr@2
|
281 |
public:
|
williamr@2
|
282 |
void resize(size_type __hint) { _M_ht.resize(__hint); }
|
williamr@2
|
283 |
size_type bucket_count() const { return _M_ht.bucket_count(); }
|
williamr@2
|
284 |
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
|
williamr@2
|
285 |
size_type elems_in_bucket(size_type __n) const
|
williamr@2
|
286 |
{ return _M_ht.elems_in_bucket(__n); }
|
williamr@2
|
287 |
|
williamr@2
|
288 |
static bool _STLP_CALL _M_equal (const _Self& __x, const _Self& __y) {
|
williamr@2
|
289 |
return _Ht::_M_equal(__x._M_ht,__y._M_ht);
|
williamr@2
|
290 |
}
|
williamr@2
|
291 |
|
williamr@2
|
292 |
};
|
williamr@2
|
293 |
|
williamr@2
|
294 |
template <class _Value, __DFL_TMPL_PARAM(_HashFcn,hash<_Value>),
|
williamr@2
|
295 |
__DFL_TMPL_PARAM(_EqualKey,equal_to<_Value>),
|
williamr@2
|
296 |
_STLP_DEFAULT_ALLOCATOR_SELECT(_Value) >
|
williamr@2
|
297 |
class hash_multiset
|
williamr@2
|
298 |
{
|
williamr@2
|
299 |
private:
|
williamr@2
|
300 |
typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>,
|
williamr@2
|
301 |
_EqualKey, _Alloc> _Ht;
|
williamr@2
|
302 |
typedef hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc> _Self;
|
williamr@2
|
303 |
|
williamr@2
|
304 |
public:
|
williamr@2
|
305 |
typedef typename _Ht::key_type key_type;
|
williamr@2
|
306 |
typedef typename _Ht::value_type value_type;
|
williamr@2
|
307 |
typedef typename _Ht::hasher hasher;
|
williamr@2
|
308 |
typedef typename _Ht::key_equal key_equal;
|
williamr@2
|
309 |
|
williamr@2
|
310 |
typedef typename _Ht::size_type size_type;
|
williamr@2
|
311 |
typedef typename _Ht::difference_type difference_type;
|
williamr@2
|
312 |
typedef typename _Ht::pointer pointer;
|
williamr@2
|
313 |
typedef typename _Ht::const_pointer const_pointer;
|
williamr@2
|
314 |
typedef typename _Ht::reference reference;
|
williamr@2
|
315 |
typedef typename _Ht::const_reference const_reference;
|
williamr@2
|
316 |
|
williamr@2
|
317 |
typedef typename _Ht::const_iterator const_iterator;
|
williamr@2
|
318 |
// SunPro bug
|
williamr@2
|
319 |
typedef const_iterator iterator;
|
williamr@2
|
320 |
|
williamr@2
|
321 |
typedef typename _Ht::allocator_type allocator_type;
|
williamr@2
|
322 |
|
williamr@2
|
323 |
hasher hash_funct() const { return _M_ht.hash_funct(); }
|
williamr@2
|
324 |
key_equal key_eq() const { return _M_ht.key_eq(); }
|
williamr@2
|
325 |
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
|
williamr@2
|
326 |
|
williamr@2
|
327 |
private:
|
williamr@2
|
328 |
_Ht _M_ht;
|
williamr@2
|
329 |
|
williamr@2
|
330 |
public:
|
williamr@2
|
331 |
hash_multiset()
|
williamr@2
|
332 |
: _M_ht(100, hasher(), key_equal(), allocator_type()) {
|
williamr@2
|
333 |
_STLP_POP_IF_CHECK
|
williamr@2
|
334 |
}
|
williamr@2
|
335 |
|
williamr@2
|
336 |
# ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
337 |
hash_multiset(const _Self& __o) :
|
williamr@2
|
338 |
_M_ht(__o.size())
|
williamr@2
|
339 |
{
|
williamr@2
|
340 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
341 |
_M_ht = __o._M_ht;
|
williamr@2
|
342 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
343 |
}
|
williamr@2
|
344 |
# else
|
williamr@2
|
345 |
hash_multiset(const _Self& __o)
|
williamr@2
|
346 |
: _M_ht(__o._M_ht) {
|
williamr@2
|
347 |
}
|
williamr@2
|
348 |
# endif
|
williamr@2
|
349 |
|
williamr@2
|
350 |
explicit hash_multiset(size_type __n)
|
williamr@2
|
351 |
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {
|
williamr@2
|
352 |
_STLP_POP_IF_CHECK
|
williamr@2
|
353 |
}
|
williamr@2
|
354 |
hash_multiset(size_type __n, const hasher& __hf)
|
williamr@2
|
355 |
: _M_ht(__n, __hf, key_equal(), allocator_type()) {
|
williamr@2
|
356 |
_STLP_POP_IF_CHECK
|
williamr@2
|
357 |
}
|
williamr@2
|
358 |
hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql)
|
williamr@2
|
359 |
: _M_ht(__n, __hf, __eql, allocator_type()) {
|
williamr@2
|
360 |
_STLP_POP_IF_CHECK
|
williamr@2
|
361 |
}
|
williamr@2
|
362 |
hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
363 |
const allocator_type& __a)
|
williamr@2
|
364 |
: _M_ht(__n, __hf, __eql, __a) {
|
williamr@2
|
365 |
_STLP_POP_IF_CHECK
|
williamr@2
|
366 |
}
|
williamr@2
|
367 |
|
williamr@2
|
368 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
369 |
template <class _InputIterator>
|
williamr@2
|
370 |
hash_multiset(_InputIterator __f, _InputIterator __l)
|
williamr@2
|
371 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
372 |
{
|
williamr@2
|
373 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
374 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
375 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
376 |
}
|
williamr@2
|
377 |
template <class _InputIterator>
|
williamr@2
|
378 |
hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n)
|
williamr@2
|
379 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
380 |
{
|
williamr@2
|
381 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
382 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
383 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
384 |
}
|
williamr@2
|
385 |
template <class _InputIterator>
|
williamr@2
|
386 |
hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
387 |
const hasher& __hf)
|
williamr@2
|
388 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
389 |
{
|
williamr@2
|
390 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
391 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
392 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
393 |
}
|
williamr@2
|
394 |
|
williamr@2
|
395 |
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
|
williamr@2
|
396 |
template <class _InputIterator>
|
williamr@2
|
397 |
hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
398 |
const hasher& __hf, const key_equal& __eql)
|
williamr@2
|
399 |
: _M_ht(__n, __hf, __eql, allocator_type())
|
williamr@2
|
400 |
{
|
williamr@2
|
401 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
402 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
403 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
404 |
}
|
williamr@2
|
405 |
# endif
|
williamr@2
|
406 |
template <class _InputIterator>
|
williamr@2
|
407 |
hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
|
williamr@2
|
408 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
409 |
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
|
williamr@2
|
410 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
411 |
{
|
williamr@2
|
412 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
413 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
414 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
415 |
}
|
williamr@2
|
416 |
#else
|
williamr@2
|
417 |
|
williamr@2
|
418 |
hash_multiset(const value_type* __f, const value_type* __l)
|
williamr@2
|
419 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
420 |
{
|
williamr@2
|
421 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
422 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
423 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
424 |
}
|
williamr@2
|
425 |
hash_multiset(const value_type* __f, const value_type* __l, size_type __n)
|
williamr@2
|
426 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
427 |
{
|
williamr@2
|
428 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
429 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
430 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
431 |
}
|
williamr@2
|
432 |
hash_multiset(const value_type* __f, const value_type* __l, size_type __n,
|
williamr@2
|
433 |
const hasher& __hf)
|
williamr@2
|
434 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
435 |
{
|
williamr@2
|
436 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
437 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
438 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
439 |
}
|
williamr@2
|
440 |
hash_multiset(const value_type* __f, const value_type* __l, size_type __n,
|
williamr@2
|
441 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
442 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
443 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
444 |
{
|
williamr@2
|
445 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
446 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
447 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
448 |
}
|
williamr@2
|
449 |
|
williamr@2
|
450 |
hash_multiset(const_iterator __f, const_iterator __l)
|
williamr@2
|
451 |
: _M_ht(100, hasher(), key_equal(), allocator_type())
|
williamr@2
|
452 |
{
|
williamr@2
|
453 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
454 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
455 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
456 |
}
|
williamr@2
|
457 |
hash_multiset(const_iterator __f, const_iterator __l, size_type __n)
|
williamr@2
|
458 |
: _M_ht(__n, hasher(), key_equal(), allocator_type())
|
williamr@2
|
459 |
{
|
williamr@2
|
460 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
461 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
462 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
463 |
}
|
williamr@2
|
464 |
hash_multiset(const_iterator __f, const_iterator __l, size_type __n,
|
williamr@2
|
465 |
const hasher& __hf)
|
williamr@2
|
466 |
: _M_ht(__n, __hf, key_equal(), allocator_type())
|
williamr@2
|
467 |
{
|
williamr@2
|
468 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
469 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
470 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
471 |
}
|
williamr@2
|
472 |
hash_multiset(const_iterator __f, const_iterator __l, size_type __n,
|
williamr@2
|
473 |
const hasher& __hf, const key_equal& __eql,
|
williamr@2
|
474 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
475 |
: _M_ht(__n, __hf, __eql, __a)
|
williamr@2
|
476 |
{
|
williamr@2
|
477 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
478 |
_M_ht.insert_equal(__f, __l);
|
williamr@2
|
479 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
480 |
}
|
williamr@2
|
481 |
#endif /*_STLP_MEMBER_TEMPLATES */
|
williamr@2
|
482 |
|
williamr@2
|
483 |
#ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
484 |
public:
|
williamr@2
|
485 |
static void* operator new (size_t __n, TLeave) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
486 |
static void* operator new (size_t __n) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
487 |
#endif
|
williamr@2
|
488 |
|
williamr@2
|
489 |
public:
|
williamr@2
|
490 |
size_type size() const { return _M_ht.size(); }
|
williamr@2
|
491 |
size_type max_size() const { return _M_ht.max_size(); }
|
williamr@2
|
492 |
bool empty() const { return _M_ht.empty(); }
|
williamr@2
|
493 |
void swap(_Self& hs) { _M_ht.swap(hs._M_ht); }
|
williamr@2
|
494 |
|
williamr@2
|
495 |
iterator begin() const { return _M_ht.begin(); }
|
williamr@2
|
496 |
iterator end() const { return _M_ht.end(); }
|
williamr@2
|
497 |
|
williamr@2
|
498 |
public:
|
williamr@2
|
499 |
iterator insert(const value_type& __obj)
|
williamr@2
|
500 |
{ return _M_ht.insert_equal(__obj); }
|
williamr@2
|
501 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
502 |
template <class _InputIterator>
|
williamr@2
|
503 |
void insert(_InputIterator __f, _InputIterator __l)
|
williamr@2
|
504 |
{ _M_ht.insert_equal(__f,__l); }
|
williamr@2
|
505 |
#else
|
williamr@2
|
506 |
void insert(const value_type* __f, const value_type* __l) {
|
williamr@2
|
507 |
_M_ht.insert_equal(__f,__l);
|
williamr@2
|
508 |
}
|
williamr@2
|
509 |
void insert(const_iterator __f, const_iterator __l)
|
williamr@2
|
510 |
{ _M_ht.insert_equal(__f, __l); }
|
williamr@2
|
511 |
#endif /*_STLP_MEMBER_TEMPLATES */
|
williamr@2
|
512 |
iterator insert_noresize(const value_type& __obj)
|
williamr@2
|
513 |
{ return _M_ht.insert_equal_noresize(__obj); }
|
williamr@2
|
514 |
|
williamr@2
|
515 |
# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS )
|
williamr@2
|
516 |
template <class _KT>
|
williamr@2
|
517 |
iterator find(const _KT& __key) const { return _M_ht.find(__key); }
|
williamr@2
|
518 |
# else
|
williamr@2
|
519 |
iterator find(const key_type& __key) const { return _M_ht.find(__key); }
|
williamr@2
|
520 |
# endif
|
williamr@2
|
521 |
|
williamr@2
|
522 |
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
|
williamr@2
|
523 |
|
williamr@2
|
524 |
pair<iterator, iterator> equal_range(const key_type& __key) const
|
williamr@2
|
525 |
{ return _M_ht.equal_range(__key); }
|
williamr@2
|
526 |
|
williamr@2
|
527 |
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
|
williamr@2
|
528 |
void erase(iterator __it) { _M_ht.erase(__it); }
|
williamr@2
|
529 |
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
|
williamr@2
|
530 |
void clear() { _M_ht.clear(); }
|
williamr@2
|
531 |
|
williamr@2
|
532 |
public:
|
williamr@2
|
533 |
void resize(size_type __hint) { _M_ht.resize(__hint); }
|
williamr@2
|
534 |
size_type bucket_count() const { return _M_ht.bucket_count(); }
|
williamr@2
|
535 |
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
|
williamr@2
|
536 |
size_type elems_in_bucket(size_type __n) const
|
williamr@2
|
537 |
{ return _M_ht.elems_in_bucket(__n); }
|
williamr@2
|
538 |
static bool _STLP_CALL _M_equal (const _Self& __x, const _Self& __y) {
|
williamr@2
|
539 |
return _Ht::_M_equal(__x._M_ht,__y._M_ht);
|
williamr@2
|
540 |
}
|
williamr@2
|
541 |
};
|
williamr@2
|
542 |
|
williamr@2
|
543 |
#define _STLP_TEMPLATE_HEADER template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
|
williamr@2
|
544 |
#define _STLP_TEMPLATE_CONTAINER hash_set<_Value,_HashFcn,_EqualKey,_Alloc>
|
williamr@2
|
545 |
|
williamr@2
|
546 |
#include <stl/_relops_hash_cont.h>
|
williamr@2
|
547 |
|
williamr@2
|
548 |
#undef _STLP_TEMPLATE_CONTAINER
|
williamr@2
|
549 |
#define _STLP_TEMPLATE_CONTAINER hash_multiset<_Value,_HashFcn,_EqualKey,_Alloc>
|
williamr@2
|
550 |
#include <stl/_relops_hash_cont.h>
|
williamr@2
|
551 |
|
williamr@2
|
552 |
#undef _STLP_TEMPLATE_CONTAINER
|
williamr@2
|
553 |
#undef _STLP_TEMPLATE_HEADER
|
williamr@2
|
554 |
|
williamr@2
|
555 |
// Specialization of insert_iterator so that it will work for hash_set
|
williamr@2
|
556 |
// and hash_multiset.
|
williamr@2
|
557 |
|
williamr@2
|
558 |
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
|
williamr@2
|
559 |
|
williamr@2
|
560 |
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
|
williamr@2
|
561 |
class insert_iterator<hash_set<_Value, _HashFcn, _EqualKey, _Alloc> > {
|
williamr@2
|
562 |
protected:
|
williamr@2
|
563 |
typedef hash_set<_Value, _HashFcn, _EqualKey, _Alloc> _Container;
|
williamr@2
|
564 |
_Container* container;
|
williamr@2
|
565 |
public:
|
williamr@2
|
566 |
typedef _Container container_type;
|
williamr@2
|
567 |
typedef output_iterator_tag iterator_category;
|
williamr@2
|
568 |
typedef void value_type;
|
williamr@2
|
569 |
typedef void difference_type;
|
williamr@2
|
570 |
typedef void pointer;
|
williamr@2
|
571 |
typedef void reference;
|
williamr@2
|
572 |
|
williamr@2
|
573 |
insert_iterator(_Container& __x) : container(&__x) {}
|
williamr@2
|
574 |
insert_iterator(_Container& __x, typename _Container::iterator)
|
williamr@2
|
575 |
: container(&__x) {}
|
williamr@2
|
576 |
insert_iterator<_Container>&
|
williamr@2
|
577 |
operator=(const typename _Container::value_type& __val) {
|
williamr@2
|
578 |
container->insert(__val);
|
williamr@2
|
579 |
return *this;
|
williamr@2
|
580 |
}
|
williamr@2
|
581 |
insert_iterator<_Container>& operator*() { return *this; }
|
williamr@2
|
582 |
insert_iterator<_Container>& operator++() { return *this; }
|
williamr@2
|
583 |
insert_iterator<_Container>& operator++(int) { return *this; }
|
williamr@2
|
584 |
};
|
williamr@2
|
585 |
|
williamr@2
|
586 |
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
|
williamr@2
|
587 |
class insert_iterator<hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc> > {
|
williamr@2
|
588 |
protected:
|
williamr@2
|
589 |
typedef hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc> _Container;
|
williamr@2
|
590 |
_Container* container;
|
williamr@2
|
591 |
typename _Container::iterator iter;
|
williamr@2
|
592 |
public:
|
williamr@2
|
593 |
typedef _Container container_type;
|
williamr@2
|
594 |
typedef output_iterator_tag iterator_category;
|
williamr@2
|
595 |
typedef void value_type;
|
williamr@2
|
596 |
typedef void difference_type;
|
williamr@2
|
597 |
typedef void pointer;
|
williamr@2
|
598 |
typedef void reference;
|
williamr@2
|
599 |
|
williamr@2
|
600 |
insert_iterator(_Container& __x) : container(&__x) {}
|
williamr@2
|
601 |
insert_iterator(_Container& __x, typename _Container::iterator)
|
williamr@2
|
602 |
: container(&__x) {}
|
williamr@2
|
603 |
insert_iterator<_Container>&
|
williamr@2
|
604 |
operator=(const typename _Container::value_type& __val) {
|
williamr@2
|
605 |
container->insert(__val);
|
williamr@2
|
606 |
return *this;
|
williamr@2
|
607 |
}
|
williamr@2
|
608 |
insert_iterator<_Container>& operator*() { return *this; }
|
williamr@2
|
609 |
insert_iterator<_Container>& operator++() { return *this; }
|
williamr@2
|
610 |
insert_iterator<_Container>& operator++(int) { return *this; }
|
williamr@2
|
611 |
};
|
williamr@2
|
612 |
|
williamr@2
|
613 |
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
|
williamr@2
|
614 |
_STLP_END_NAMESPACE
|
williamr@2
|
615 |
|
williamr@2
|
616 |
// do a cleanup
|
williamr@2
|
617 |
# undef hash_set
|
williamr@2
|
618 |
# undef hash_multiset
|
williamr@2
|
619 |
|
williamr@2
|
620 |
// provide a uniform way to access full funclionality
|
williamr@2
|
621 |
# define __hash_set__ __FULL_NAME(hash_set)
|
williamr@2
|
622 |
# define __hash_multiset__ __FULL_NAME(hash_multiset)
|
williamr@2
|
623 |
|
williamr@2
|
624 |
# if defined ( _STLP_USE_WRAPPER_FOR_ALLOC_PARAM )
|
williamr@2
|
625 |
# include <stl/wrappers/_hash_set.h>
|
williamr@2
|
626 |
# endif /* WRAPPER */
|
williamr@2
|
627 |
|
williamr@2
|
628 |
#endif /* _STLP_INTERNAL_HASH_SET_H */
|
williamr@2
|
629 |
|
williamr@2
|
630 |
// Local Variables:
|
williamr@2
|
631 |
// mode:C++
|
williamr@2
|
632 |
// End:
|
williamr@2
|
633 |
|