@@ -8,137 +8,140 @@ namespace NYT {
8
8
9
9
// /////////////////////////////////////////////////////////////////////////////
10
10
11
- template <class K , class V , size_t N>
11
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
12
12
template <class TInputIterator >
13
- TCompactFlatMap<K, V , N>::TCompactFlatMap(TInputIterator begin, TInputIterator end)
13
+ TCompactFlatMap<TKey, TValue , N, TKeyCompare >::TCompactFlatMap(TInputIterator begin, TInputIterator end)
14
14
{
15
15
insert (begin, end);
16
16
}
17
17
18
- template <class K , class V , size_t N>
19
- TCompactFlatMap<K, V , N>::TCompactFlatMap(std::initializer_list<value_type> values)
20
- : TCompactFlatMap<K, V , N>(values.begin(), values.end())
18
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
19
+ TCompactFlatMap<TKey, TValue , N, TKeyCompare >::TCompactFlatMap(std::initializer_list<value_type> values)
20
+ : TCompactFlatMap<TKey, TValue , N, TKeyCompare >(values.begin(), values.end())
21
21
{ }
22
22
23
- template <class K , class V , size_t N>
24
- bool TCompactFlatMap<K, V , N>::operator ==(const TCompactFlatMap& rhs) const
23
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
24
+ bool TCompactFlatMap<TKey, TValue , N, TKeyCompare >::operator ==(const TCompactFlatMap& rhs) const
25
25
{
26
26
return Storage_ == rhs.Storage_ ;
27
27
}
28
28
29
- template <class K , class V , size_t N>
30
- bool TCompactFlatMap<K, V , N>::operator !=(const TCompactFlatMap& rhs) const
29
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
30
+ bool TCompactFlatMap<TKey, TValue , N, TKeyCompare >::operator !=(const TCompactFlatMap& rhs) const
31
31
{
32
32
return !(*this == rhs);
33
33
}
34
34
35
- template <class K , class V , size_t N>
36
- typename TCompactFlatMap<K, V , N>::iterator TCompactFlatMap<K, V , N>::begin()
35
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
36
+ typename TCompactFlatMap<TKey, TValue , N, TKeyCompare >::iterator TCompactFlatMap<TKey, TValue , N, TKeyCompare >::begin()
37
37
{
38
38
return Storage_.begin ();
39
39
}
40
40
41
- template <class K , class V , size_t N>
42
- typename TCompactFlatMap<K, V , N>::const_iterator TCompactFlatMap<K, V , N>::begin() const
41
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
42
+ typename TCompactFlatMap<TKey, TValue , N, TKeyCompare >::const_iterator TCompactFlatMap<TKey, TValue , N, TKeyCompare >::begin() const
43
43
{
44
44
return Storage_.begin ();
45
45
}
46
46
47
- template <class K , class V , size_t N>
48
- typename TCompactFlatMap<K, V , N>::const_iterator TCompactFlatMap<K, V , N>::cbegin() const
47
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
48
+ typename TCompactFlatMap<TKey, TValue , N, TKeyCompare >::const_iterator TCompactFlatMap<TKey, TValue , N, TKeyCompare >::cbegin() const
49
49
{
50
50
return Storage_.begin ();
51
51
}
52
52
53
- template <class K , class V , size_t N>
54
- typename TCompactFlatMap<K, V , N>::iterator TCompactFlatMap<K, V , N>::end()
53
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
54
+ typename TCompactFlatMap<TKey, TValue , N, TKeyCompare >::iterator TCompactFlatMap<TKey, TValue , N, TKeyCompare >::end()
55
55
{
56
56
return Storage_.end ();
57
57
}
58
58
59
- template <class K , class V , size_t N>
60
- typename TCompactFlatMap<K, V , N>::const_iterator TCompactFlatMap<K, V , N>::end() const
59
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
60
+ typename TCompactFlatMap<TKey, TValue , N, TKeyCompare >::const_iterator TCompactFlatMap<TKey, TValue , N, TKeyCompare >::end() const
61
61
{
62
62
return Storage_.end ();
63
63
}
64
64
65
- template <class K , class V , size_t N>
66
- typename TCompactFlatMap<K, V , N>::const_iterator TCompactFlatMap<K, V , N>::cend() const
65
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
66
+ typename TCompactFlatMap<TKey, TValue , N, TKeyCompare >::const_iterator TCompactFlatMap<TKey, TValue , N, TKeyCompare >::cend() const
67
67
{
68
68
return Storage_.end ();
69
69
}
70
70
71
- template <class K , class V , size_t N>
72
- void TCompactFlatMap<K, V , N>::reserve(size_type n)
71
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
72
+ void TCompactFlatMap<TKey, TValue , N, TKeyCompare >::reserve(size_type n)
73
73
{
74
74
Storage_.reserve (n);
75
75
}
76
76
77
- template <class K , class V , size_t N>
78
- typename TCompactFlatMap<K, V , N>::size_type TCompactFlatMap<K, V , N>::size() const
77
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
78
+ typename TCompactFlatMap<TKey, TValue , N, TKeyCompare >::size_type TCompactFlatMap<TKey, TValue , N, TKeyCompare >::size() const
79
79
{
80
80
return Storage_.size ();
81
81
}
82
82
83
- template <class K , class V , size_t N>
84
- int TCompactFlatMap<K, V , N>::ssize() const
83
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
84
+ int TCompactFlatMap<TKey, TValue , N, TKeyCompare >::ssize() const
85
85
{
86
86
return static_cast <int >(Storage_.size ());
87
87
}
88
88
89
- template <class K , class V , size_t N>
90
- bool TCompactFlatMap<K, V , N>::empty() const
89
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
90
+ bool TCompactFlatMap<TKey, TValue , N, TKeyCompare >::empty() const
91
91
{
92
92
return Storage_.empty ();
93
93
}
94
94
95
- template <class K , class V , size_t N>
96
- void TCompactFlatMap<K, V , N>::clear()
95
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
96
+ void TCompactFlatMap<TKey, TValue , N, TKeyCompare >::clear()
97
97
{
98
98
Storage_.clear ();
99
99
}
100
100
101
- template <class K , class V , size_t N>
102
- void TCompactFlatMap<K, V , N>::shrink_to_small()
101
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
102
+ void TCompactFlatMap<TKey, TValue , N, TKeyCompare >::shrink_to_small()
103
103
{
104
104
Storage_.shrink_to_small ();
105
105
}
106
106
107
- template <class K , class V , size_t N>
108
- typename TCompactFlatMap<K, V, N>::iterator TCompactFlatMap<K, V, N>::find(const K& k)
107
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
108
+ template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey>
109
+ typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::find(const TOtherKey& k)
109
110
{
110
111
auto [rangeBegin, rangeEnd] = equal_range (k);
111
112
return rangeBegin == rangeEnd ? end () : rangeBegin;
112
113
}
113
114
114
- template <class K , class V , size_t N>
115
- typename TCompactFlatMap<K, V, N>::const_iterator TCompactFlatMap<K, V, N>::find(const K& k) const
115
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
116
+ template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey>
117
+ typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::find(const TOtherKey& k) const
116
118
{
117
119
auto [rangeBegin, rangeEnd] = equal_range (k);
118
120
return rangeBegin == rangeEnd ? end () : rangeBegin;
119
121
}
120
122
121
- template <class K , class V , size_t N>
122
- bool TCompactFlatMap<K, V, N>::contains(const K& k) const
123
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
124
+ template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey>
125
+ bool TCompactFlatMap<TKey, TValue, N, TKeyCompare>::contains(const TOtherKey& k) const
123
126
{
124
127
return find (k) != end ();
125
128
}
126
129
127
- template <class K , class V , size_t N>
128
- auto TCompactFlatMap<K, V , N>::insert(const value_type& value) -> std::pair<iterator, bool >
130
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
131
+ auto TCompactFlatMap<TKey, TValue , N, TKeyCompare >::insert(const value_type& value) -> std::pair<iterator, bool >
129
132
{
130
133
return do_insert (value);
131
134
}
132
135
133
- template <class K , class V , size_t N>
134
- auto TCompactFlatMap<K, V , N>::insert(value_type&& value) -> std::pair<iterator, bool >
136
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
137
+ auto TCompactFlatMap<TKey, TValue , N, TKeyCompare >::insert(value_type&& value) -> std::pair<iterator, bool >
135
138
{
136
139
return do_insert (std::move (value));
137
140
}
138
141
139
- template <class K , class V , size_t N>
142
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
140
143
template <class TArg >
141
- auto TCompactFlatMap<K, V , N>::do_insert(TArg&& value) -> std::pair<iterator, bool >
144
+ auto TCompactFlatMap<TKey, TValue , N, TKeyCompare >::do_insert(TArg&& value) -> std::pair<iterator, bool >
142
145
{
143
146
auto [rangeBegin, rangeEnd] = equal_range (value.first );
144
147
if (rangeBegin != rangeEnd) {
@@ -149,94 +152,100 @@ auto TCompactFlatMap<K, V, N>::do_insert(TArg&& value) -> std::pair<iterator, bo
149
152
}
150
153
}
151
154
152
- template <class K , class V , size_t N>
155
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
153
156
template <class TInputIterator >
154
- void TCompactFlatMap<K, V , N>::insert(TInputIterator begin, TInputIterator end)
157
+ void TCompactFlatMap<TKey, TValue , N, TKeyCompare >::insert(TInputIterator begin, TInputIterator end)
155
158
{
156
159
for (auto it = begin; it != end; ++it) {
157
160
insert (*it);
158
161
}
159
162
}
160
163
161
- template <class K , class V , size_t N>
164
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
162
165
template <class ... TArgs>
163
- auto TCompactFlatMap<K, V , N>::emplace(TArgs&&... args) -> std::pair<iterator, bool >
166
+ auto TCompactFlatMap<TKey, TValue , N, TKeyCompare >::emplace(TArgs&&... args) -> std::pair<iterator, bool >
164
167
{
165
168
return insert (value_type (std::forward<TArgs>(args)...));
166
169
}
167
170
168
- template <class K , class V , size_t N>
169
- V & TCompactFlatMap<K, V , N>::operator [](const K & k)
171
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
172
+ TValue & TCompactFlatMap<TKey, TValue , N, TKeyCompare >::operator [](const TKey & k)
170
173
{
171
- auto [it, inserted] = insert ({k, V ()});
174
+ auto [it, inserted] = insert ({k, TValue ()});
172
175
return it->second ;
173
176
}
174
177
175
- template <class K , class V , size_t N>
176
- void TCompactFlatMap<K, V , N>::erase(const K & k)
178
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
179
+ void TCompactFlatMap<TKey, TValue , N, TKeyCompare >::erase(const TKey & k)
177
180
{
178
181
auto [rangeBegin, rangeEnd] = equal_range (k);
179
182
erase (rangeBegin, rangeEnd);
180
183
}
181
184
182
- template <class K , class V , size_t N>
183
- void TCompactFlatMap<K, V , N>::erase(iterator pos)
185
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
186
+ void TCompactFlatMap<TKey, TValue , N, TKeyCompare >::erase(iterator pos)
184
187
{
185
188
Storage_.erase (pos);
186
189
187
190
// Try to keep the storage inline. This is why erase doesn't return an iterator.
188
191
Storage_.shrink_to_small ();
189
192
}
190
193
191
- template <class K , class V , size_t N>
192
- void TCompactFlatMap<K, V , N>::erase(iterator b, iterator e)
194
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
195
+ void TCompactFlatMap<TKey, TValue , N, TKeyCompare >::erase(iterator b, iterator e)
193
196
{
194
197
Storage_.erase (b, e);
195
198
196
199
// Try to keep the storage inline. This is why erase doesn't return an iterator.
197
200
Storage_.shrink_to_small ();
198
201
}
199
202
200
- template <class K , class V , size_t N>
201
- std::pair<typename TCompactFlatMap<K, V, N>::iterator, typename TCompactFlatMap<K, V, N>::iterator>
202
- TCompactFlatMap<K, V, N>::equal_range(const K& k)
203
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
204
+ template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey>
205
+ std::pair<typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator, typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator>
206
+ TCompactFlatMap<TKey, TValue, N, TKeyCompare>::equal_range(const TOtherKey& k)
203
207
{
204
- auto result = std::equal_range (Storage_. begin (), Storage_. end (), k, TKeyComparer () );
205
- YT_ASSERT (std::distance ( result.first , result. second ) <= 1 );
208
+ auto result = std::ranges:: equal_range (Storage_, k, {}, &value_type::first );
209
+ YT_ASSERT (result.size ( ) <= 1 );
206
210
return result;
207
211
}
208
212
209
- template <class K , class V , size_t N>
210
- std::pair<typename TCompactFlatMap<K, V, N>::const_iterator, typename TCompactFlatMap<K, V, N>::const_iterator>
211
- TCompactFlatMap<K, V, N>::equal_range(const K& k) const
213
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
214
+ template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey>
215
+ std::pair<typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator, typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator>
216
+ TCompactFlatMap<TKey, TValue, N, TKeyCompare>::equal_range(const TOtherKey& k) const
212
217
{
213
- auto result = std::equal_range (Storage_. begin (), Storage_. end (), k, TKeyComparer () );
214
- YT_ASSERT (std::distance ( result.first , result. second ) <= 1 );
218
+ auto result = std::ranges:: equal_range (Storage_, k, {}, &value_type::first );
219
+ YT_ASSERT (result.size ( ) <= 1 );
215
220
return result;
216
221
}
217
222
218
- template <class K , class V , size_t N>
219
- typename TCompactFlatMap<K, V, N>::const_iterator TCompactFlatMap<K, V, N>::lower_bound(const K& k) const
223
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
224
+ template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey>
225
+ typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::lower_bound(const TOtherKey& k) const
220
226
{
221
- return std::lower_bound (Storage_. begin (), Storage_. end (), k, TKeyComparer () );
227
+ return std::ranges:: lower_bound (Storage_, k, {}, &value_type::first );
222
228
}
223
229
224
- template <class K , class V , size_t N>
225
- typename TCompactFlatMap<K, V, N>::iterator TCompactFlatMap<K, V, N>::lower_bound(const K& k)
230
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
231
+ template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey>
232
+ typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::lower_bound(const TOtherKey& k)
226
233
{
227
- return std::lower_bound (Storage_. begin (), Storage_. end (), k, TKeyComparer () );
234
+ return std::ranges:: lower_bound (Storage_, k, {}, &value_type::first );
228
235
}
229
236
230
- template <class K , class V , size_t N>
231
- typename TCompactFlatMap<K, V, N>::const_iterator TCompactFlatMap<K, V, N>::upper_bound(const K& k) const
237
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
238
+ template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey>
239
+ typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::const_iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::upper_bound(const TOtherKey& k) const
232
240
{
233
- return std::upper_bound (Storage_. begin (), Storage_. end (), k, TKeyComparer () );
241
+ return std::ranges:: upper_bound (Storage_, k, {}, &value_type::first );
234
242
}
235
243
236
- template <class K , class V , size_t N>
237
- typename TCompactFlatMap<K, V, N>::iterator TCompactFlatMap<K, V, N>::upper_bound(const K& k)
244
+ template <class TKey , class TValue , size_t N, class TKeyCompare >
245
+ template <NDetail::CComparisonAllowed<TKey, TKeyCompare> TOtherKey>
246
+ typename TCompactFlatMap<TKey, TValue, N, TKeyCompare>::iterator TCompactFlatMap<TKey, TValue, N, TKeyCompare>::upper_bound(const TOtherKey& k)
238
247
{
239
- return std::upper_bound (Storage_. begin (), Storage_. end (), k, TKeyComparer () );
248
+ return std::ranges:: upper_bound (Storage_, k, {}, &value_type::first );
240
249
}
241
250
242
251
// //////////////////////////////////////////////////////////////////////////////
0 commit comments