@@ -1165,32 +1165,87 @@ public:
11651165 template <class _Key >
11661166 _LIBCPP_HIDE_FROM_ABI size_type __count_multi (const _Key& __k) const ;
11671167
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+
11681195 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 ));
11711198 }
1199+
11721200 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+
11741205 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 ));
11771208 }
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+
11781215 template <class _Key >
11791216 _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:
11811220 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 ());
11841223 }
11851224 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+
11871234 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 ());
11901237 }
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+
11911244 template <class _Key >
11921245 _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:
11941249 template <class _Key >
11951250 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> __equal_range_unique (const _Key& __k);
11961251 template <class _Key >
@@ -2098,16 +2153,16 @@ __tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const {
20982153 __rt = static_cast <__node_pointer>(__rt->__right_ );
20992154 else
21002155 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));
21032158 }
21042159 return 0 ;
21052160}
21062161
21072162template <class _Tp , class _Compare , class _Allocator >
21082163template <class _Key >
21092164typename __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) {
21112166 while (__root != nullptr ) {
21122167 if (!value_comp ()(__root->__get_value (), __v)) {
21132168 __result = static_cast <__end_node_pointer>(__root);
@@ -2120,7 +2175,7 @@ __tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, __node_pointer
21202175
21212176template <class _Tp , class _Compare , class _Allocator >
21222177template <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 (
21242179 const _Key& __v, __node_pointer __root, __end_node_pointer __result) const {
21252180 while (__root != nullptr ) {
21262181 if (!value_comp ()(__root->__get_value (), __v)) {
@@ -2135,7 +2190,7 @@ typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare,
21352190template <class _Tp , class _Compare , class _Allocator >
21362191template <class _Key >
21372192typename __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) {
21392194 while (__root != nullptr ) {
21402195 if (value_comp ()(__v, __root->__get_value ())) {
21412196 __result = static_cast <__end_node_pointer>(__root);
@@ -2148,7 +2203,7 @@ __tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, __node_pointer
21482203
21492204template <class _Tp , class _Compare , class _Allocator >
21502205template <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 (
21522207 const _Key& __v, __node_pointer __root, __end_node_pointer __result) const {
21532208 while (__root != nullptr ) {
21542209 if (value_comp ()(__v, __root->__get_value ())) {
@@ -2224,8 +2279,8 @@ __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) {
22242279 } else if (__comp_res.__greater ())
22252280 __rt = static_cast <__node_pointer>(__rt->__right_ );
22262281 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));
22292284 }
22302285 return _Pp (iterator (__result), iterator (__result));
22312286}
@@ -2247,8 +2302,8 @@ __tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const {
22472302 } else if (__comp_res.__greater ())
22482303 __rt = static_cast <__node_pointer>(__rt->__right_ );
22492304 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));
22522307 }
22532308 return _Pp (const_iterator (__result), const_iterator (__result));
22542309}
0 commit comments