@@ -1166,32 +1166,87 @@ public:
1166
1166
template <class _Key >
1167
1167
_LIBCPP_HIDE_FROM_ABI size_type __count_multi (const _Key& __k) const ;
1168
1168
1169
+ template <bool _LowerBound, class _Key >
1170
+ _LIBCPP_HIDE_FROM_ABI __end_node_pointer __lower_upper_bound_unique_impl (const _Key& __v) const {
1171
+ auto __rt = __root ();
1172
+ auto __result = __end_node ();
1173
+ auto __comp = __lazy_synth_three_way_comparator<_Compare, _Key, value_type>(value_comp ());
1174
+ while (__rt != nullptr ) {
1175
+ auto __comp_res = __comp (__v, __rt->__get_value ());
1176
+
1177
+ if (__comp_res.__less ()) {
1178
+ __result = static_cast <__end_node_pointer>(__rt);
1179
+ __rt = static_cast <__node_pointer>(__rt->__left_ );
1180
+ } else if (__comp_res.__greater ()) {
1181
+ __rt = static_cast <__node_pointer>(__rt->__right_ );
1182
+ } else if _LIBCPP_CONSTEXPR (_LowerBound) {
1183
+ return static_cast <__end_node_pointer>(__rt);
1184
+ } else {
1185
+ return __rt->__right_ ? static_cast <__end_node_pointer>(std::__tree_min (__rt->__right_ )) : __result;
1186
+ }
1187
+ }
1188
+ return __result;
1189
+ }
1190
+
1191
+ template <class _Key >
1192
+ _LIBCPP_HIDE_FROM_ABI iterator __lower_bound_unique (const _Key& __v) {
1193
+ return iterator (__lower_upper_bound_unique_impl<true >(__v));
1194
+ }
1195
+
1169
1196
template <class _Key >
1170
- _LIBCPP_HIDE_FROM_ABI iterator lower_bound (const _Key& __v) {
1171
- return __lower_bound (__v, __root (), __end_node ( ));
1197
+ _LIBCPP_HIDE_FROM_ABI const_iterator __lower_bound_unique (const _Key& __v) const {
1198
+ return const_iterator (__lower_upper_bound_unique_impl< true >(__v ));
1172
1199
}
1200
+
1173
1201
template <class _Key >
1174
- _LIBCPP_HIDE_FROM_ABI iterator __lower_bound (const _Key& __v, __node_pointer __root, __end_node_pointer __result);
1202
+ _LIBCPP_HIDE_FROM_ABI iterator __upper_bound_unique (const _Key& __v) {
1203
+ return iterator (__lower_upper_bound_unique_impl<false >(__v));
1204
+ }
1205
+
1175
1206
template <class _Key >
1176
- _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound (const _Key& __v) const {
1177
- return __lower_bound (__v, __root (), __end_node ( ));
1207
+ _LIBCPP_HIDE_FROM_ABI const_iterator __upper_bound_unique (const _Key& __v) const {
1208
+ return iterator (__lower_upper_bound_unique_impl< false >(__v ));
1178
1209
}
1210
+
1211
+ private:
1212
+ template <class _Key >
1213
+ _LIBCPP_HIDE_FROM_ABI iterator
1214
+ __lower_bound_multi (const _Key& __v, __node_pointer __root, __end_node_pointer __result);
1215
+
1179
1216
template <class _Key >
1180
1217
_LIBCPP_HIDE_FROM_ABI const_iterator
1181
- __lower_bound (const _Key& __v, __node_pointer __root, __end_node_pointer __result) const ;
1218
+ __lower_bound_multi (const _Key& __v, __node_pointer __root, __end_node_pointer __result) const ;
1219
+
1220
+ public:
1221
+ template <class _Key >
1222
+ _LIBCPP_HIDE_FROM_ABI iterator __lower_bound_multi (const _Key& __v) {
1223
+ return __lower_bound_multi (__v, __root (), __end_node ());
1224
+ }
1182
1225
template <class _Key >
1183
- _LIBCPP_HIDE_FROM_ABI iterator upper_bound (const _Key& __v) {
1184
- return __upper_bound (__v, __root (), __end_node ());
1226
+ _LIBCPP_HIDE_FROM_ABI const_iterator __lower_bound_multi (const _Key& __v) const {
1227
+ return __lower_bound_multi (__v, __root (), __end_node ());
1185
1228
}
1229
+
1186
1230
template <class _Key >
1187
- _LIBCPP_HIDE_FROM_ABI iterator __upper_bound (const _Key& __v, __node_pointer __root, __end_node_pointer __result);
1231
+ _LIBCPP_HIDE_FROM_ABI iterator __upper_bound_multi (const _Key& __v) {
1232
+ return __upper_bound_multi (__v, __root (), __end_node ());
1233
+ }
1234
+
1188
1235
template <class _Key >
1189
- _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound (const _Key& __v) const {
1190
- return __upper_bound (__v, __root (), __end_node ());
1236
+ _LIBCPP_HIDE_FROM_ABI const_iterator __upper_bound_multi (const _Key& __v) const {
1237
+ return __upper_bound_multi (__v, __root (), __end_node ());
1191
1238
}
1239
+
1240
+ private:
1241
+ template <class _Key >
1242
+ _LIBCPP_HIDE_FROM_ABI iterator
1243
+ __upper_bound_multi (const _Key& __v, __node_pointer __root, __end_node_pointer __result);
1244
+
1192
1245
template <class _Key >
1193
1246
_LIBCPP_HIDE_FROM_ABI const_iterator
1194
- __upper_bound (const _Key& __v, __node_pointer __root, __end_node_pointer __result) const ;
1247
+ __upper_bound_multi (const _Key& __v, __node_pointer __root, __end_node_pointer __result) const ;
1248
+
1249
+ public:
1195
1250
template <class _Key >
1196
1251
_LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> __equal_range_unique (const _Key& __k);
1197
1252
template <class _Key >
@@ -2100,16 +2155,16 @@ __tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const {
2100
2155
__rt = static_cast <__node_pointer>(__rt->__right_ );
2101
2156
else
2102
2157
return std::distance (
2103
- __lower_bound (__k, static_cast <__node_pointer>(__rt->__left_ ), static_cast <__end_node_pointer>(__rt)),
2104
- __upper_bound (__k, static_cast <__node_pointer>(__rt->__right_ ), __result));
2158
+ __lower_bound_multi (__k, static_cast <__node_pointer>(__rt->__left_ ), static_cast <__end_node_pointer>(__rt)),
2159
+ __upper_bound_multi (__k, static_cast <__node_pointer>(__rt->__right_ ), __result));
2105
2160
}
2106
2161
return 0 ;
2107
2162
}
2108
2163
2109
2164
template <class _Tp , class _Compare , class _Allocator >
2110
2165
template <class _Key >
2111
- typename __tree<_Tp, _Compare, _Allocator>::iterator
2112
- __tree<_Tp, _Compare, _Allocator>::__lower_bound( const _Key& __v, __node_pointer __root, __end_node_pointer __result) {
2166
+ typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__lower_bound_multi(
2167
+ const _Key& __v, __node_pointer __root, __end_node_pointer __result) {
2113
2168
while (__root != nullptr ) {
2114
2169
if (!value_comp ()(__root->__get_value (), __v)) {
2115
2170
__result = static_cast <__end_node_pointer>(__root);
@@ -2122,7 +2177,7 @@ __tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, __node_pointer
2122
2177
2123
2178
template <class _Tp , class _Compare , class _Allocator >
2124
2179
template <class _Key >
2125
- typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__lower_bound (
2180
+ typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__lower_bound_multi (
2126
2181
const _Key& __v, __node_pointer __root, __end_node_pointer __result) const {
2127
2182
while (__root != nullptr ) {
2128
2183
if (!value_comp ()(__root->__get_value (), __v)) {
@@ -2136,8 +2191,8 @@ typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare,
2136
2191
2137
2192
template <class _Tp , class _Compare , class _Allocator >
2138
2193
template <class _Key >
2139
- typename __tree<_Tp, _Compare, _Allocator>::iterator
2140
- __tree<_Tp, _Compare, _Allocator>::__upper_bound( const _Key& __v, __node_pointer __root, __end_node_pointer __result) {
2194
+ typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::__upper_bound_multi(
2195
+ const _Key& __v, __node_pointer __root, __end_node_pointer __result) {
2141
2196
while (__root != nullptr ) {
2142
2197
if (value_comp ()(__v, __root->__get_value ())) {
2143
2198
__result = static_cast <__end_node_pointer>(__root);
@@ -2150,7 +2205,7 @@ __tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, __node_pointer
2150
2205
2151
2206
template <class _Tp , class _Compare , class _Allocator >
2152
2207
template <class _Key >
2153
- typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__upper_bound (
2208
+ typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__upper_bound_multi (
2154
2209
const _Key& __v, __node_pointer __root, __end_node_pointer __result) const {
2155
2210
while (__root != nullptr ) {
2156
2211
if (value_comp ()(__v, __root->__get_value ())) {
@@ -2226,8 +2281,9 @@ __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) {
2226
2281
} else if (__comp_res.__greater ())
2227
2282
__rt = static_cast <__node_pointer>(__rt->__right_ );
2228
2283
else
2229
- return _Pp (__lower_bound (__k, static_cast <__node_pointer>(__rt->__left_ ), static_cast <__end_node_pointer>(__rt)),
2230
- __upper_bound (__k, static_cast <__node_pointer>(__rt->__right_ ), __result));
2284
+ return _Pp (
2285
+ __lower_bound_multi (__k, static_cast <__node_pointer>(__rt->__left_ ), static_cast <__end_node_pointer>(__rt)),
2286
+ __upper_bound_multi (__k, static_cast <__node_pointer>(__rt->__right_ ), __result));
2231
2287
}
2232
2288
return _Pp (iterator (__result), iterator (__result));
2233
2289
}
@@ -2249,8 +2305,9 @@ __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const {
2249
2305
} else if (__comp_res.__greater ())
2250
2306
__rt = static_cast <__node_pointer>(__rt->__right_ );
2251
2307
else
2252
- return _Pp (__lower_bound (__k, static_cast <__node_pointer>(__rt->__left_ ), static_cast <__end_node_pointer>(__rt)),
2253
- __upper_bound (__k, static_cast <__node_pointer>(__rt->__right_ ), __result));
2308
+ return _Pp (
2309
+ __lower_bound_multi (__k, static_cast <__node_pointer>(__rt->__left_ ), static_cast <__end_node_pointer>(__rt)),
2310
+ __upper_bound_multi (__k, static_cast <__node_pointer>(__rt->__right_ ), __result));
2254
2311
}
2255
2312
return _Pp (const_iterator (__result), const_iterator (__result));
2256
2313
}
0 commit comments