Message ID | 20190416220839.1577-9-laurent.pinchart@ideasonboard.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Laurent, Thanks for your work. On 2019-04-17 01:08:34 +0300, Laurent Pinchart wrote: > 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> > --- > src/libcamera/include/utils.h | 19 +++++++++++++++++++ > src/libcamera/utils.cpp | 12 ++++++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h > index 79038a96feab..97bd470a45b0 100644 > --- a/src/libcamera/include/utils.h > +++ b/src/libcamera/include/utils.h > @@ -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 */ > diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp > index cd0fd7614cc7..e38f32684bb1 100644 > --- a/src/libcamera/utils.cpp > +++ b/src/libcamera/utils.cpp > @@ -68,6 +68,18 @@ char *secure_getenv(const char *name) > * \brief Constructs an object of type T and wraps it in a std::unique_ptr. > */ > > +/** > + * \fn libcamera::utils::set_overlap(InputIt1 first1, InputIt1 last1, > + * InputIt2 first2, InputIt2 last2) > + * \brief Count the number of elements in the intersection of two ranges > + * > + * Count the number of elements in the intersection of the sorted ranges [\a > + * first1, \a last1) and [\a first1, \a last2). Elements are compared using > + * operator< and the ranges must be sorted with respect to the same. > + * > + * \return The number of elements in the intersection of the two ranges > + */ > + > } /* namespace utils */ > > } /* namespace libcamera */ > -- > Regards, > > Laurent Pinchart > > _______________________________________________ > libcamera-devel mailing list > libcamera-devel@lists.libcamera.org > https://lists.libcamera.org/listinfo/libcamera-devel
Hi Laurent, On Wed, Apr 17, 2019 at 01:08:34AM +0300, Laurent Pinchart wrote: > 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> Very nice indeed! Thanks Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> > --- > src/libcamera/include/utils.h | 19 +++++++++++++++++++ > src/libcamera/utils.cpp | 12 ++++++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h > index 79038a96feab..97bd470a45b0 100644 > --- a/src/libcamera/include/utils.h > +++ b/src/libcamera/include/utils.h > @@ -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 */ > diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp > index cd0fd7614cc7..e38f32684bb1 100644 > --- a/src/libcamera/utils.cpp > +++ b/src/libcamera/utils.cpp > @@ -68,6 +68,18 @@ char *secure_getenv(const char *name) > * \brief Constructs an object of type T and wraps it in a std::unique_ptr. > */ > > +/** > + * \fn libcamera::utils::set_overlap(InputIt1 first1, InputIt1 last1, > + * InputIt2 first2, InputIt2 last2) > + * \brief Count the number of elements in the intersection of two ranges > + * > + * Count the number of elements in the intersection of the sorted ranges [\a > + * first1, \a last1) and [\a first1, \a last2). Elements are compared using > + * operator< and the ranges must be sorted with respect to the same. > + * > + * \return The number of elements in the intersection of the two ranges > + */ > + > } /* namespace utils */ > > } /* namespace libcamera */ > -- > Regards, > > Laurent Pinchart > > _______________________________________________ > libcamera-devel mailing list > libcamera-devel@lists.libcamera.org > https://lists.libcamera.org/listinfo/libcamera-devel
diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index 79038a96feab..97bd470a45b0 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -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 */ diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index cd0fd7614cc7..e38f32684bb1 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -68,6 +68,18 @@ char *secure_getenv(const char *name) * \brief Constructs an object of type T and wraps it in a std::unique_ptr. */ +/** + * \fn libcamera::utils::set_overlap(InputIt1 first1, InputIt1 last1, + * InputIt2 first2, InputIt2 last2) + * \brief Count the number of elements in the intersection of two ranges + * + * Count the number of elements in the intersection of the sorted ranges [\a + * first1, \a last1) and [\a first1, \a last2). Elements are compared using + * operator< and the ranges must be sorted with respect to the same. + * + * \return The number of elements in the intersection of the two ranges + */ + } /* namespace utils */ } /* namespace libcamera */
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> --- src/libcamera/include/utils.h | 19 +++++++++++++++++++ src/libcamera/utils.cpp | 12 ++++++++++++ 2 files changed, 31 insertions(+)