libcamera: utils: Add set_overlap() function
The new set_overlap() function counts the number of overlapping elements in the intersection of two sorted ranges defined by their beginning and ending iterators. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
@@ -26,6 +26,25 @@ std::unique_ptr<T> make_unique(Args&&... args)
|
||||
|
||||
char *secure_getenv(const char *name);
|
||||
|
||||
template<class InputIt1, class InputIt2>
|
||||
unsigned int set_overlap(InputIt1 first1, InputIt1 last1,
|
||||
InputIt2 first2, InputIt2 last2)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
|
||||
while (first1 != last1 && first2 != last2) {
|
||||
if (*first1 < *first2) {
|
||||
++first1;
|
||||
} else {
|
||||
if (!(*first2 < *first1))
|
||||
count++;
|
||||
++first2;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
} /* namespace utils */
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
||||
Reference in New Issue
Block a user