From patchwork Thu Apr 18 14:14:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1055 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BAA2C60DC6 for ; Thu, 18 Apr 2019 16:14:57 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4F469333 for ; Thu, 18 Apr 2019 16:14:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1555596897; bh=bWh0/QPbU0r4kITQv6ooxGQ4yRXLQO/1DRYUJh5+T0Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AK4LzH7qU0kgLhlEGKPMIoneUXqIIYyYlCTkClswnuVgXoEVh3/qRCO/r6tIRLfFE /6x2lzt11bNhHftRPXnkmgm8kvGa9B1irZZA/UBR36LB67TfmsTKBRU4PBNjMCAXBQ kHXjt7EjEYLPkND78ncE6N62p9DzJsCZo5VhaZig= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 18 Apr 2019 17:14:32 +0300 Message-Id: <20190418141437.14014-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418141437.14014-1-laurent.pinchart@ideasonboard.com> References: <20190418141437.14014-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 08/13] libcamera: utils: Add set_overlap() function X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Apr 2019 14:14:58 -0000 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 Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- 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 make_unique(Args&&... args) char *secure_getenv(const char *name); +template +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 */