From 8d58d9ce4f09f4ca6f6b7f7b1b7b1ca1bb055df5 2017-08-17 07:44:44 From: Alexandre Leroux Date: 2017-08-17 07:44:44 Subject: [PATCH] Adds subData() method --- diff --git a/core/include/Data/DataSeries.h b/core/include/Data/DataSeries.h index fe252a3..8637c28 100644 --- a/core/include/Data/DataSeries.h +++ b/core/include/Data/DataSeries.h @@ -192,6 +192,27 @@ public: Iterator cend() const { return Iterator{*this, false}; } + std::pair subData(double min, double max) const + { + if (min > max) { + std::swap(min, max); + } + + auto begin = cbegin(); + auto end = cend(); + + auto lowerIt + = std::lower_bound(begin, end, min, [](const auto &itValue, const auto &value) { + return itValue.x() == value; + }); + auto upperIt + = std::upper_bound(begin, end, max, [](const auto &value, const auto &itValue) { + return itValue.x() == value; + }); + + return std::make_pair(lowerIt, upperIt); + } + // /////// // // Mutexes // // /////// //