[libcxx-commits] [libcxx] [libc++] Introduce one-sided binary search for lower_bound on non-random iterators, and use that to improve the average complexity of set_intersection. (PR #75230)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 12 11:01:48 PST 2023


philnik777 wrote:

> Hi Mark, thanks for your reply!
> 
> Strictly speaking, yes, that is true: the number of comparisons may violate the requirement of there being at most log(last - first) + O(1) projections and comparisons. However, that is only being done for non-random access iterators, where we are also executing 2*(last-first) iterator mutations, which are not part of the explicit algorithm guarantees, and are the reason why std::set and std::map have their own lower_bound -- std::lower_bound is really hard to use on non-random iterators because of this additional cost.
> 
> Would this be a blocker for accepting the contribution?

Yes. We have to stay standards-conforming - libc++ is an implementation of the C++ standard after all, so even if the trade-off seems like a good idea we can't make the call in this case. If this improves the performance for trivial calls like an integer and `std::less` or friends as the comparator, that should be allowable, since that's not user-visible. Anything as generic as you currently have won't be possible.

https://github.com/llvm/llvm-project/pull/75230


More information about the libcxx-commits mailing list