|
|
|
1 |
|
// unordered_set standard header |
2 |
|
#pragma once |
3 |
|
#ifndef _UNORDERED_SET_ |
4 |
|
#define _UNORDERED_SET_ |
5 |
|
#ifndef RC_INVOKED |
6 |
|
#include <xhash> |
7 |
|
|
8 |
|
#pragma pack(push,_CRT_PACKING) |
9 |
|
#pragma warning(push,3) |
10 |
|
|
11 |
|
_STD_BEGIN |
12 |
|
namespace tr1 { // TR1 additions |
13 |
|
|
14 |
|
// TEMPLATE CLASS _Uset_traits |
15 |
|
template<class _Kty, // key type (same as value type) |
16 |
|
class _Tr, // comparator predicate type |
17 |
|
class _Alloc, // actual allocator type (should be value allocator) |
18 |
|
bool _Mfl> // true if multiple equivalent keys are permitted |
19 |
|
class _Uset_traits |
20 |
|
: public _Container_base |
21 |
|
{ // traits required to make _Hash behave like a set |
22 |
|
public: |
23 |
|
typedef _Kty key_type; |
24 |
|
typedef _Kty value_type; |
25 |
|
typedef _Tr key_compare; |
26 |
|
|
27 |
|
typedef typename _Alloc::template rebind<value_type>::other |
28 |
|
allocator_type; |
29 |
|
|
30 |
|
typedef typename allocator_type::const_pointer _ITptr; |
31 |
|
typedef typename allocator_type::const_reference _IReft; |
32 |
|
|
33 |
|
enum |
34 |
|
{ // make multi parameter visible as an enum constant |
35 |
|
_Multi = _Mfl}; |
36 |
|
|
37 |
|
_Uset_traits() |
38 |
|
: comp() |
39 |
|
{ // construct with default comparator |
40 |
|
} |
41 |
|
|
42 |
|
_Uset_traits(const _Tr& _Traits) |
43 |
|
: comp(_Traits) |
44 |
|
{ // construct with specified comparator |
45 |
|
} |
46 |
|
|
47 |
|
typedef key_compare value_compare; |
48 |
|
|
49 |
|
static const _Kty& _Kfn(const value_type& _Val) |
50 |
|
{ // return entire value as key |
51 |
|
return (_Val); |
52 |
|
} |
53 |
|
|
54 |
|
_Tr comp; // the comparator predicate for keys |
55 |
|
}; |
284 |
|
_Mybase::insert(*_First); |
285 |
|
} |
286 |
|
|
287 |
|
template<class _Iter> |
288 |
|
unordered_multiset(_Iter _First, _Iter _Last, |
289 |
|
size_type _Buckets, const hasher& _Hasharg, |
290 |
|
const _Keyeq& _Keyeqarg) |
291 |
|
: _Mybase(key_compare(_Hasharg, _Keyeqarg), allocator_type()) |
292 |
|
{ // construct set from sequence, comparator, and allocator |
293 |
|
this->rehash(_Buckets); |
294 |
|
for (; _First != _Last; ++_First) |
295 |
|
_Mybase::insert(*_First); |
296 |
|
} |
297 |
|
|
298 |
|
template<class _Iter> |
299 |
|
unordered_multiset(_Iter _First, _Iter _Last, |
300 |
|
size_type _Buckets, const hasher& _Hasharg, |
301 |
|
const _Keyeq& _Keyeqarg, const allocator_type& _Al) |
302 |
|
: _Mybase(key_compare(_Hasharg, _Keyeqarg), _Al) |
303 |
|
{ // construct set from sequence, comparator, and allocator |
304 |
|
this->rehash(_Buckets); |
305 |
|
for (; _First != _Last; ++_First) |
306 |
|
_Mybase::insert(*_First); |
307 |
|
} |
308 |
|
|
309 |
|
hasher hash_function() const |
310 |
|
{ // return hasher object |
311 |
|
return (this->comp._Hashobj); |
312 |
|
} |
313 |
|
|
314 |
|
key_equal key_eq() const |
315 |
|
{ // return equality comparator object |
316 |
|
return (this->comp._Keyeqobj); |
317 |
|
} |
318 |
|
|
319 |
|
iterator insert(const value_type& _Val) |
320 |
|
{ // insert a key value |
321 |
|
return (_Mybase::insert(_Val).first); |
322 |
|
} |
323 |
|
|
324 |
|
iterator insert(const_iterator _Where, const value_type& _Val) |
325 |
|
{ // insert a key value, with hint |
326 |
|
return (_Mybase::insert(_Where, _Val)); |
327 |
|
} |
328 |
|
|
329 |
|
template<class _Iter> |
330 |
|
void insert(_Iter _First, _Iter _Last) |
331 |
|
{ // insert [_First, _Last), arbitrary iterators |
332 |
|
|
333 |
|
#if _HAS_ITERATOR_DEBUGGING |
334 |
|
_DEBUG_RANGE(_First, _Last); |
335 |
|
#endif /* _HAS_ITERATOR_DEBUGGING */ |
336 |
|
|
337 |
|
_Mybase::insert(_First, _Last); |
338 |
|
} |
339 |
|
}; |
340 |
|
|
341 |
|
template<class _Kty, |
342 |
|
class _Hasher, |
343 |
|
class _Keyeq, |
344 |
|
class _Alloc> |
345 |
|
void swap(unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Left, |
346 |
|
unordered_multiset<_Kty, _Hasher, _Keyeq, _Alloc>& _Right) |
347 |
|
{ // swap _Left and _Right unordered_multisets |
348 |
|
_Left.swap(_Right); |
349 |
|
} |
350 |
|
|
351 |
|
} // namespace tr1 |
352 |
|
|
353 |
|
// unordered_set implements a performant swap |
354 |
|
template<class _Kty, |
355 |
|
class _Hasher, |
356 |
|
class _Keyeq, |
357 |
|
class _Alloc> |
358 |
|
class _Move_operation_category<tr1::unordered_set<_Kty, _Hasher, |
359 |
|
_Keyeq, _Alloc> > |
360 |
|
{ |
361 |
|
public: |
362 |
|
typedef _Swap_move_tag _Move_cat; |
363 |
|
}; |
364 |
|
|
365 |
|
// unordered_multiset implements a performant swap |
366 |
|
template<class _Kty, |
367 |
|
class _Hasher, |
368 |
|
class _Keyeq, |
369 |
|
class _Alloc> |
370 |
|
class _Move_operation_category<tr1::unordered_multiset<_Kty, _Hasher, |
371 |
|
_Keyeq, _Alloc> > |
372 |
|
{ |
373 |
|
public: |
374 |
|
typedef _Swap_move_tag _Move_cat; |
375 |
|
}; |
376 |
|
_STD_END |
377 |
|
#pragma warning(pop) |
378 |
|
#pragma pack(pop) |
379 |
|
|
380 |
|
#endif /* RC_INVOKED */ |
381 |
|
#endif /* _UNORDERED_SET_ */ |
382 |
|
|
383 |
|
/* |
384 |
|
* Copyright (c) 1992-2008 by P.J. Plauger. ALL RIGHTS RESERVED. |
385 |
|
* Consult your license regarding permissions and restrictions. |
386 |
|
V5.05:0009 */ |
387 |
|
|
|
|
|