|
|
|
| 1 |
|
// hash_set standard header |
| 2 |
|
#pragma once |
| 3 |
|
#ifndef _HASH_SET_ |
| 4 |
|
#define _HASH_SET_ |
| 5 |
|
#ifndef RC_INVOKED |
| 6 |
|
#include <xhash> |
| 7 |
|
|
| 8 |
|
#ifdef _MSC_VER |
| 9 |
|
#pragma pack(push,_CRT_PACKING) |
| 10 |
|
#pragma warning(push,3) |
| 11 |
|
#endif /* _MSC_VER */ |
| 12 |
|
|
| 13 |
|
_STDEXT_BEGIN |
| 14 |
|
|
| 15 |
|
#if _HAS_ITERATOR_DEBUGGING |
| 16 |
|
using std::_Debug_message; |
| 17 |
|
#endif |
| 18 |
|
|
| 19 |
|
// TEMPLATE CLASS _Hset_traits |
| 20 |
|
template<class _Kty, // key type (same as value type) |
| 21 |
|
class _Tr, // comparator predicate type |
| 22 |
|
class _Alloc, // actual allocator type (should be value allocator) |
| 23 |
|
bool _Mfl> // true if multiple equivalent keys are permitted |
| 24 |
|
class _Hset_traits |
| 25 |
|
: public _STD _Container_base |
| 26 |
|
{ // traits required to make _Hash behave like a set |
| 27 |
|
public: |
| 28 |
|
typedef _Kty key_type; |
| 29 |
|
typedef _Kty value_type; |
| 30 |
|
typedef _Tr key_compare; |
| 31 |
|
typedef typename _Alloc::template rebind<value_type>::other |
| 32 |
|
allocator_type; |
| 33 |
|
|
| 34 |
|
typedef typename allocator_type::const_pointer _ITptr; |
| 35 |
|
typedef typename allocator_type::const_reference _IReft; |
| 36 |
|
|
| 37 |
|
enum |
| 38 |
|
{ // make multi parameter visible as an enum constant |
| 39 |
|
_Multi = _Mfl}; |
| 40 |
|
|
| 41 |
|
_Hset_traits() |
| 42 |
|
: comp() |
| 43 |
|
{ // construct with default comparator |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
_Hset_traits(const _Tr& _Traits) |
| 47 |
|
: comp(_Traits) |
| 48 |
|
{ // construct with specified comparator |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
typedef key_compare value_compare; |
| 52 |
|
|
| 53 |
|
static const _Kty& _Kfn(const value_type& _Val) |
| 54 |
|
{ // return entire value as key |
| 55 |
|
return (_Val); |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
_Tr comp; // the comparator predicate for keys |
| 59 |
|
}; |
| 60 |
|
|
| 61 |
|
// TEMPLATE CLASS hash_set |
| 62 |
|
template<class _Kty, |
| 63 |
|
class _Tr = hash_compare<_Kty, _STD less<_Kty> >, |
| 64 |
|
class _Alloc = _STD allocator<_Kty> > |
| 65 |
|
class hash_set |
| 66 |
|
: public _Hash<_Hset_traits<_Kty, _Tr, _Alloc, false> > |
| 67 |
|
{ // hash table of key values, unique keys |
| 68 |
|
public: |
| 69 |
|
typedef hash_set<_Kty, _Tr, _Alloc> _Myt; |
| 70 |
|
typedef _Hash<_Hset_traits<_Kty, _Tr, _Alloc, false> > _Mybase; |
| 71 |
|
typedef _Kty key_type; |
| 72 |
|
typedef _Tr key_compare; |
| 73 |
|
typedef typename _Mybase::value_compare value_compare; |
| 74 |
|
typedef typename _Mybase::allocator_type allocator_type; |
| 75 |
|
typedef typename _Mybase::size_type size_type; |
| 76 |
|
typedef typename _Mybase::difference_type difference_type; |
| 77 |
|
typedef typename _Mybase::pointer pointer; |
| 78 |
|
typedef typename _Mybase::const_pointer const_pointer; |
| 79 |
|
typedef typename _Mybase::reference reference; |
| 80 |
|
typedef typename _Mybase::const_reference const_reference; |
| 81 |
|
typedef typename _Mybase::iterator iterator; |
| 82 |
|
typedef typename _Mybase::const_iterator const_iterator; |
| 83 |
|
typedef typename _Mybase::reverse_iterator reverse_iterator; |
| 84 |
|
typedef typename _Mybase::const_reverse_iterator |
| 85 |
|
const_reverse_iterator; |
| 86 |
|
typedef typename _Mybase::value_type value_type; |
| 87 |
|
|
| 88 |
|
hash_set() |
| 89 |
|
: _Mybase(key_compare(), allocator_type()) |
| 90 |
|
{ // construct empty set from defaults |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
explicit hash_set(const key_compare& _Traits) |
| 94 |
|
: _Mybase(_Traits, allocator_type()) |
| 95 |
|
{ // construct empty set from comparator |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
hash_set(const key_compare& _Traits, const allocator_type& _Al) |
| 99 |
|
: _Mybase(_Traits, _Al) |
| 100 |
|
{ // construct empty set from comparator and allocator |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
template<class _Iter> |
| 104 |
|
hash_set(_Iter _First, _Iter _Last) |
| 105 |
|
: _Mybase(key_compare(), allocator_type()) |
| 106 |
|
{ // construct set from sequence, defaults |
| 107 |
|
_DEBUG_RANGE(_First, _Last); |
| 108 |
|
for (; _First != _Last; ++_First) |
| 109 |
|
this->insert(*_First); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
template<class _Iter> |
| 113 |
|
hash_set(_Iter _First, _Iter _Last, |
| 114 |
|
const key_compare& _Traits) |
| 115 |
|
: _Mybase(_Traits, allocator_type()) |
| 116 |
|
{ // construct set from sequence, comparator |
| 127 |
|
_DEBUG_RANGE(_First, _Last); |
| 128 |
|
for (; _First != _Last; ++_First) |
| 129 |
|
this->insert(*_First); |
| 130 |
|
} |
| 131 |
|
}; |
| 132 |
|
|
| 133 |
|
template<class _Kty, |
| 134 |
|
class _Tr, |
| 135 |
|
class _Alloc> inline |
| 136 |
|
void swap(_STDEXT hash_set<_Kty, _Tr, _Alloc>& _Left, |
| 137 |
|
_STDEXT hash_set<_Kty, _Tr, _Alloc>& _Right) |
| 138 |
|
{ // swap _Left and _Right hash_sets |
| 139 |
|
_Left.swap(_Right); |
| 140 |
|
} |
| 141 |
|
|
| 142 |
|
// TEMPLATE CLASS hash_multiset |
| 143 |
|
template<class _Kty, |
| 144 |
|
class _Tr = hash_compare<_Kty, _STD less<_Kty> >, |
| 145 |
|
class _Alloc = _STD allocator<_Kty> > |
| 146 |
|
class hash_multiset |
| 147 |
|
: public _Hash<_Hset_traits<_Kty, _Tr, _Alloc, true> > |
| 148 |
|
{ // hash table of key values, non-unique keys |
| 149 |
|
public: |
| 150 |
|
typedef hash_multiset<_Kty, _Tr, _Alloc> _Myt; |
| 151 |
|
typedef _Hash<_Hset_traits<_Kty, _Tr, _Alloc, true> > _Mybase; |
| 152 |
|
typedef _Kty key_type; |
| 153 |
|
typedef _Tr key_compare; |
| 154 |
|
typedef typename _Mybase::value_compare value_compare; |
| 155 |
|
typedef typename _Mybase::allocator_type allocator_type; |
| 156 |
|
typedef typename _Mybase::size_type size_type; |
| 157 |
|
typedef typename _Mybase::difference_type difference_type; |
| 158 |
|
typedef typename _Mybase::pointer pointer; |
| 159 |
|
typedef typename _Mybase::const_pointer const_pointer; |
| 160 |
|
typedef typename _Mybase::reference reference; |
| 161 |
|
typedef typename _Mybase::const_reference const_reference; |
| 162 |
|
typedef typename _Mybase::iterator iterator; |
| 163 |
|
typedef typename _Mybase::const_iterator const_iterator; |
| 164 |
|
typedef typename _Mybase::reverse_iterator reverse_iterator; |
| 165 |
|
typedef typename _Mybase::const_reverse_iterator |
| 166 |
|
const_reverse_iterator; |
| 167 |
|
typedef typename _Mybase::value_type value_type; |
| 168 |
|
|
| 169 |
|
hash_multiset() |
| 170 |
|
: _Mybase(key_compare(), allocator_type()) |
| 171 |
|
{ // construct empty set from defaults |
| 172 |
|
} |
| 173 |
|
|
| 174 |
|
explicit hash_multiset(const key_compare& _Traits) |
| 175 |
|
: _Mybase(_Traits, allocator_type()) |
| 176 |
|
{ // construct empty set from comparator |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
hash_multiset(const key_compare& _Traits, |
| 180 |
|
const allocator_type& _Al) |
| 181 |
|
: _Mybase(_Traits, _Al) |
| 182 |
|
{ // construct empty set from comparator and allocator |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
template<class _Iter> |
| 186 |
|
hash_multiset(_Iter _First, _Iter _Last) |
| 187 |
|
: _Mybase(key_compare(), allocator_type()) |
| 188 |
|
{ // construct from sequence, defaults |
| 189 |
|
_DEBUG_RANGE(_First, _Last); |
| 190 |
|
for (; _First != _Last; ++_First) |
| 191 |
|
this->insert(*_First); |
| 192 |
|
} |
| 193 |
|
|
| 194 |
|
template<class _Iter> |
| 195 |
|
hash_multiset(_Iter _First, _Iter _Last, |
| 196 |
|
const key_compare& _Traits) |
| 197 |
|
: _Mybase(_Traits, allocator_type()) |
| 198 |
|
{ // construct from sequence, comparator |
| 199 |
|
_DEBUG_RANGE(_First, _Last); |
| 200 |
|
for (; _First != _Last; ++_First) |
| 201 |
|
this->insert(*_First); |
| 202 |
|
} |
| 203 |
|
|
| 204 |
|
template<class _Iter> |
| 205 |
|
hash_multiset(_Iter _First, _Iter _Last, |
| 206 |
|
const key_compare& _Traits, const allocator_type& _Al) |
| 207 |
|
: _Mybase(_Traits, _Al) |
| 208 |
|
{ // construct from sequence, comparator, and allocator |
| 209 |
|
_DEBUG_RANGE(_First, _Last); |
| 210 |
|
for (; _First != _Last; ++_First) |
| 211 |
|
this->insert(*_First); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
iterator insert(const value_type& _Val) |
| 215 |
|
{ // insert a key value |
| 216 |
|
return (_Mybase::insert(_Val).first); |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
iterator insert(const_iterator _Where, const value_type& _Val) |
| 220 |
|
{ // insert a key value, with hint |
| 221 |
|
return (_Mybase::insert(_Where, _Val)); |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
template<class _Iter> |
| 225 |
|
void insert(_Iter _First, _Iter _Last) |
| 226 |
|
{ // insert [_First, _Last), arbitrary iterators |
| 227 |
|
|
| 228 |
|
#if _HAS_ITERATOR_DEBUGGING |
| 229 |
|
_DEBUG_RANGE(_First, _Last); |
| 230 |
|
#endif /* _HAS_ITERATOR_DEBUGGING */ |
| 231 |
|
|
| 232 |
|
this->_Mybase::insert(_First, _Last); |
| 233 |
|
} |
| 234 |
|
}; |
| 235 |
|
|
| 236 |
|
template<class _Kty, |
| 237 |
|
class _Tr, |
| 238 |
|
class _Alloc> inline |
| 239 |
|
void swap(_STDEXT hash_multiset<_Kty, _Tr, _Alloc>& _Left, |
| 240 |
|
_STDEXT hash_multiset<_Kty, _Tr, _Alloc>& _Right) |
| 241 |
|
{ // swap _Left and _Right hash_multisets |
| 242 |
|
_Left.swap(_Right); |
| 243 |
|
} |
| 244 |
|
|
| 245 |
|
_STDEXT_END |
| 246 |
|
|
| 247 |
|
_STD_BEGIN |
| 248 |
|
// _STDEXT hash_set implements a performant swap |
| 249 |
|
template<class _Kty, |
| 250 |
|
class _Tr, |
| 251 |
|
class _Alloc> |
| 252 |
|
class _Move_operation_category<_STDEXT hash_set<_Kty, _Tr, _Alloc> > |
| 253 |
|
{ |
| 254 |
|
public: |
| 255 |
|
typedef _Swap_move_tag _Move_cat; |
| 256 |
|
}; |
| 257 |
|
|
| 258 |
|
// _STDEXT hash_multiset implements a performant swap |
| 259 |
|
template<class _Kty, |
| 260 |
|
class _Tr, |
| 261 |
|
class _Alloc> |
| 262 |
|
class _Move_operation_category<_STDEXT hash_multiset<_Kty, _Tr, _Alloc> > |
| 263 |
|
{ |
| 264 |
|
public: |
| 265 |
|
typedef _Swap_move_tag _Move_cat; |
| 266 |
|
}; |
| 267 |
|
_STD_END |
| 268 |
|
|
| 269 |
|
#ifdef _MSC_VER |
| 270 |
|
#pragma warning(pop) |
| 271 |
|
#pragma pack(pop) |
| 272 |
|
#endif /* _MSC_VER */ |
| 273 |
|
|
| 274 |
|
#endif /* RC_INVOKED */ |
| 275 |
|
#endif /* _HASH_SET_ */ |
| 276 |
|
|
| 277 |
|
/* |
| 278 |
|
* Copyright (c) 1992-2008 by P.J. Plauger. ALL RIGHTS RESERVED. |
| 279 |
|
* Consult your license regarding permissions and restrictions. |
| 280 |
|
V5.05:0009 */ |
| 281 |
|
|
| 282 |
|
|
| 283 |
|
|
|
|
|