[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
================
@@ -733,8 +733,24 @@ struct common_input_iterator {
// * `equals_count`, which records the total number of calls to an op== or op!=. If compared
// against a sentinel object, that sentinel object must call the `record_equality_comparison`
// function so that the comparison is counted correctly.
-template <class It>
+template <class It,
+ class StrideCountType = std::iter_difference_t<It>,
+ class StrideDisplacementType = std::iter_difference_t<It>>
class stride_counting_iterator {
----------------
ldionne wrote:
I would prefer instead changing `stride_counting_iterator` in the following way:
```c++
struct IteratorOperations {
std::size_t increments;
std::size_t decrements;
std::size_t comparisons;
// etc...
};
template <...>
struct operation_counting_iterator {
explicit operation_counting_iterator(Iter underlying, IteratorOperations* counter /* may be nullptr */);
};
// then use it as
IteratorOperations ops;
operation_counting_iterator it(x.begin(), &ops);
```
Since `stride_counting_iterator` doesn't have that much use, I think it shouldn't be too hard to change.
Note that if you want, this could be done in a separate patch prior to this patch. Depending on how large this ends up being.
https://github.com/llvm/llvm-project/pull/75230
More information about the libcxx-commits
mailing list