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