forked from mutouyun/nixy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_map.h
214 lines (179 loc) · 7.09 KB
/
hash_map.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
The Nixy Library
Code covered by the MIT License
Author: mutouyun (http://darkc.at)
*/
#pragma once
#include "nixycore/general/general.h"
#ifdef NX_SP_CXX11_UNORDERED_MAP
#include "nixycore/memory/default_alloc.h"
#include "nixycore/utility/rvalue.h"
#include <unordered_map> // std::unordered_map
//////////////////////////////////////////////////////////////////////////
NX_BEG
//////////////////////////////////////////////////////////////////////////
#ifdef NX_SP_CXX11_ALIAS
template <typename KeyT, typename TypeT, class HashT = std::hash<KeyT>
, class PredT = std::equal_to<KeyT>
, class AllocT = NX_DEFAULT_ALLOC>
using hash_map = std::unordered_map<KeyT, TypeT, HashT, PredT,
typename AllocT::template std_allocator<std::pair<const KeyT, TypeT> >::type_t>;
template <typename KeyT, typename TypeT, class HashT = std::hash<KeyT>
, class PredT = std::equal_to<KeyT>
, class AllocT = NX_DEFAULT_ALLOC>
using hash_multimap = std::unordered_multimap<KeyT, TypeT, HashT, PredT,
typename AllocT::template std_allocator<std::pair<const KeyT, TypeT> >::type_t>;
#else /*NX_SP_CXX11_ALIAS*/
template <typename KeyT, typename TypeT, class HashT = std::hash<KeyT>
, class PredT = std::equal_to<KeyT>
, class AllocT = NX_DEFAULT_ALLOC>
class hash_map : public std::unordered_map<KeyT, TypeT, HashT, PredT,
typename AllocT::template std_allocator<std::pair<const KeyT, TypeT> >::type_t>
{
typedef std::unordered_map<KeyT, TypeT, HashT, PredT,
typename AllocT::template std_allocator<std::pair<const KeyT, TypeT> >::type_t> base_t;
public:
#ifdef NX_SP_CXX11_INHERITING
using base_t::unordered_map;
#else /*NX_SP_CXX11_INHERITING*/
hash_map(void)
: base_t()
{}
explicit hash_map(const typename base_t::allocator_type& a)
: base_t(a)
{}
explicit hash_map(typename base_t::size_type n,
const typename base_t::hasher& hf = typename base_t::hasher(),
const typename base_t::key_equal& eql = typename base_t::key_equal(),
const typename base_t::allocator_type& a = typename base_t::allocator_type())
: base_t(n, hf, eql, a)
{}
template <typename IteratorT>
hash_map(IteratorT f, IteratorT l)
: base_t(f, l)
{}
template <typename IteratorT>
hash_map(IteratorT f, IteratorT l,
typename base_t::size_type n,
const typename base_t::hasher& hf = typename base_t::hasher(),
const typename base_t::key_equal& eql = typename base_t::key_equal(),
const typename base_t::allocator_type& a = typename base_t::allocator_type())
: base_t(f, l, n, hf, eql, a)
{}
hash_map(const hash_map& rhs)
: base_t(rhs)
{}
hash_map(nx_rref(hash_map, true) rhs)
: base_t()
{
base_t::swap(moved(rhs));
}
#endif/*NX_SP_CXX11_INHERITING*/
hash_map& operator=(hash_map rhs)
{
rhs.swap(*this);
return (*this);
}
};
template <typename KeyT, typename TypeT, class HashT = std::hash<KeyT>
, class PredT = std::equal_to<KeyT>
, class AllocT = NX_DEFAULT_ALLOC>
class hash_multimap : public std::unordered_multimap<KeyT, TypeT, HashT, PredT,
typename AllocT::template std_allocator<std::pair<const KeyT, TypeT> >::type_t>
{
typedef std::unordered_multimap<KeyT, TypeT, HashT, PredT,
typename AllocT::template std_allocator<std::pair<const KeyT, TypeT> >::type_t> base_t;
public:
#ifdef NX_SP_CXX11_INHERITING
using base_t::unordered_multimap;
#else /*NX_SP_CXX11_INHERITING*/
hash_multimap(void)
: base_t()
{}
explicit hash_multimap(const typename base_t::allocator_type& a)
: base_t(a)
{}
explicit hash_multimap(typename base_t::size_type n,
const typename base_t::hasher& hf = typename base_t::hasher(),
const typename base_t::key_equal& eql = typename base_t::key_equal(),
const typename base_t::allocator_type& a = typename base_t::allocator_type())
: base_t(n, hf, eql, a)
{}
template <typename IteratorT>
hash_multimap(IteratorT f, IteratorT l)
: base_t(f, l)
{}
template <typename IteratorT>
hash_multimap(IteratorT f, IteratorT l,
typename base_t::size_type n,
const typename base_t::hasher& hf = typename base_t::hasher(),
const typename base_t::key_equal& eql = typename base_t::key_equal(),
const typename base_t::allocator_type& a = typename base_t::allocator_type())
: base_t(f, l, n, hf, eql, a)
{}
hash_multimap(const hash_multimap& rhs)
: base_t(rhs)
{}
hash_multimap(nx_rref(hash_multimap, true) rhs)
: base_t()
{
base_t::swap(moved(rhs));
}
#endif/*NX_SP_CXX11_INHERITING*/
hash_multimap& operator=(hash_multimap rhs)
{
rhs.swap(*this);
return (*this);
}
};
/*
Special swap algorithm
*/
template <typename K, typename T, class H, class P, class A>
inline void swap(hash_map<K, T, H, P, A>& x, hash_map<K, T, H, P, A>& y)
{
x.swap(y);
}
template <typename K, typename T, class H, class P, class A>
inline void swap(hash_multimap<K, T, H, P, A>& x, hash_multimap<K, T, H, P, A>& y)
{
x.swap(y);
}
#endif/*NX_SP_CXX11_ALIAS*/
/*
Special container traits
*/
template <typename K, typename T, class H, class P, class A>
struct container_traits<std::unordered_map<K, T, H, P, A> >
{
typedef typename std::unordered_map<K, T, H, P, A>::value_type val_t;
typedef typename std::unordered_map<K, T, H, P, A>::iterator ite_t;
typedef std::pair<K, T> pair_t;
};
template <typename K, typename T, class H, class P, class A>
struct container_traits<std::unordered_multimap<K, T, H, P, A> >
{
typedef typename std::unordered_multimap<K, T, H, P, A>::value_type val_t;
typedef typename std::unordered_multimap<K, T, H, P, A>::iterator ite_t;
typedef std::pair<K, T> pair_t;
};
#ifndef NX_SP_CXX11_ALIAS
template <typename K, typename T, class H, class P, class A>
struct container_traits<nx::hash_map<K, T, H, P, A> >
{
typedef typename nx::hash_map<K, T, H, P, A>::value_type val_t;
typedef typename nx::hash_map<K, T, H, P, A>::iterator ite_t;
typedef std::pair<K, T> pair_t;
};
template <typename K, typename T, class H, class P, class A>
struct container_traits<nx::hash_multimap<K, T, H, P, A> >
{
typedef typename nx::hash_multimap<K, T, H, P, A>::value_type val_t;
typedef typename nx::hash_multimap<K, T, H, P, A>::iterator ite_t;
typedef std::pair<K, T> pair_t;
};
#endif/*NX_SP_CXX11_ALIAS*/
//////////////////////////////////////////////////////////////////////////
NX_END
//////////////////////////////////////////////////////////////////////////
#endif/*NX_SP_CXX11_UNORDERED_MAP*/