1 // hash_map standard header
2 #pragma once
3 #ifndef _HASH_MAP_
4 #define _HASH_MAP_
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 _Hmap_traits
20 template<class _Kty,    // key type
21     class _Ty,    // mapped type
22     class _Tr,    // comparator predicate type
23     class _Alloc,    // actual allocator type (should be value allocator)
24     bool _Mfl>    // true if multiple equivalent keys are permitted
25     class _Hmap_traits
26         : public _STD _Container_base
27     {    // traits required to make _Hash behave like a map
28 public:
29     typedef _Kty key_type;
30     typedef _STD pair<const _Kty, _Ty> value_type;
31     typedef _Tr key_compare;
32     typedef typename _Alloc::template rebind<value_type>::other
33         allocator_type;
34
35      typedef typename allocator_type::pointer _ITptr;
36     typedef typename allocator_type::reference _IReft;
37
38     enum
39         {    // make multi parameter visible as an enum constant
40         _Multi = _Mfl};
41
42     _Hmap_traits()
43         : comp()
44         {    // construct with default comparator
45         }
46
47     _Hmap_traits(const _Tr& _Traits)
48         : comp(_Traits)
49         {    // construct with specified comparator
50         }
51
52     class value_compare
53         : public _STD binary_function<value_type, value_type, bool>
54         {    // functor for comparing two element values
55         friend class _Hmap_traits<_Kty, _Ty, _Tr, _Alloc, _Mfl>;
56
57     public:
58         bool operator()(const value_type& _Left,
59             const value_type& _Right) const
60             {    // test if _Left precedes _Right by comparing just keys
61             return (comp(_Left.first, _Right.first));
62             }
63
64         value_compare(const key_compare& _Traits)
65             : comp(_Traits)
66             {    // construct with specified predicate
67             }
68
69     protected:
70         key_compare comp;    // the comparator predicate for keys
71         };
72
73     static const _Kty& _Kfn(const value_type& _Val)
74         {    // extract key from element value
75         return (_Val.first);
76         }
77
78     _Tr comp;    // the comparator predicate for keys
79     };
80
81         // TEMPLATE CLASS hash_map
82 template<class _Kty,
83     class _Ty,
84     class _Tr = hash_compare<_Kty, _STD less<_Kty> >,
85     class _Alloc = _STD allocator< _STD pair<const _Kty, _Ty> > >
86     class hash_map
87         : public _Hash<_Hmap_traits<_Kty, _Ty, _Tr, _Alloc, false> >
88     {    // hash table of {key, mapped} values, unique keys
89 public:
90     typedef hash_map<_Kty, _Ty, _Tr, _Alloc> _Myt;
91     typedef _Hash<_Hmap_traits<_Kty, _Ty, _Tr, _Alloc, false> > _Mybase;
92     typedef _Kty key_type;
93     typedef _Ty mapped_type;
94     typedef _Ty referent_type;
95     typedef _Tr key_compare;
96     typedef typename _Mybase::value_compare value_compare;
97     typedef typename _Mybase::allocator_type allocator_type;
98     typedef typename _Mybase::size_type size_type;
99     typedef typename _Mybase::difference_type difference_type;
100     typedef typename _Mybase::pointer pointer;
101     typedef typename _Mybase::const_pointer const_pointer;
102     typedef typename _Mybase::reference reference;
103     typedef typename _Mybase::const_reference const_reference;
104     typedef typename _Mybase::iterator iterator;
105     typedef typename _Mybase::const_iterator const_iterator;
106     typedef typename _Mybase::reverse_iterator reverse_iterator;
107     typedef typename _Mybase::const_reverse_iterator
108         const_reverse_iterator;
109     typedef typename _Mybase::value_type value_type;
110
111     hash_map()
112         : _Mybase(key_compare(), allocator_type())
113         {    // construct empty map from defaults
114         }
115
116     explicit hash_map(const key_compare& _Traits)
117         : _Mybase(_Traits, allocator_type())
118         {    // construct empty map from comparator
119         }
120
121     hash_map(const key_compare& _Traits, const allocator_type& _Al)
122         : _Mybase(_Traits, _Al)
123         {    // construct empty map from comparator and allocator
124         }
125
126     template<class _Iter>
127         hash_map(_Iter _First, _Iter _Last)
128         : _Mybase(key_compare(), allocator_type())
129         {    // construct map from sequence, defaults
130         _DEBUG_RANGE(_First, _Last);
131         for (; _First != _Last; ++_First)
132             this->insert(*_First);
133         }
134
Lines 135 ... 144 are skipped.
145     template<class _Iter>
146         hash_map(_Iter _First, _Iter _Last,
147             const key_compare& _Traits,
148             const allocator_type& _Al)
149         : _Mybase(_Traits, _Al)
150         {    // construct map from sequence, comparator, and allocator
151         _DEBUG_RANGE(_First, _Last);
152         for (; _First != _Last; ++_First)
153             this->insert(*_First);
154         }
155
156     mapped_type& operator[](const key_type& _Keyval)
157         {    // find element matching _Keyval or insert with default mapped
158         iterator _Where = this->lower_bound(_Keyval);
159         if (_Where == this->end())
160             _Where = this->insert(value_type(_Keyval, mapped_type())).first;
161         return ((*_Where).second);
162         }
163     };
164
165 template<class _Kty,
166     class _Ty,
167     class _Tr,
168     class _Alloc> inline
169     void swap(_STDEXT hash_map<_Kty, _Ty, _Tr, _Alloc>& _Left,
170         _STDEXT hash_map<_Kty, _Ty, _Tr, _Alloc>& _Right)
171     {    // swap _Left and _Right hash_maps
172     _Left.swap(_Right);
173     }
174
175         // TEMPLATE CLASS hash_multimap
176 template<class _Kty,
177     class _Ty,
178     class _Tr = hash_compare<_Kty, _STD less<_Kty> >,
179     class _Alloc = _STD allocator< _STD pair<const _Kty, _Ty> > >
180     class hash_multimap
181         : public _Hash<_Hmap_traits<_Kty, _Ty, _Tr, _Alloc, true> >
182     {    // hash table of {key, mapped} values, non-unique keys
183 public:
184     typedef hash_multimap<_Kty, _Ty, _Tr, _Alloc> _Myt;
185     typedef _Hash<_Hmap_traits<_Kty, _Ty, _Tr, _Alloc, true> > _Mybase;
186     typedef _Kty key_type;
187     typedef _Ty mapped_type;
188     typedef _Ty referent_type;    // old name, magically gone
189     typedef _Tr key_compare;
190     typedef typename _Mybase::value_compare value_compare;
191     typedef typename _Mybase::allocator_type allocator_type;
192     typedef typename _Mybase::size_type size_type;
193     typedef typename _Mybase::difference_type difference_type;
194     typedef typename _Mybase::pointer pointer;
195     typedef typename _Mybase::const_pointer const_pointer;
196     typedef typename _Mybase::reference reference;
197     typedef typename _Mybase::const_reference const_reference;
198     typedef typename _Mybase::iterator iterator;
199     typedef typename _Mybase::const_iterator const_iterator;
200     typedef typename _Mybase::reverse_iterator reverse_iterator;
201     typedef typename _Mybase::const_reverse_iterator
202         const_reverse_iterator;
203     typedef typename _Mybase::value_type value_type;
204
205     hash_multimap()
206         : _Mybase(key_compare(), allocator_type())
207         {    // construct empty map from defaults
208         }
209
210     explicit hash_multimap(const key_compare& _Traits)
211         : _Mybase(_Traits, allocator_type())
212         {    // construct empty map from comparator
213         }
214
215     hash_multimap(const key_compare& _Traits,
216         const allocator_type& _Al)
217         : _Mybase(_Traits, _Al)
218         {    // construct empty map from comparator and allocator
219         }
220
221     template<class _Iter>
222         hash_multimap(_Iter _First, _Iter _Last)
223         : _Mybase(key_compare(), allocator_type())
224         {    // construct map from sequence, defaults
225         _DEBUG_RANGE(_First, _Last);
226         for (; _First != _Last; ++_First)
227             this->insert(*_First);
228         }
229
230     template<class _Iter>
231         hash_multimap(_Iter _First, _Iter _Last,
232             const key_compare& _Traits)
233         : _Mybase(_Traits, allocator_type())
234         {    // construct map from sequence, comparator
235         _DEBUG_RANGE(_First, _Last);
236         for (; _First != _Last; ++_First)
237             this->insert(*_First);
238         }
239
240     template<class _Iter>
241         hash_multimap(_Iter _First, _Iter _Last,
242             const key_compare& _Traits,
243             const allocator_type& _Al)
244         : _Mybase(_Traits, _Al)
245         {    // construct map from sequence, comparator, and allocator
246         _DEBUG_RANGE(_First, _Last);
247         for (; _First != _Last; ++_First)
248             this->insert(*_First);
249         }
250
251     iterator insert(const value_type& _Val)
252         {    // insert a {key, mapped} value
253         return (_Mybase::insert(_Val).first);
254         }
255
256     iterator insert(const_iterator _Where, const value_type& _Val)
257         {    // insert a {key, mapped} value, with hint
258         return (_Mybase::insert(_Where, _Val));
259         }
260
261     template<class _Iter>
262         void insert(_Iter _First, _Iter _Last)
263         {    // insert [_First, _Last), arbitrary iterators
264  #if _HAS_ITERATOR_DEBUGGING
265         _DEBUG_RANGE(_First, _Last);
266  #endif /* _HAS_ITERATOR_DEBUGGING */
267         this->_Mybase::insert(_First, _Last);
268         }
269     };
270
271 template<class _Kty,
272     class _Ty,
273     class _Tr,
274     class _Alloc> inline
275     void swap(_STDEXT hash_multimap<_Kty, _Ty, _Tr, _Alloc>& _Left,
276         _STDEXT hash_multimap<_Kty, _Ty, _Tr, _Alloc>& _Right)
277     {    // swap _Left and _Right hash_multimaps
278     _Left.swap(_Right);
279     }
280
281 _STDEXT_END
282
283 _STD_BEGIN
284     // _STDEXT hash_map implements a performant swap
285 template<class _Kty,
286     class _Ty,
287     class _Tr,
288     class _Alloc>
289     class _Move_operation_category<_STDEXT hash_map<_Kty, _Ty,
290         _Tr, _Alloc> >
291     {
292 public:
293     typedef _Swap_move_tag _Move_cat;
294     };
295
296     // _STDEXT hash_multimap implements a performant swap
297 template<class _Kty,
298     class _Ty,
299     class _Tr,
300     class _Alloc>
301     class _Move_operation_category<_STDEXT hash_multimap<_Kty, _Ty,
302         _Tr, _Alloc> >
303     {
304 public:
305     typedef _Swap_move_tag _Move_cat;
306     };
307 _STD_END
308
309 #ifdef _MSC_VER
310  #pragma warning(pop)
311  #pragma pack(pop)
312 #endif  /* _MSC_VER */
313
314 #endif /* RC_INVOKED */
315 #endif /* _HASH_MAP_ */
316
317 /*
318  * Copyright (c) 1992-2008 by P.J. Plauger.  ALL RIGHTS RESERVED.
319  * Consult your license regarding permissions and restrictions.
320  V5.05:0009 */
321
322
323