Skip to content

Commit faa3115

Browse files
committed
Oops, bad mistake while porting into libc++! __lower_bound_onesided() must start with __step==0, otherwise we can't match the complexity of linear search when continually matching (like a std::set_intersection() of matching containers will).
1 parent d0c5f2b commit faa3115

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

libcxx/include/__algorithm/lower_bound.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ __lower_bound_onesided(_Iter __first, _Sent __last, const _Type& __value, _Comp&
6363
// __iterator_category<_Iter>>::value,
6464
// "lower_bound() is a multipass algorithm and requires forward iterator or better");
6565

66+
// split the step 0 scenario: this allows us to match worst-case complexity
67+
// when replacing linear search
68+
if (__first == __last || !std::__invoke(__comp, std::__invoke(__proj, *__first), __value))
69+
return __first;
70+
++__first;
71+
6672
using _Distance = typename iterator_traits<_Iter>::difference_type;
6773
for (_Distance __step = 1; __first != __last; __step <<= 1) {
6874
auto __it = __first;

0 commit comments

Comments
 (0)