|
|
|
1 |
|
// hash_map stl/clr header |
2 |
|
#ifndef _CLI_HASH_MAP_ |
3 |
|
#define _CLI_HASH_MAP_ |
4 |
|
#include <cliext/xhash> |
5 |
|
#include <cliext/utility> |
6 |
|
|
7 |
|
namespace cliext { |
8 |
|
namespace impl { |
9 |
|
// |
10 |
|
// TEMPLATE CLASS hash_map_traits |
11 |
|
// |
12 |
|
template<typename _Key_t, // key type |
13 |
|
typename _Mapped_t, // mapped type |
14 |
|
bool _Mflag> // true if multiple equivalent keys are permitted |
15 |
|
ref class hash_map_traits |
16 |
|
{ // traits required to make hash table behave like a map |
17 |
|
public: |
18 |
|
typedef hash_map_traits<_Key_t, _Mapped_t, _Mflag> _Mytype_t; |
19 |
|
|
20 |
|
typedef _Key_t key_type; |
21 |
|
typedef _Mapped_t mapped_type; |
22 |
|
typedef _STLCLR GenericPair<_Key_t, _Mapped_t>^ value_type; |
23 |
|
typedef _STLCLR BinaryDelegate<key_type, key_type, bool> |
24 |
|
key_compare; |
25 |
|
typedef _STLCLR BinaryDelegate<value_type, value_type, bool> |
26 |
|
value_compare; |
27 |
|
typedef _STLCLR UnaryDelegate<key_type, int> hasher; |
28 |
|
|
29 |
|
typedef _Key_t generic_key; |
30 |
|
typedef _Mapped_t generic_mapped; |
31 |
|
|
32 |
|
hash_map_traits() |
33 |
|
: comp(gcnew key_compare(&_Hash_key_compare)), |
34 |
|
hash_fun(gcnew hasher(&_Hasher)), |
35 |
|
_Multi(_Mflag) |
36 |
|
{ // construct with default comparator and hash function |
37 |
|
} |
38 |
|
|
39 |
|
hash_map_traits(key_compare^ _Pred) |
40 |
|
: comp(_Pred), |
41 |
|
hash_fun(gcnew hasher(&_Hasher)), |
42 |
|
_Multi(_Mflag) |
43 |
|
{ // construct with specified comparator and default hash function |
44 |
|
} |
45 |
|
|
46 |
|
hash_map_traits(key_compare^ _Pred, hasher^ _Hashfn) |
47 |
|
: comp(_Pred), hash_fun(_Hashfn), |
48 |
|
_Multi(_Mflag) |
49 |
|
{ // construct with specified comparator and default hash function |
50 |
|
} |
51 |
|
|
52 |
|
key_compare^ key_comp() |
53 |
|
{ // return object for comparing keys |
2423 |
|
|
2424 |
|
hash_multimap(_Myenum_it^ _Right, |
2425 |
|
key_compare^ _Pred) |
2426 |
|
: _Mybase_t(_Pred) |
2427 |
|
{ // construct map from enumeration, comparator |
2428 |
|
for each (value_type _Val in _Right) |
2429 |
|
insert(_Val); |
2430 |
|
} |
2431 |
|
|
2432 |
|
hash_multimap(_Myenum_it^ _Right, |
2433 |
|
key_compare^ _Pred, hasher^ _Hasher) |
2434 |
|
: _Mybase_t(_Pred, _Hasher) |
2435 |
|
{ // construct map from enumeration, compare and hash |
2436 |
|
for each (value_type _Val in _Right) |
2437 |
|
insert(_Val); |
2438 |
|
} |
2439 |
|
|
2440 |
|
// mutators |
2441 |
|
void swap(hash_multimap% _Right) |
2442 |
|
{ // exchange contents with _Right |
2443 |
|
_Mybase_t::swap(_Right); |
2444 |
|
} |
2445 |
|
|
2446 |
|
// interfaces |
2447 |
|
public: |
2448 |
|
virtual System::Object^ Clone() override |
2449 |
|
{ // clone the vector |
2450 |
|
return (gcnew _Mytype_t(*this)); |
2451 |
|
} |
2452 |
|
}; |
2453 |
|
|
2454 |
|
// |
2455 |
|
// TEMPLATE FUNCTION swap |
2456 |
|
// |
2457 |
|
template<typename _Key_t, |
2458 |
|
typename _Mapped_t> inline |
2459 |
|
void swap(cliext::hash_multimap<_Key_t, _Mapped_t>% _Left, |
2460 |
|
cliext::hash_multimap<_Key_t, _Mapped_t>% _Right) |
2461 |
|
{ // swap two hash_multimaps |
2462 |
|
_Left.swap(_Right); |
2463 |
|
} |
2464 |
|
} // namespace cliext |
2465 |
|
#endif // _CLI_HASH_MAP_ |
2466 |
|
|
2467 |
|
/* |
2468 |
|
* Copyright (c) 2004-2007 by Dinkumware, Ltd. ALL RIGHTS RESERVED. |
2469 |
|
* Consult your license regarding permissions and restrictions. |
2470 |
|
V5.03:0009 */ |
2471 |
|
|
|
|
|