-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiset.hpp
319 lines (269 loc) · 6.97 KB
/
multiset.hpp
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* multiset.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: davidzh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/17 15:31:01 by tyamcha #+# #+# */
/* Updated: 2022/09/11 19:42:54 by davidzh ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MULTISET_HPP
# define MULTISET_HPP
namespace ft
{
template <typename _Key, typename _Compare = ft::less<_Key>,
typename _Alloc = std::allocator<_Key> >
class multiset
{
typedef typename _Alloc::value_type _Alloc_value_type;
public:
typedef _Key key_type;
typedef _Key value_type;
typedef _Compare key_compare;
typedef _Compare value_compare;
typedef _Alloc allocator_type;
private:
typedef typename _Alloc::template
rebind<_Key>::other _Key_alloc_type;
typedef _bin_tree<key_type, value_type, _Identity<value_type>,
key_compare, _Key_alloc_type> _Rep_type;
_Rep_type _M_t;
typedef _Key_alloc_type _Alloc_traits;
public:
typedef typename _Alloc_traits::pointer pointer;
typedef typename _Alloc_traits::const_pointer const_pointer;
typedef typename _Alloc_traits::reference reference;
typedef typename _Alloc_traits::const_reference const_reference;
typedef typename _Rep_type::const_iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
multiset (void)
: _M_t()
{}
explicit
multiset(const _Compare& comp,
const allocator_type& a = allocator_type())
: _M_t(comp, _Key_alloc_type(a))
{}
template<typename _InputIterator>
multiset(_InputIterator first, _InputIterator last)
: _M_t()
{
_M_t._M_insert_equal(first, last);
}
template<typename _InputIterator>
multiset(_InputIterator first, _InputIterator last,
const _Compare& comp,
const allocator_type& a = allocator_type())
: _M_t(comp, _Key_alloc_type(a))
{
_M_t._M_insert_equal(first, last);
}
multiset(const multiset& x)
: _M_t(x._M_t)
{}
multiset&
operator=(const multiset& x)
{
_M_t = x._M_t;
return (*this);
}
key_compare
key_comp (void) const
{
return (_M_t.key_comp());
}
value_compare
value_comp (void) const
{
return (_M_t.key_comp());
}
allocator_type
get_allocator (void) const
{ return allocator_type(_M_t.get_allocator()); }
iterator
begin (void) const
{
return (_M_t.begin());
}
iterator
end (void) const
{
return (_M_t.end());
}
reverse_iterator
rbegin (void) const
{
return (_M_t.rbegin());
}
reverse_iterator
rend (void) const
{
return (_M_t.rend());
}
bool
empty (void) const
{
return (_M_t.empty());
}
size_type
size (void) const
{
return (_M_t.size());
}
size_type
max_size (void) const
{
return (_M_t.max_size());
}
void
swap(multiset& x)
{
_M_t.swap(x._M_t);
}
iterator
insert(const value_type& x)
{
return (_M_t._M_insert_equal(x));
}
iterator
insert(const_iterator position, const value_type& x)
{
return (_M_t._M_insert_equal_(position, x));
}
template<typename _InputIterator>
void
insert(_InputIterator first, _InputIterator last)
{
_M_t._M_insert_equal(first, last);
}
void
erase(iterator position)
{
_M_t.erase(position);
}
size_type
erase(const key_type& x)
{
return (_M_t.erase(x));
}
void
erase(iterator first, iterator last)
{
_M_t.erase(first, last);
}
void
clear (void)
{
_M_t.clear();
}
size_type
count(const key_type& x) const
{
return (_M_t.count(x));
}
iterator
find(const key_type& x)
{
return (_M_t.find(x));
}
const_iterator
find(const key_type& x) const
{
return (_M_t.find(x));
}
iterator
lower_bound(const key_type& x)
{
return (_M_t.lower_bound(x));
}
const_iterator
lower_bound(const key_type& x) const
{
return (_M_t.lower_bound(x));
}
iterator
upper_bound(const key_type& x)
{
return (_M_t.upper_bound(x));
}
const_iterator
upper_bound(const key_type& x) const
{
return (_M_t.upper_bound(x));
}
ft::pair<iterator, iterator>
equal_range(const key_type& x)
{
return (_M_t.equal_range(x));
}
ft::pair<const_iterator, const_iterator>
equal_range(const key_type& x) const
{
return (_M_t.equal_range(x));
}
template<typename _K1, typename _C1, typename _A1>
friend bool
operator==(const multiset<_K1, _C1, _A1>&,
const multiset<_K1, _C1, _A1>&);
template<typename _K1, typename _C1, typename _A1>
friend bool
operator< (const multiset<_K1, _C1, _A1>&,
const multiset<_K1, _C1, _A1>&);
};
template<typename _Key, typename _Compare, typename _Alloc>
inline bool
operator==(const multiset<_Key, _Compare, _Alloc>& x,
const multiset<_Key, _Compare, _Alloc>& y)
{
return (x._M_t == y._M_t);
}
template<typename _Key, typename _Compare, typename _Alloc>
inline bool
operator<(const multiset<_Key, _Compare, _Alloc>& x,
const multiset<_Key, _Compare, _Alloc>& y)
{
return (x._M_t < y._M_t);
}
template<typename _Key, typename _Compare, typename _Alloc>
inline bool
operator!=(const multiset<_Key, _Compare, _Alloc>& x,
const multiset<_Key, _Compare, _Alloc>& y)
{
return (!(x == y));
}
template<typename _Key, typename _Compare, typename _Alloc>
inline bool
operator>(const multiset<_Key,_Compare,_Alloc>& x,
const multiset<_Key,_Compare,_Alloc>& y)
{
return (y < x);
}
template<typename _Key, typename _Compare, typename _Alloc>
inline bool
operator<=(const multiset<_Key, _Compare, _Alloc>& x,
const multiset<_Key, _Compare, _Alloc>& y)
{
return (!(y < x));
}
template<typename _Key, typename _Compare, typename _Alloc>
inline bool
operator>=(const multiset<_Key, _Compare, _Alloc>& x,
const multiset<_Key, _Compare, _Alloc>& y)
{
return (!(x < y));
}
template<typename _Key, typename _Compare, typename _Alloc>
inline void
swap(multiset<_Key, _Compare, _Alloc>& x,
multiset<_Key, _Compare, _Alloc>& y)
{
x.swap(y);
}
}
#endif