[libcxx-commits] [libcxx] [libc++] Speed up set_intersection() by fast-forwarding over ranges of non-matching elements with one-sided binary search. (PR #75230)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 24 12:17:29 PDT 2024


================
@@ -46,6 +48,48 @@ __lower_bound(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp,
   return __first;
 }
 
+// One-sided binary search, aka meta binary search, has been in the public domain for decades, and has the general
+// advantage of being \Omega(1) rather than the classic algorithm's \Omega(log(n)), with the downside of executing at
+// most 2*log(n) comparisons vs the classic algorithm's exact log(n). There are two scenarios in which it really shines:
+// the first one is when operating over non-random iterators, because the classic algorithm requires knowing the
----------------
ldionne wrote:

```suggestion
// the first one is when operating over non-random-access iterators, because the classic algorithm requires knowing the
```

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


More information about the libcxx-commits mailing list